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:
parent
cdad188233
commit
093a6816bc
7 changed files with 236 additions and 49 deletions
|
@ -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();
|
||||
|
|
|
@ -4,6 +4,7 @@ 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";
|
||||
|
||||
export default async function page() {
|
||||
const schedule: Schedule = JSON.parse(await readFile("schedule.json", "utf-8"));
|
||||
|
@ -16,6 +17,7 @@ export default async function page() {
|
|||
</p>
|
||||
<h2>Schedule</h2>
|
||||
<Timetable />
|
||||
<EventsEdit />
|
||||
<h2>Events</h2>
|
||||
<Events />
|
||||
<h2>Locations</h2>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue