@@ -2,36 +2,50 @@ import { useMemo } from "react";
22
33import type { HTConference } from "@/types/db" ;
44
5- import { ConferenceCard } from "./ConferenceCard " ;
5+ import { type DateLike , toDate } from "@/lib/utils/dates " ;
66
7- /** Firestore / date helpers */
8- type FirestoreTimestampLike = { toDate : ( ) => Date } ;
9- type DateLike = Date | string | number | FirestoreTimestampLike | null | undefined ;
7+ import { ConferenceCard } from "./ConferenceCard" ;
108
11- function isFirestoreTimestamp ( v : unknown ) : v is FirestoreTimestampLike {
12- return typeof ( v as { toDate ?: unknown } ) ?. toDate === "function" ;
13- }
149function toMillis ( value : DateLike ) : number {
15- if ( ! value ) return 0 ;
16- if ( value instanceof Date ) return value . getTime ( ) ;
17- if ( typeof value === "number" ) return value ;
18- if ( typeof value === "string" ) return new Date ( value ) . getTime ( ) ;
19- if ( isFirestoreTimestamp ( value ) ) return value . toDate ( ) . getTime ( ) ;
20- return 0 ;
10+ return toDate ( value ) ?. getTime ( ) ?? 0 ;
2111}
2212
2313type ConferenceWithDates < T > = T & {
2414 start_timestamp ?: DateLike ;
15+ end_timestamp ?: DateLike ;
2516 start_date ?: DateLike ;
17+ end_date ?: DateLike ;
18+ start_timestamp_str ?: DateLike ;
19+ end_timestamp_str ?: DateLike ;
20+ begin_tsz ?: DateLike ;
21+ end_tsz ?: DateLike ;
2622 updated_at ?: DateLike ;
23+ updated_timestamp ?: DateLike ;
24+ updated_tsz ?: DateLike ;
25+ updated ?: DateLike ;
2726 modified ?: DateLike ;
2827} ;
2928
3029const startMs = ( c : ConferenceWithDates < HTConference > ) =>
31- toMillis ( c . start_timestamp ?? c . start_date ) ;
30+ toMillis ( c . start_timestamp ?? c . start_timestamp_str ?? c . start_date ?? c . begin_tsz ) ;
31+
32+ const endMs = ( c : ConferenceWithDates < HTConference > ) =>
33+ toMillis ( c . end_timestamp ?? c . end_timestamp_str ?? c . end_date ?? c . end_tsz ) ;
3234
3335const updatedMs = ( c : ConferenceWithDates < HTConference > ) =>
34- toMillis ( c . updated_at ?? c . modified ?? c . start_timestamp ?? c . start_date ) ;
36+ toMillis (
37+ c . updated_at ??
38+ c . updated_timestamp ??
39+ c . updated_tsz ??
40+ c . updated ??
41+ c . modified ??
42+ c . start_timestamp ??
43+ c . start_timestamp_str ??
44+ c . start_date ,
45+ ) ;
46+
47+ const updatedDate = ( c : ConferenceWithDates < HTConference > ) =>
48+ toDate ( c . updated_at ?? c . updated_timestamp ?? c . updated_tsz ?? c . updated ?? c . modified ) ;
3549
3650const byStartAsc = ( a : HTConference , b : HTConference ) =>
3751 startMs ( a as ConferenceWithDates < HTConference > ) - startMs ( b as ConferenceWithDates < HTConference > ) ;
@@ -46,12 +60,18 @@ const byUpdatedDesc = (a: HTConference, b: HTConference) =>
4660export function DisplayConferences ( { conferences } : { conferences : HTConference [ ] } ) {
4761 const { upcoming, updated, past } = useMemo ( ( ) => {
4862 const now = Date . now ( ) ;
49- const future = conferences . filter (
50- ( c ) => startMs ( c as ConferenceWithDates < HTConference > ) >= now ,
51- ) ;
52- const history = conferences . filter (
53- ( c ) => startMs ( c as ConferenceWithDates < HTConference > ) < now ,
54- ) ;
63+ const future = conferences . filter ( ( c ) => {
64+ const conf = c as ConferenceWithDates < HTConference > ;
65+ const endsAt = endMs ( conf ) ;
66+ const startsAt = startMs ( conf ) ;
67+ return ( endsAt || startsAt ) >= now ;
68+ } ) ;
69+ const history = conferences . filter ( ( c ) => {
70+ const conf = c as ConferenceWithDates < HTConference > ;
71+ const endsAt = endMs ( conf ) ;
72+ const startsAt = startMs ( conf ) ;
73+ return ( endsAt || startsAt ) < now ;
74+ } ) ;
5575
5676 const THIRTY_DAYS = 1000 * 60 * 60 * 24 * 30 ;
5777
@@ -106,7 +126,10 @@ export function DisplayConferences({ conferences }: { conferences: HTConference[
106126 < CardsGrid >
107127 { updated . map ( ( c ) => (
108128 < CardWrap key = { c . id } >
109- < ConferenceCard conference = { c } />
129+ < ConferenceCard
130+ conference = { c }
131+ updatedAt = { updatedDate ( c as ConferenceWithDates < HTConference > ) }
132+ />
110133 </ CardWrap >
111134 ) ) }
112135 </ CardsGrid >
0 commit comments