Bton commited on
Commit
1a345ca
·
verified ·
1 Parent(s): 2d4ae6a

There seems to be a bunch of placeholder posts in script.js, but none being displayed in the UI

Browse files
Files changed (1) hide show
  1. script.js +35 -37
script.js CHANGED
@@ -71,36 +71,15 @@ document.addEventListener('DOMContentLoaded', function() {
71
  setActiveNav(unansweredLink);
72
  showUnansweredPanel();
73
 
74
- // Add placeholder posts
75
- const placeholderPosts = [
76
- {
77
- title: "How to implement binary search tree?",
78
- body: "I'm struggling with implementing the insert function for a BST. Can someone explain the recursive approach?",
79
- tags: ["BST", "Data Structures", "Recursion"],
80
- responses: 0,
81
- time: "30 minutes ago",
82
- status: "unanswered"
83
- },
84
- {
85
- title: "Question about HW3 problem 5",
86
- body: "The problem asks for O(n) solution but I can only think of O(n^2). Any hints?",
87
- tags: ["Homework", "Algorithms"],
88
- responses: 0,
89
- time: "1 hour ago",
90
- status: "unanswered"
91
- },
92
- {
93
- title: "Lecture 8 slides clarification",
94
- body: "On slide 25, the time complexity analysis isn't clear to me. Can someone explain?",
95
- tags: ["Lecture", "Time Complexity"],
96
- responses: 0,
97
- time: "2 hours ago",
98
- status: "unanswered"
99
- }
100
- ];
101
-
102
- // Store for later use
103
- window.placeholderPosts = placeholderPosts;
104
  });
105
  // Navigation
106
  allQuestionsLink.addEventListener('click', function(e) {
@@ -133,7 +112,7 @@ function setActiveNav(activeElement) {
133
  panel2.classList.add('hidden');
134
  panel3.classList.add('hidden');
135
  }
136
- function showUnansweredPanel() {
137
  panel1.classList.add('hidden');
138
  panel2.classList.remove('hidden');
139
  panel3.classList.add('hidden');
@@ -146,26 +125,45 @@ function setActiveNav(activeElement) {
146
  feedContainer.className = 'space-y-4';
147
  feedContainer.id = 'questions-feed';
148
 
149
- // Add placeholder posts
150
- window.placeholderPosts.forEach(post => {
151
  const postElement = document.createElement('custom-post-card');
152
  postElement.setAttribute('post', JSON.stringify({
153
  title: post.title,
154
  content: post.body,
155
  tags: post.tags,
156
  responses: post.responses,
157
- time: post.time,
158
- status: post.status,
159
  confidence: Math.floor(Math.random() * 100),
160
  upvotes: Math.floor(Math.random() * 10),
161
  author: "Student " + Math.floor(Math.random() * 100)
162
  }));
163
  feedContainer.appendChild(postElement);
164
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  postsList.appendChild(feedContainer);
166
  feather.replace();
167
-
168
- // Highlight unanswered filter in sidebar
169
  const sidebar = document.querySelector('custom-sidebar');
170
  if (sidebar) {
171
  const shadow = sidebar.shadowRoot;
 
71
  setActiveNav(unansweredLink);
72
  showUnansweredPanel();
73
 
74
+ // Store sample posts for later use
75
+ window.placeholderPosts = samplePosts.map(post => ({
76
+ title: post.title,
77
+ body: post.body,
78
+ tags: post.tags,
79
+ responses: post.responses,
80
+ time: "2 hours ago",
81
+ status: "unanswered"
82
+ }));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  });
84
  // Navigation
85
  allQuestionsLink.addEventListener('click', function(e) {
 
112
  panel2.classList.add('hidden');
113
  panel3.classList.add('hidden');
114
  }
115
+ function showUnansweredPanel() {
116
  panel1.classList.add('hidden');
117
  panel2.classList.remove('hidden');
118
  panel3.classList.add('hidden');
 
125
  feedContainer.className = 'space-y-4';
126
  feedContainer.id = 'questions-feed';
127
 
128
+ // Add sample posts as unanswered questions
129
+ samplePosts.forEach(post => {
130
  const postElement = document.createElement('custom-post-card');
131
  postElement.setAttribute('post', JSON.stringify({
132
  title: post.title,
133
  content: post.body,
134
  tags: post.tags,
135
  responses: post.responses,
136
+ time: `${Math.floor(Math.random() * 6) + 1} hours ago`,
137
+ status: post.responses > 0 ? "answered" : "unanswered",
138
  confidence: Math.floor(Math.random() * 100),
139
  upvotes: Math.floor(Math.random() * 10),
140
  author: "Student " + Math.floor(Math.random() * 100)
141
  }));
142
  feedContainer.appendChild(postElement);
143
  });
144
+
145
+ // Add placeholder posts if any
146
+ if (window.placeholderPosts && window.placeholderPosts.length > 0) {
147
+ window.placeholderPosts.forEach(post => {
148
+ const postElement = document.createElement('custom-post-card');
149
+ postElement.setAttribute('post', JSON.stringify({
150
+ title: post.title,
151
+ content: post.body,
152
+ tags: post.tags,
153
+ responses: post.responses,
154
+ time: post.time,
155
+ status: post.status,
156
+ confidence: Math.floor(Math.random() * 100),
157
+ upvotes: Math.floor(Math.random() * 10),
158
+ author: "Student " + Math.floor(Math.random() * 100)
159
+ }));
160
+ feedContainer.appendChild(postElement);
161
+ });
162
+ }
163
+
164
  postsList.appendChild(feedContainer);
165
  feather.replace();
166
+ // Highlight unanswered filter in sidebar
 
167
  const sidebar = document.querySelector('custom-sidebar');
168
  if (sidebar) {
169
  const shadow = sidebar.shadowRoot;