Spaces:
Running
Running
File size: 8,035 Bytes
71e7c4b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
// Sample data for the forum
const forumData = {
stats: {
threads: 1245,
users: 856,
posts: 9873
},
categories: [
{ id: 1, name: "General Discussion", description: "Talk about anything and everything", threads: 342, icon: "bi-chat-square-text" },
{ id: 2, name: "Technology", description: "Computers, gadgets, and tech news", threads: 278, icon: "bi-laptop" },
{ id: 3, name: "Gaming", description: "Video games and consoles", threads: 195, icon: "bi-controller" },
{ id: 4, name: "Movies & TV", description: "Films, series, and streaming", threads: 167, icon: "bi-film" },
{ id: 5, name: "Music", description: "Artists, albums, and concerts", threads: 132, icon: "bi-music-note-beamed" },
{ id: 6, name: "Sports", description: "Athletes, teams, and events", threads: 98, icon: "bi-trophy" }
],
recentThreads: [
{ id: 1, title: "What's your favorite programming language?", category: "Technology", author: "CodeMaster", replies: 24, views: 156, lastPost: "2 hours ago" },
{ id: 2, title: "Best games of 2023 so far?", category: "Gaming", author: "GameFan", replies: 18, views: 203, lastPost: "5 hours ago" },
{ id: 3, title: "New movie recommendations", category: "Movies & TV", author: "FilmBuff", replies: 12, views: 98, lastPost: "Yesterday" },
{ id: 4, title: "Upcoming concert announcements", category: "Music", author: "MusicLover", replies: 8, views: 76, lastPost: "2 days ago" }
],
popularTags: ["javascript", "react", "gaming", "movies", "music", "sports", "technology", "programming", "webdev", "css"],
thread: {
id: 1,
title: "What's your favorite programming language?",
content: "I'm curious to know what programming languages everyone is using these days. Personally, I've been working a lot with JavaScript and TypeScript for web development, but I'm also interested in exploring Rust for system programming. What about you?",
author: "CodeMaster",
date: "June 15, 2023",
category: "Technology",
replies: [
{ id: 1, author: "DevGuru", date: "June 15, 2023", content: "I'm all about Python these days. The ecosystem is amazing for data science and machine learning.", avatar: "http://static.photos/technology/200x200/1" },
{ id: 2, author: "WebWizard", date: "June 16, 2023", content: "JavaScript/TypeScript for frontend and Go for backend services. Love the simplicity of Go!", avatar: "http://static.photos/technology/200x200/2" },
{ id: 3, author: "Rustacean", date: "June 16, 2023", content: "Rust is definitely worth learning! The compiler is strict but it helps prevent so many bugs.", avatar: "http://static.photos/technology/200x200/3" }
]
}
};
// DOM Content Loaded
document.addEventListener('DOMContentLoaded', function() {
// Load stats on homepage
if (document.getElementById('threadCount')) {
document.getElementById('threadCount').textContent = forumData.stats.threads.toLocaleString();
document.getElementById('userCount').textContent = forumData.stats.users.toLocaleString();
document.getElementById('postCount').textContent = forumData.stats.posts.toLocaleString();
}
// Load recent threads on homepage
if (document.getElementById('recentThreads')) {
const recentThreadsContainer = document.getElementById('recentThreads');
forumData.recentThreads.forEach(thread => {
const threadElement = document.createElement('a');
threadElement.href = `thread.html?id=${thread.id}`;
threadElement.className = 'list-group-item list-group-item-action thread-item';
threadElement.innerHTML = `
<div class="d-flex w-100 justify-content-between">
<h5 class="mb-1">${thread.title}</h5>
<small class="text-muted">${thread.lastPost}</small>
</div>
<div class="d-flex justify-content-between">
<small class="text-muted">${thread.category} • ${thread.author}</small>
<small class="text-muted">${thread.replies} replies • ${thread.views} views</small>
</div>
`;
recentThreadsContainer.appendChild(threadElement);
});
}
// Load popular tags on homepage
if (document.getElementById('popularTags')) {
const tagsContainer = document.getElementById('popularTags');
forumData.popularTags.forEach(tag => {
const tagElement = document.createElement('a');
tagElement.href = '#';
tagElement.className = 'tag';
tagElement.textContent = tag;
tagsContainer.appendChild(tagElement);
});
}
// Load categories on categories page
if (document.getElementById('categoriesList')) {
const categoriesContainer = document.getElementById('categoriesList');
forumData.categories.forEach(category => {
const categoryElement = document.createElement('div');
categoryElement.className = 'col-md-6 mb-4';
categoryElement.innerHTML = `
<div class="card h-100">
<div class="card-body">
<div class="d-flex align-items-center mb-3">
<i class="bi ${category.icon} fs-3 me-3"></i>
<h5 class="card-title mb-0"><a href="#" class="text-decoration-none">${category.name}</a></h5>
</div>
<p class="card-text">${category.description}</p>
<div class="d-flex justify-content-between align-items-center">
<small class="text-muted">${category.threads} threads</small>
<a href="#" class="btn btn-sm btn-outline-primary">View</a>
</div>
</div>
</div>
`;
categoriesContainer.appendChild(categoryElement);
});
}
// Load thread on thread page
if (document.getElementById('threadTitle')) {
const urlParams = new URLSearchParams(window.location.search);
const threadId = urlParams.get('id') || 1;
document.getElementById('threadTitle').textContent = forumData.thread.title;
document.getElementById('threadContent').textContent = forumData.thread.content;
document.getElementById('threadAuthor').textContent = forumData.thread.author;
document.getElementById('threadDate').textContent = forumData.thread.date;
const repliesContainer = document.getElementById('repliesList');
forumData.thread.replies.forEach(reply => {
const replyElement = document.createElement('div');
replyElement.className = 'list-group-item';
replyElement.innerHTML = `
<div class="d-flex">
<img src="${reply.avatar}" alt="${reply.author}" class="avatar me-3">
<div class="flex-grow-1">
<div class="reply-header">
<strong>${reply.author}</strong> • <small>${reply.date}</small>
</div>
<div class="reply-content">
${reply.content}
</div>
</div>
</div>
`;
repliesContainer.appendChild(replyElement);
});
// Handle reply form submission
document.getElementById('replyForm').addEventListener('submit', function(e) {
e.preventDefault();
const replyContent = document.getElementById('replyContent').value;
if (replyContent.trim()) {
alert('Your reply has been posted! (In a real app, this would be sent to the server)');
document.getElementById('replyContent').value = '';
}
});
}
}); |