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