Move all code to old/ to prepare for Nuxt rewrite

This commit is contained in:
Hornwitser 2025-03-01 16:32:51 +01:00
parent 6007f4caeb
commit 51ff27c569
33 changed files with 0 additions and 1 deletions

View file

@ -0,0 +1,39 @@
"use client";
import { createContext, useContext, useEffect, useState } from "react";
import { Schedule } from "./types";
const ScheduleContext = createContext<Schedule | null>(null);
interface ScheduleProviderProps {
children: React.ReactElement;
schedule: Schedule;
}
export function ScheduleProvider(props: ScheduleProviderProps) {
const [schedule, setSchedule] = useState(props.schedule);
useEffect(() => {
console.log("Opening event source")
const source = new EventSource("/api/events");
source.addEventListener("message", (message) => {
console.log("Message", message.data);
});
source.addEventListener("update", (message) => {
const updatedSchedule: Schedule = JSON.parse(message.data);
console.log("Update", updatedSchedule);
setSchedule(updatedSchedule);
});
return () => {
console.log("Closing event source")
source.close();
}
}, [])
return (
<ScheduleContext.Provider value={schedule}>
{props.children}
</ScheduleContext.Provider>
);
}
export function useSchedule() {
return useContext(ScheduleContext);
}

35
old/app/schedule/page.tsx Normal file
View file

@ -0,0 +1,35 @@
import Timetable from "@/ui/timetable"
import { Schedule } from "./types"
import { readFile } from "fs/promises"
import { ScheduleProvider } from "./context"
import { Events } from "@/ui/events";
import { Locations } from "@/ui/locations";
import { EventsEdit } from "@/ui/events-edit";
import { PushNotification } from "@/ui/push-notification";
export const dynamic = "force-dynamic";
export default async function page() {
const schedule: Schedule = JSON.parse(await readFile("schedule.json", "utf-8"));
return (
<ScheduleProvider schedule={schedule}>
<main>
<h1>Schedule & Events</h1>
<p>
Study carefully, we only hold these events once a year.
</p>
<p>
Get notified about updates
</p>
<PushNotification vapidPublicKey={process.env.VAPID_PUBLIC_KEY!} />
<h2>Schedule</h2>
<Timetable />
<EventsEdit />
<h2>Events</h2>
<Events />
<h2>Locations</h2>
<Locations />
</main>
</ScheduleProvider>
);
}

26
old/app/schedule/types.ts Normal file
View file

@ -0,0 +1,26 @@
export interface ScheduleEvent {
name: string,
id: string,
host?: string,
cancelled?: boolean,
description?: string,
slots: TimeSlot[],
}
export interface ScheduleLocation {
name: string,
id: string,
description?: string,
}
export interface TimeSlot {
id: string,
start: string,
end: string,
locations: string[],
}
export interface Schedule {
locations: ScheduleLocation[],
events: ScheduleEvent[],
}