Skip to content

Commit bbd8081

Browse files
committed
created org_announcements page and fixed filtering
1 parent 356e534 commit bbd8081

File tree

4 files changed

+593
-40
lines changed

4 files changed

+593
-40
lines changed

frontend/src/pages/Admin/AnnouncementsPage/Announcements.tsx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,6 @@ const AdminAnnouncements = () => {
249249
});
250250
};
251251

252-
const generateSlug = (title: string): string => {
253-
const baseSlug = title
254-
.toLowerCase()
255-
.replace(/[^a-z0-9]+/g, '-')
256-
.replace(/(^-|-$)/g, '');
257-
const timestamp = Date.now().toString(36);
258-
return `${baseSlug}-${timestamp}`;
259-
};
260-
261252
useEffect(() => {
262253
fetchAnnouncement();
263254
fetchTags();
@@ -646,7 +637,6 @@ const AdminAnnouncements = () => {
646637
setNewAnnouncement({
647638
...newAnnouncement,
648639
title,
649-
slug: generateSlug(title),
650640
});
651641
}}
652642
className='w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-[#194B90]'

frontend/src/pages/AnnouncementPage/Announcement.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default function Announcement() {
5757
<h1 className='font-[Open_Sans] text-[40px] font-bold mb-4'>{announcement.title}</h1>
5858
<div className='flex items-center gap-3 mb-4'>
5959
<h3 className='font-[Open_Sans] text-[16px] font-normal leading-[150%] text-[#717171]'>
60-
{getTimeAgo(announcement.createdAt)}
60+
{getTimeAgo(announcement.publishedDate || announcement.createdAt)}
6161
</h3>
6262
{announcement.tags && announcement.tags.length > 0 && (
6363
<>

frontend/src/pages/AnnouncementsPage/Announcements.tsx

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -109,39 +109,47 @@ const AnnouncementsPage = () => {
109109
return `${Math.floor(diffInMinutes / 1440)} ${Math.floor(diffInMinutes / 1440) === 1 ? 'day' : 'days'} ago`;
110110
};
111111

112-
const filterAnnouncements = announcements.filter(a => {
113-
const now = new Date();
112+
const filterAnnouncements = announcements
113+
.filter(a => {
114+
const now = new Date();
114115

115-
// TIME FILTER
116-
if (timeFilter) {
117-
const createdAt = new Date(a.createdAt);
118-
const diffInHours = (now.getTime() - createdAt.getTime()) / 1000 / 3600;
119-
if (
120-
(timeFilter === '24h' && diffInHours > 24) ||
121-
(timeFilter === 'week' && diffInHours > 24 * 7) ||
122-
(timeFilter === 'month' && diffInHours > 24 * 30) ||
123-
(timeFilter === 'year' && diffInHours > 24 * 365)
124-
) {
125-
return false;
116+
// TIME FILTER
117+
if (timeFilter) {
118+
const publishedDate = new Date(a.publishedDate || a.createdAt);
119+
const diffInHours = (now.getTime() - publishedDate.getTime()) / 1000 / 3600;
120+
if (
121+
(timeFilter === '24h' && diffInHours > 24) ||
122+
(timeFilter === 'week' && diffInHours > 24 * 7) ||
123+
(timeFilter === 'month' && diffInHours > 24 * 30) ||
124+
(timeFilter === 'year' && diffInHours > 24 * 365)
125+
) {
126+
return false;
127+
}
126128
}
127-
}
128129

129-
// TAG FILTER
130-
if (selectedTags.length > 0) {
131-
const selectedTagNames = selectedTags.map(t => t.name);
132-
const announcementTagNames = a.tags.map(t => t.name);
133-
if (!announcementTagNames.some(tag => selectedTagNames.includes(tag))) {
134-
return false;
130+
// TAG FILTER
131+
if (selectedTags.length > 0) {
132+
const selectedTagNames = selectedTags.map(t => t.name);
133+
const announcementTagNames = a.tags.map(t => t.name);
134+
if (!announcementTagNames.some(tag => selectedTagNames.includes(tag))) {
135+
return false;
136+
}
135137
}
136-
}
137138

138-
if (searchQuery) {
139-
const query = searchQuery.toLowerCase();
140-
return a.title.toLowerCase().includes(query) || a.content.toLowerCase().includes(query);
141-
}
139+
// SEARCH FILTER
140+
if (searchQuery) {
141+
const query = searchQuery.toLowerCase();
142+
return a.title.toLowerCase().includes(query) || a.content.toLowerCase().includes(query);
143+
}
142144

143-
return true;
144-
});
145+
return true;
146+
})
147+
.sort((a, b) => {
148+
// sort by publishedDate descending (most recent first)
149+
const dateA = new Date(a.publishedDate || a.createdAt).getTime();
150+
const dateB = new Date(b.publishedDate || b.createdAt).getTime();
151+
return dateB - dateA;
152+
});
145153

146154
return (
147155
<div className='mt-8'>
@@ -301,7 +309,7 @@ const AnnouncementsPage = () => {
301309
</h2>
302310
<div className='flex items-center gap-3 mb-4'>
303311
<h3 className='font-[Open_Sans] text-[14px] font-normal leading-[150%] text-[#717171]'>
304-
{getTimeAgo(a.createdAt)}
312+
{getTimeAgo(a.publishedDate || a.createdAt)}
305313
</h3>
306314
{a.tags.length > 0 && (
307315
<>

0 commit comments

Comments
 (0)