1- import { readFile } from "node:fs/promises"
2- import path from "node:path"
1+ import dynamic from "next/dynamic"
32
43import { Breadcrumbs } from "@/_design-system/breadcrumbs"
5- import { meetups } from "@/components/meetups"
64import { Button } from "@/app/conf/_design-system/button"
75
86import { MeetupsMap } from "./meetups-map"
97import { EventsList } from "./events-list"
10- import { events , type Event , type Meetup } from "./events"
118import { BenefitsSection } from "./benefits-section"
129import { GetYourMeetupNoticedSection } from "./get-your-meetup-noticed-section"
1310import { BringGraphQLToYourCommunity } from "./bring-graphql-to-your-community"
14- import type { WorkingGroupMeeting } from "../../../../../scripts/sync-working-groups/sync-working-groups"
15- import dynamic from "next/dynamic"
16-
17- type AnyEvent = Event | Meetup | WorkingGroupMeeting
11+ import { getAllEvents } from "./get-all-events"
1812
1913const ISSUE_TEMPLATE_LINK =
2014 "https://github.com/graphql/community-wg/issues/new?assignees=&labels=event&template=event-submission.yml"
@@ -27,69 +21,8 @@ const GalleryStrip = dynamic(
2721 { ssr : false } ,
2822)
2923
30- const WORKING_GROUP_MEETINGS_FILE = path . join (
31- process . cwd ( ) ,
32- "scripts/sync-working-groups/working-group-events.ndjson" ,
33- )
34-
3524export default async function EventsPage ( ) {
36- const workingGroupMeetings = await loadWorkingGroupMeetings ( )
37-
38- let {
39- pastEvents,
40- upcomingEvents,
41- } : { pastEvents : AnyEvent [ ] ; upcomingEvents : AnyEvent [ ] } = events . reduce (
42- ( acc , event ) => {
43- const now = new Date ( )
44- const date = new Date ( event . date )
45- if ( date < now ) {
46- acc . pastEvents . push ( event )
47- } else {
48- acc . upcomingEvents . push ( event )
49- }
50- return acc
51- } ,
52- { pastEvents : [ ] , upcomingEvents : [ ] } as {
53- pastEvents : Event [ ]
54- upcomingEvents : Event [ ]
55- } ,
56- )
57-
58- const now = new Date ( )
59-
60- for ( const meeting of workingGroupMeetings ) {
61- if ( meeting . start && new Date ( meeting . start ) < now ) {
62- pastEvents . push ( meeting )
63- } else upcomingEvents . push ( meeting )
64- }
65-
66- for ( const meetup of meetups ) {
67- const { next, prev } = meetup . node
68- if ( next && new Date ( next ) < now ) {
69- pastEvents . push ( meetup )
70- } else {
71- upcomingEvents . push ( meetup )
72- pastEvents . push ( {
73- ...meetup ,
74- date : prev ,
75- } )
76- }
77- }
78-
79- const getDate = ( event : AnyEvent ) => {
80- if ( "date" in event ) return new Date ( event . date )
81- if ( "node" in event ) return new Date ( event . node . next || event . node . prev )
82- return new Date ( event . start )
83- }
84-
85- function sortByDate ( a : AnyEvent , b : AnyEvent ) {
86- const aDate = getDate ( a )
87- const bDate = getDate ( b )
88- return bDate . getTime ( ) - aDate . getTime ( )
89- }
90-
91- pastEvents = pastEvents . sort ( sortByDate )
92- upcomingEvents = upcomingEvents . sort ( sortByDate )
25+ const { upcomingEvents, pastEvents } = await getAllEvents ( )
9326
9427 return (
9528 < div className = "gql-container" >
@@ -169,17 +102,3 @@ export default async function EventsPage() {
169102 </ div >
170103 )
171104}
172-
173- async function loadWorkingGroupMeetings ( ) : Promise < WorkingGroupMeeting [ ] > {
174- try {
175- const raw = ( await readFile ( WORKING_GROUP_MEETINGS_FILE , "utf8" ) ) . trim ( )
176- if ( ! raw ) return [ ]
177- return raw
178- . split ( "\n" )
179- . filter ( Boolean )
180- . map ( line => JSON . parse ( line ) as WorkingGroupMeeting )
181- } catch ( error ) {
182- console . error ( "Failed to read working group meetings" , error )
183- return [ ]
184- }
185- }
0 commit comments