forge
Explore
Log in

Don't you dare go Hollow

🐛 lazy-load event attendance behind disclosure

Browse files at this commit

6505c30c11bb0b8edf56cc16bbdbb8e8e7ae9a00Burak BoduroğluParent: b67b398
  • fix
    • 🐛 lazy-load event attendance behind disclosure
Show full message
fix: 🐛 lazy-load event attendance behind disclosure
- wrap teacher attendance in SectionDisclosure
- fetch only when disclosure opens
- signals before resources
- doc + remove completed optimization task
docs/frontend-next-steps.mdmodified+3 -7
@@ -68,6 +68,7 @@ Started fixes:
6868 - Exams page create action appears only when the teacher/manager has at least one manageable course to receive the new exam.
6969 - Exam create course picker lists only manageable courses, not every visible course.
7070 - Exam detail defers teacher-only heavy data: statistics load when opened, questions mount when opened, and results/roster load when the results or grade workflow needs them.
71+- Event detail defers the teacher-only attendance roster until the attendance disclosure is opened.
7172
7273 ## Priority 2: Pagination And Request Audit
7374
@@ -113,6 +114,7 @@ Current classification:
113114 - `/courses/:id` exams: unpaginated `GET /courses/{id}/exams`; course-scoped and accepted short-term.
114115 - `/courses/:id` sessions: unpaginated `GET /courses/{id}/sessions`, deferred until sessions section or create panel is opened. Course-scoped and accepted short-term.
115116 - `/courses/:id` roster: unpaginated `GET /courses/{id}/enrollments`, course-management only. Accepted for normal class sizes.
117+- `/events/:id` attendance: unpaginated `GET /events/{id}/attendance`, teacher+ only and deferred until the attendance disclosure opens. Accepted for event-scale rosters.
116118 - `/exams/:id` results: unpaginated `GET /exams/{id}/results`, deferred until results/grade/answer-sheet workflow needs it. Accepted for normal class sizes.
117119 - `/exams/:id` questions: unpaginated `GET /exams/{id}/questions`, deferred until questions section is opened. Accepted for exam-scale data.
118120 - `/exams/:id/live`: client-paginated/sorted live roster over backend snapshot/SSE. Accepted because monitor snapshot is role-gated and exam-scoped.
@@ -145,12 +147,6 @@ Known follow-ups:
145147 - This is acceptable while the question form stays small.
146148 - Revisit as a `SidePanel` if question authoring grows or needs more vertical space.
147149
148-### Event Detail Optimization
149-
150-- Event detail still fetches attendance on initial page load.
151-- Consider wrapping attendance in `SectionDisclosure` so the attendance list fetches only when opened.
152-- Keep self-attendance visible if it remains a primary action.
153-
154150 ### Schedule Validation
155151
156152 - Lesson session creation currently validates date shape and end-after-start in the client; backend still enforces not-in-the-past with server time.
@@ -174,7 +170,7 @@ Known follow-ups:
174170 - `/courses`: max 2-4 initial API calls depending on role and lookup needs.
175171 - `/courses/:id`: course detail may keep opened section state mounted; avoid fetching large hidden data unless the section is opened or needed for header metadata.
176172 - `/exams/:id`: exam detail may keep disclosure content mounted to preserve local state; defer heavy section data where practical.
177-- `/events/:id`: consider lazy-loading attendance if the route feels heavy.
173+- `/events/:id`: teacher-only attendance is lazy-loaded behind the attendance disclosure; keep self-attendance visible as a primary action.
178174 - Dashboard should avoid broad role-specific requests unless that role actually needs global scope.
179175 - Settings-dependent controls should share the cached settings request.
180176 - Paginated tables should prefer server-side pagination when backend support exists.
src/pages/event-detail-page.tsxmodified+19 -16
@@ -18,6 +18,7 @@ import { Button } from "@/components/ui/button";
1818 import { ConfirmDialog } from "@/components/ui/confirm-dialog";
1919 import { IconChevronLeft, IconEdit, IconTrash } from "@/components/ui/icons";
2020 import { PageSpinner } from "@/components/ui/page-spinner";
21+import { SectionDisclosure } from "@/components/ui/section-disclosure";
2122 import { SidePanel } from "@/components/ui/side-panel";
2223 import { UserSearchSelect } from "@/components/users/user-search-select";
2324 import { formatDateTime } from "@/lib/format";
@@ -45,27 +46,28 @@ function EventDetailContent() {
4546 return params().id;
4647 });
4748
48- const [event, { refetch: refetchEvent }] = createResource(id, (eventId) => getEventById(eventId));
49- const [attendance, { refetch: refetchAttendance }] = createResource(
50- () => (hasMinRole(auth.user()?.role, "teacher") ? id() : null),
51- async (eventId) => (eventId ? getEventAttendance(eventId) : []),
52- );
53-
5449 const [status, setStatus] = createSignal<AttendanceStatus>("present");
5550 const [otherUserId, setOtherUserId] = createSignal("");
5651 const [editing, setEditing] = createSignal(false);
5752 const [deleteOpen, setDeleteOpen] = createSignal(false);
53+ const [attendanceOpen, setAttendanceOpen] = createSignal(false);
5854 const [error, setError] = createSignal("");
5955 const [pending, setPending] = createSignal(false);
6056
57+ const isTeacherPlus = () => hasMinRole(auth.user()?.role, "teacher");
58+
59+ const [event, { refetch: refetchEvent }] = createResource(id, (eventId) => getEventById(eventId));
60+ const [attendance, { refetch: refetchAttendance }] = createResource(
61+ () => (isTeacherPlus() && attendanceOpen() ? id() : null),
62+ async (eventId) => (eventId ? getEventAttendance(eventId) : []),
63+ );
64+
6165 const canManage = () => {
6266 const e = event();
6367 const u = auth.user();
6468 if (!e || !u) return false;
6569 return e.creator === u.id || hasMinRole(u.role, "manager");
6670 };
67- const isTeacherPlus = () => hasMinRole(auth.user()?.role, "teacher");
68-
6971 const wrap = async (fn: () => Promise<void>) => {
7072 setError("");
7173 setPending(true);
@@ -198,7 +200,7 @@ function EventDetailContent() {
198200 onClick={() =>
199201 void wrap(async () => {
200202 await postEventAttendance(id(), { status: status() });
201- if (isTeacherPlus()) await refetchAttendance();
203+ if (attendanceOpen()) await refetchAttendance();
202204 })
203205 }
204206 >
@@ -243,7 +245,7 @@ function EventDetailContent() {
243245 user_id: uid,
244246 });
245247 setOtherUserId("");
246- await refetchAttendance();
248+ if (attendanceOpen()) await refetchAttendance();
247249 })
248250 }
249251 >
@@ -259,11 +261,12 @@ function EventDetailContent() {
259261 )}
260262
261263 <Show when={isTeacherPlus()}>
262- <section class="data-shell space-y-4 p-4">
263- <div>
264- <h2 class="font-display text-lg font-semibold">{t("events.attendance")}</h2>
265- <p class="mt-1 text-sm text-muted-foreground">{t("events.markedBy")}</p>
266- </div>
264+ <SectionDisclosure
265+ open={attendanceOpen()}
266+ onToggle={() => setAttendanceOpen((open) => !open)}
267+ title={t("events.attendance")}
268+ description={t("events.markedBy")}
269+ >
267270 <Suspense fallback={<PageSpinner />}>
268271 <Show when={attendance()}>
269272 {(rows) => (
@@ -281,7 +284,7 @@ function EventDetailContent() {
281284 )}
282285 </Show>
283286 </Suspense>
284- </section>
287+ </SectionDisclosure>
285288 </Show>
286289 </div>
287290 )}