@@ -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