Skip to content

Commit f112fc4

Browse files
Merge pull request #85 from ChangePlusPlusVandy/org_announcements
org_announcements
2 parents c96cf59 + 37b4bb1 commit f112fc4

File tree

4 files changed

+415
-312
lines changed

4 files changed

+415
-312
lines changed

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,6 @@ const AdminAnnouncements = () => {
264264
});
265265
};
266266

267-
const generateSlug = (title: string): string => {
268-
const baseSlug = title
269-
.toLowerCase()
270-
.replace(/[^a-z0-9]+/g, '-')
271-
.replace(/(^-|-$)/g, '');
272-
const timestamp = Date.now().toString(36);
273-
return `${baseSlug}-${timestamp}`;
274-
};
275-
276267
useEffect(() => {
277268
fetchAnnouncement();
278269
fetchTags();
@@ -830,7 +821,6 @@ const AdminAnnouncements = () => {
830821
setNewAnnouncement({
831822
...newAnnouncement,
832823
title,
833-
slug: generateSlug(title),
834824
});
835825
}}
836826
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
@@ -58,7 +58,7 @@ export default function Announcement() {
5858
<h1 className='font-[Open_Sans] text-[40px] font-bold mb-4'>{announcement.title}</h1>
5959
<div className='flex items-center gap-3 mb-4'>
6060
<h3 className='font-[Open_Sans] text-[16px] font-normal leading-[150%] text-[#717171]'>
61-
{getTimeAgo(announcement.createdAt)}
61+
{getTimeAgo(announcement.publishedDate || announcement.createdAt)}
6262
</h3>
6363
{announcement.tags && announcement.tags.length > 0 && (
6464
<>

frontend/src/pages/AnnouncementsPage/Announcements.tsx

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -142,39 +142,47 @@ const AnnouncementsPage = ({ previewContent }: AnnouncementsPageProps = {}) => {
142142
return `${Math.floor(diffInMinutes / 1440)} ${Math.floor(diffInMinutes / 1440) === 1 ? 'day' : 'days'} ago`;
143143
};
144144

145-
const filterAnnouncements = announcements.filter(a => {
146-
const now = new Date();
147-
148-
// TIME FILTER
149-
if (timeFilter) {
150-
const createdAt = new Date(a.createdAt);
151-
const diffInHours = (now.getTime() - createdAt.getTime()) / 1000 / 3600;
152-
if (
153-
(timeFilter === '24h' && diffInHours > 24) ||
154-
(timeFilter === 'week' && diffInHours > 24 * 7) ||
155-
(timeFilter === 'month' && diffInHours > 24 * 30) ||
156-
(timeFilter === 'year' && diffInHours > 24 * 365)
157-
) {
158-
return false;
145+
const filterAnnouncements = announcements
146+
.filter(a => {
147+
const now = new Date();
148+
149+
// TIME FILTER
150+
if (timeFilter) {
151+
const publishedDate = new Date(a.publishedDate || a.createdAt);
152+
const diffInHours = (now.getTime() - publishedDate.getTime()) / 1000 / 3600;
153+
if (
154+
(timeFilter === '24h' && diffInHours > 24) ||
155+
(timeFilter === 'week' && diffInHours > 24 * 7) ||
156+
(timeFilter === 'month' && diffInHours > 24 * 30) ||
157+
(timeFilter === 'year' && diffInHours > 24 * 365)
158+
) {
159+
return false;
160+
}
159161
}
160-
}
161162

162-
// TAG FILTER
163-
if (selectedTags.length > 0) {
164-
const selectedTagNames = selectedTags.map(t => t.name);
165-
const announcementTagNames = a.tags.map(t => t.name);
166-
if (!announcementTagNames.some(tag => selectedTagNames.includes(tag))) {
167-
return false;
163+
// TAG FILTER
164+
if (selectedTags.length > 0) {
165+
const selectedTagNames = selectedTags.map(t => t.name);
166+
const announcementTagNames = a.tags.map(t => t.name);
167+
if (!announcementTagNames.some(tag => selectedTagNames.includes(tag))) {
168+
return false;
169+
}
168170
}
169-
}
170171

171-
if (searchQuery) {
172-
const query = searchQuery.toLowerCase();
173-
return a.title.toLowerCase().includes(query) || a.content.toLowerCase().includes(query);
174-
}
172+
// SEARCH FILTER
173+
if (searchQuery) {
174+
const query = searchQuery.toLowerCase();
175+
return a.title.toLowerCase().includes(query) || a.content.toLowerCase().includes(query);
176+
}
175177

176-
return true;
177-
});
178+
return true;
179+
})
180+
.sort((a, b) => {
181+
// sort by publishedDate descending (most recent first)
182+
const dateA = new Date(a.publishedDate || a.createdAt).getTime();
183+
const dateB = new Date(b.publishedDate || b.createdAt).getTime();
184+
return dateB - dateA;
185+
});
178186

179187
if (pageLoading) {
180188
return (
@@ -375,7 +383,7 @@ const AnnouncementsPage = ({ previewContent }: AnnouncementsPageProps = {}) => {
375383
</h2>
376384
<div className='flex items-center gap-3 mb-4'>
377385
<h3 className='font-[Open_Sans] text-[14px] font-normal leading-[150%] text-[#717171]'>
378-
{getTimeAgo(a.createdAt)}
386+
{getTimeAgo(a.publishedDate || a.createdAt)}
379387
</h3>
380388
{a.tags.length > 0 && (
381389
<>

0 commit comments

Comments
 (0)