Implement editing of the schedule

Cobbled together minimum viable system for editing the schedule in a way
that propogates updates to connected clients.
This commit is contained in:
Hornwitser 2025-02-27 18:39:04 +01:00
parent cdad188233
commit 093a6816bc
7 changed files with 236 additions and 49 deletions

View file

@ -16,14 +16,12 @@ export function ScheduleProvider(props: ScheduleProviderProps) {
const source = new EventSource("/api/events");
source.addEventListener("message", (message) => {
console.log("Message", message.data);
setSchedule(old => {
const copy: Schedule = JSON.parse(JSON.stringify(old));
const ts = copy.events[0].slots[0].start;
copy.events[0].slots[0].start = new Date(Date.parse(ts) + 36e5).toISOString();
return copy;
})
});
source.addEventListener("update", (message) => console.log("Update", 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();