From 5efbaa37755d20cc834e6b916d0d18259b2ff507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 12 Jul 2026 02:16:42 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20add=20events=20and=20notes?= =?UTF-8?q?=20pages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Events: list plus creation for teacher+; the detail page adds editing and the attendance roster — anyone marks themselves, teacher+ marks and removes others - Notes: personal notes with list, create, edit in place, and delete Every mutation updates its resource from the server response instead of refetching, so the UI reacts the frame the request resolves. --- src/pages/EventDetail.tsx | 236 ++++++++++++++++++++++++++++++++++++++ src/pages/Events.tsx | 110 ++++++++++++++++++ src/pages/Notes.tsx | 171 +++++++++++++++++++++++++++ 3 files changed, 517 insertions(+) create mode 100644 src/pages/EventDetail.tsx create mode 100644 src/pages/Events.tsx create mode 100644 src/pages/Notes.tsx diff --git a/src/pages/EventDetail.tsx b/src/pages/EventDetail.tsx new file mode 100644 index 0000000..80970d8 --- /dev/null +++ b/src/pages/EventDetail.tsx @@ -0,0 +1,236 @@ +// One event: view-first, with an edit toggle for its creator (or manager+), +// plus the attendance roster. Anyone marks themselves; teacher+ marks and +// removes others. + +import { useNavigate, useParams } from "@solidjs/router"; +import { For, Show, createResource, createSignal } from "solid-js"; +import { Empty, ErrorLine, Loading } from "../components/Feedback"; +import { IconEdit } from "../components/Icons"; +import { createAction } from "../lib/action"; +import { ApiError, events } from "../lib/api"; +import { useAuth } from "../lib/auth"; +import { formatWindow, fromInputValue, toInputValue } from "../lib/format"; +import { ATTENDANCE_STATUSES, LIMITS, type AttendanceStatus } from "../lib/types"; + +export default function EventDetail() { + const params = useParams<{ id: string }>(); + const navigate = useNavigate(); + const { user, can } = useAuth(); + const [editing, setEditing] = createSignal(false); + + const [event, { mutate: setEvent }] = createResource(() => params.id, events.get); + const [roster, { mutate: setRoster }] = createResource(() => params.id, events.attendance); + + const canManage = () => { + const current = event(); + return current !== undefined && (current.creator === user()?.id || can("manager")); + }; + const myStatus = () => roster()?.find((a) => a.user === user()?.id)?.status; + + const save = createAction(async (form: HTMLFormElement) => { + const data = new FormData(form); + setEvent( + await events.update(params.id, { + title: String(data.get("title")), + description: String(data.get("description")), + starts_at: fromInputValue(String(data.get("starts_at"))), + ends_at: fromInputValue(String(data.get("ends_at"))), + }), + ); + setEditing(false); + }); + + const remove = createAction(async () => { + await events.remove(params.id); + navigate("/events", { replace: true }); + }); + + const mark = createAction(async (status: AttendanceStatus, userId?: string) => { + const marked = await events.mark(params.id, status, userId); + // The backend upserts one row per (event, user); mirror that. + setRoster((current) => [ + ...(current ?? []).filter((a) => a.user !== marked.user), + marked, + ]); + }); + + const unmark = createAction(async (userId: string) => { + await events.unmark(params.id, userId); + setRoster((current) => current?.filter((a) => a.user !== userId)); + }); + + return ( + : } + > + {(current) => ( +
+
+
+

{current().title}

+

{formatWindow(current().starts_at, current().ends_at)}

+
+ + + +
+ + +

{current().description}

+
+ + +
{ + e.preventDefault(); + void save.run(e.currentTarget); + }} + > + + +
+ + +
+ + + + + + + +
+ +
+

Attendance

+
+ + {(status) => ( + + )} + +
+ + +
{ + e.preventDefault(); + const data = new FormData(e.currentTarget); + void mark.run( + data.get("status") as AttendanceStatus, + String(data.get("user_id")), + ); + }} + > + + + +
+
+ + + }> + Nobody marked yet.}> +
+ + + + + + + + + + + {(entry) => ( + + + + + + + + )} + + +
UserStatus + +
+ {entry.user === user()?.id ? "you" : entry.user} + + {entry.status} + + +
+
+
+
+
+
+ )} +
+ ); +} + +function NotFoundMessage(props: { error: unknown }) { + const message = + props.error instanceof ApiError && props.error.status === 404 + ? "This event does not exist." + : "Failed to load the event."; + return {message}; +} diff --git a/src/pages/Events.tsx b/src/pages/Events.tsx new file mode 100644 index 0000000..c621e9f --- /dev/null +++ b/src/pages/Events.tsx @@ -0,0 +1,110 @@ +// Event list plus creation (teacher+). Cards link to the detail page where +// editing and attendance live. + +import { A } from "@solidjs/router"; +import { For, Show, createResource, createSignal } from "solid-js"; +import { Empty, ErrorLine, Loading } from "../components/Feedback"; +import { IconPlus } from "../components/Icons"; +import { createAction } from "../lib/action"; +import { events } from "../lib/api"; +import { useAuth } from "../lib/auth"; +import { formatWindow, fromInputValue } from "../lib/format"; +import { LIMITS } from "../lib/types"; + +export default function Events() { + const { can } = useAuth(); + const [list, { mutate }] = createResource(events.list); + const [creating, setCreating] = createSignal(false); + + const create = createAction(async (form: HTMLFormElement) => { + const data = new FormData(form); + const starts = fromInputValue(String(data.get("starts_at"))); + const ends = fromInputValue(String(data.get("ends_at"))); + const created = await events.create({ + title: String(data.get("title")), + description: String(data.get("description")), + starts_at: starts ?? undefined, + ends_at: ends ?? undefined, + }); + mutate((current) => [created, ...(current ?? [])]); + form.reset(); + setCreating(false); + }); + + return ( +
+
+
+

Events

+

What's happening — open one to see or mark attendance.

+
+ + + +
+ + +
{ + e.preventDefault(); + void create.run(e.currentTarget); + }} + > + queueMicrotask(() => el.focus())} + /> + + + + + + + +
+ + ); +}