diff --git a/src/components/layout/attendance-redirect.tsx b/src/components/layout/attendance-redirect.tsx new file mode 100644 index 0000000..3e12481 --- /dev/null +++ b/src/components/layout/attendance-redirect.tsx @@ -0,0 +1,29 @@ +import { Navigate } from "@tanstack/solid-router"; +import { Show } from "solid-js"; +import { RouteGuard } from "@/components/layout/route-guard"; +import { useAuth } from "@/stores/auth-context"; + +/** + * `/attendance` is an old link every role may still hold. Attendance lives on + * a different page per role — a student's own report, a parent's child view, + * the staff roll-call tool — so the alias resolves once the role is known + * instead of sending everyone to the student-only page (a 403 for staff). + */ +export function AttendanceRedirect() { + const auth = useAuth(); + return ( + + + {(role) => + role === "student" ? ( + + ) : role === "parent" ? ( + + ) : ( + + ) + } + + + ); +} diff --git a/src/components/layout/nav-items.ts b/src/components/layout/nav-items.ts index 60a0199..7e85c4f 100644 --- a/src/components/layout/nav-items.ts +++ b/src/components/layout/nav-items.ts @@ -79,6 +79,7 @@ const AI_STUDIO_ITEM: NavItem = { to: "/ai/studio", labelKey: "aiHub.tab.studio", Icon: IconWaveform, + module: "course_notes", }; const AI_STUDY_ITEM: NavItem = { @@ -101,6 +102,7 @@ const AI_CELEBI_ITEM: NavItem = { labelKey: "nav.celebi", Icon: IconSparkles, action: "celebi", + module: "chatbot", }; const AI_GROUP: NavGroup = { diff --git a/src/lib/route-module.test.ts b/src/lib/route-module.test.ts index 1a0179b..01153c4 100644 --- a/src/lib/route-module.test.ts +++ b/src/lib/route-module.test.ts @@ -6,6 +6,7 @@ describe("routeModule", () => { expect(routeModule("/notes/abc")).toBe("notes"); expect(routeModule("/exam-room/1")).toBe("exams"); expect(routeModule("/question-bank/9")).toBe("bank_questions"); + expect(routeModule("/ai/studio")).toBe("course_notes"); }); it("prefers the longest prefix", () => { @@ -18,5 +19,8 @@ describe("routeModule", () => { expect(routeModule("/calendar")).toBeNull(); expect(routeModule("/management/students")).toBeNull(); expect(routeModule("/notebook")).toBeNull(); + // Study and insights read RAG/insight doors no school module gates. + expect(routeModule("/ai/study")).toBeNull(); + expect(routeModule("/ai/insights")).toBeNull(); }); }); diff --git a/src/lib/route-module.ts b/src/lib/route-module.ts index d1bb432..bedf510 100644 --- a/src/lib/route-module.ts +++ b/src/lib/route-module.ts @@ -18,6 +18,8 @@ const ROUTE_MODULES: ReadonlyArray = ["/students/attendance", "attendance"], ["/students/exams", "marks"], ["/students/study", "pomodoro"], + // Note Studio works on course notes (lists them, runs RAG/podcast over them). + ["/ai/studio", "course_notes"], ["/question-bank", "bank_questions"], ["/appointments", "appointments"], ["/whiteboards", "boards"], diff --git a/src/pages/course-detail-page.tsx b/src/pages/course-detail-page.tsx index a703b4f..2b56b4f 100644 --- a/src/pages/course-detail-page.tsx +++ b/src/pages/course-detail-page.tsx @@ -1,4 +1,4 @@ -import { For, Show, Suspense, createMemo, createSignal } from "solid-js"; +import { For, Show, Suspense, createEffect, createMemo, createSignal } from "solid-js"; import { createResource } from "@/lib/create-resource"; import { Link, useLocation, useNavigate, useParams } from "@tanstack/solid-router"; import type { ColumnDef } from "@tanstack/solid-table"; @@ -37,6 +37,7 @@ import { TableRowActions } from "@/components/ui/table-row-actions"; import { Textarea } from "@/components/ui/textarea"; import { UserSearchSelect } from "@/components/users/user-search-select"; import { useAuth } from "@/stores/auth-context"; +import { useModules } from "@/stores/modules-context"; import { useT } from "@/stores/preferences-context"; import { hasMinRole } from "@/lib/roles"; import { cn } from "@/lib/cn"; @@ -47,6 +48,9 @@ const COURSE_KINDS: CourseKind[] = ["course", "study", "club"]; /** One row of the "taught in" list: an instance plus the şube's name. */ type SectionRow = { instance: Instance | ClassCourse; className: string }; +// Literal class names so Tailwind sees every column count the tab strip can take. +const TAB_GRID_COLS: Record = { 1: "sm:grid-cols-1", 2: "sm:grid-cols-2", 3: "sm:grid-cols-3", 4: "sm:grid-cols-4" }; + export default function CourseDetailPage() { return ( @@ -66,7 +70,26 @@ function CourseDetailContent() { return params().id; }); + // Subjects, sections and course notes are separately sold modules; a tab for + // one the school switched off would only ever answer 403, so it is left out + // and the page opens on the first tab still there. + const modules = useModules(); + const tabOn = { + subjects: () => modules.isEnabled("subjects"), + sections: () => modules.isEnabled("classes"), + notes: () => modules.isEnabled("course_notes"), + }; const [courseTab, setCourseTab] = createSignal("subjects"); + const availableTabs = () => [ + ...(tabOn.subjects() ? ["subjects"] : []), + ...(tabOn.sections() ? ["sections"] : []), + ...(tabOn.notes() ? ["notes"] : []), + ...(hasMembers() ? ["members"] : []), + ]; + createEffect(() => { + const tabs = availableTabs(); + if (tabs.length > 0 && !tabs.includes(courseTab())) setCourseTab(tabs[0]); + }); const [course, { refetch: refetchCourse }] = createResource(id, (courseId) => getCourseById(courseId)); const [mine] = createResource( () => (auth.user()?.role === "student" ? true : null), @@ -90,7 +113,7 @@ function CourseDetailContent() { // in one call; the office has no course-scoped instance route, so it walks // the class list instead (one call per class, capped by the page limit). const [sections] = createResource( - () => (course() ? { courseId: id(), office: isOffice() } : null), + () => (course() && tabOn.sections() ? { courseId: id(), office: isOffice() } : null), async (args): Promise => { if (!args) return []; if (!args.office) { @@ -429,15 +452,22 @@ function CourseDetailContent() { - - { event.preventDefault(); setCourseTab("subjects"); }} class="min-w-0 rounded-none border-r border-border-line last:border-r-0 data-selected:border-b-2 data-selected:border-b-primary data-selected:bg-surface-base data-selected:shadow-none">{t("subjects.title")} - { event.preventDefault(); setCourseTab("sections"); }} class="min-w-0 rounded-none border-r border-border-line last:border-r-0 data-selected:border-b-2 data-selected:border-b-primary data-selected:bg-surface-base data-selected:shadow-none">{t("instances.title")} - { event.preventDefault(); setCourseTab("notes"); }} class="min-w-0 rounded-none border-r border-border-line last:border-r-0 data-selected:border-b-2 data-selected:border-b-primary data-selected:bg-surface-base data-selected:shadow-none">{t("courseNotes.title")}{noteCount()} + + + { event.preventDefault(); setCourseTab("subjects"); }} class="min-w-0 rounded-none border-r border-border-line last:border-r-0 data-selected:border-b-2 data-selected:border-b-primary data-selected:bg-surface-base data-selected:shadow-none">{t("subjects.title")} + + + { event.preventDefault(); setCourseTab("sections"); }} class="min-w-0 rounded-none border-r border-border-line last:border-r-0 data-selected:border-b-2 data-selected:border-b-primary data-selected:bg-surface-base data-selected:shadow-none">{t("instances.title")} + + + { event.preventDefault(); setCourseTab("notes"); }} class="min-w-0 rounded-none border-r border-border-line last:border-r-0 data-selected:border-b-2 data-selected:border-b-primary data-selected:bg-surface-base data-selected:shadow-none">{t("courseNotes.title")}{noteCount()} + { event.preventDefault(); setCourseTab("members"); }} class="min-w-0 rounded-none border-r border-border-line last:border-r-0 data-selected:border-b-2 data-selected:border-b-primary data-selected:bg-surface-base data-selected:shadow-none">{t("courses.members")} + + + + - + + + @@ -498,15 +533,17 @@ function CourseDetailContent() { - - - + + + + + diff --git a/src/pages/instance-detail-page.tsx b/src/pages/instance-detail-page.tsx index a7d2e0f..b655760 100644 --- a/src/pages/instance-detail-page.tsx +++ b/src/pages/instance-detail-page.tsx @@ -45,6 +45,7 @@ import { examKindLabel } from "@/lib/exam-labels"; import { examWeight } from "@/lib/exam-weight"; import { hasMinRole } from "@/lib/roles"; import { useAuth } from "@/stores/auth-context"; +import { useModules } from "@/stores/modules-context"; import { useT } from "@/stores/preferences-context"; export default function InstanceDetailPage() { @@ -72,6 +73,25 @@ function InstanceDetailContent() { const linkedTab = () => (typeof linkedSearch().tab === "string" ? (linkedSearch().tab as string) : null); const linkedRollCall = () => (typeof linkedSearch().rollCall === "string" ? (linkedSearch().rollCall as string) : undefined); const [tab, setTab] = createSignal(linkedTab() ?? "exams"); + // Exams, homework and sessions are separately sold modules; a tab for one the + // school switched off would only ever answer 403, so it is left out and the + // page falls back to the first tab still there. + const modules = useModules(); + const tabOn = { + exams: () => modules.isEnabled("exams"), + homework: () => modules.isEnabled("homework"), + sessions: () => modules.isEnabled("sessions"), + }; + createEffect(() => { + const tabs = [ + ...(tabOn.exams() ? ["exams"] : []), + ...(tabOn.homework() ? ["homework"] : []), + ...(tabOn.sessions() ? ["sessions"] : []), + "teachers", + ...(canManage() ? ["students"] : []), + ]; + if (!tabs.includes(tab())) setTab(tabs[0]); + }); const [instance, { refetch: refetchInstance }] = createResource(id, (instanceId) => getInstanceById(instanceId)); const [course] = createResource(() => instance()?.course ?? null, (courseId) => getCourseById(courseId)); const [klass] = createResource(() => instance()?.class ?? null, (classId) => getClassById(classId).catch(() => null)); @@ -89,7 +109,7 @@ function InstanceDetailContent() { const canStaff = () => hasMinRole(auth.user()?.role ?? "student", "manager"); const [exams, { refetch: refetchExams }] = createResource( - () => id(), + () => (tabOn.exams() ? id() : null), async (instanceId) => (instanceId ? (await getInstanceExams(instanceId)).items : []), ); const [roster, { refetch: refetchRoster }] = createResource( @@ -349,15 +369,17 @@ function InstanceDetailContent() { {inst().enrollment_count} - - - - - - {t("courses.exams")} - {examCount()} + + + + + + + {t("courses.exams")} + {examCount()} + - + @@ -518,15 +540,22 @@ function InstanceDetailContent() { - {t("courses.exams")}{examCount()} - {t("homework.title")}{homeworkCount()} - {t("sessions.title")}{sessionCount()} + + {t("courses.exams")}{examCount()} + + + {t("homework.title")}{homeworkCount()} + + + {t("sessions.title")}{sessionCount()} + {t("courses.teachers")}{inst().teachers.length} {t("courses.roster")}{rosterCount()} + {countDescription(examCount(), t("courses.examItem"))} @@ -548,7 +577,9 @@ function InstanceDetailContent() { /> + + {countDescription(homeworkCount(), t("homework.item"))} @@ -568,7 +599,9 @@ function InstanceDetailContent() { onCountChange={setHomeworkCount} /> + + {countDescription(sessionCount(), t("sessions.item"))} @@ -591,6 +624,7 @@ function InstanceDetailContent() { openRollCallFor={linkedRollCall()} /> + diff --git a/src/routes/router.tsx b/src/routes/router.tsx index 6308b9b..2cfd475 100644 --- a/src/routes/router.tsx +++ b/src/routes/router.tsx @@ -12,6 +12,7 @@ import { NotFoundPage } from "@/components/system/not-found-page"; import { PageSpinner } from "@/components/ui/page-spinner"; import { AuthProvider } from "@/stores/auth-context"; import { ModulesProvider } from "@/stores/modules-context"; +import { AttendanceRedirect } from "@/components/layout/attendance-redirect"; import { PreferencesProvider } from "@/stores/preferences-context"; function lazyRoute(loader: () => Promise<{ default: Component }>): Component { @@ -272,9 +273,8 @@ const studentPomodoroRoute = createRoute({ const attendanceRoute = createRoute({ getParentRoute: () => rootRoute, path: "/attendance", - beforeLoad: () => { - throw redirect({ to: "/marks", search: { tab: "attendance" } }); - }, + // Role-aware, so it has to wait for the session: see AttendanceRedirect. + component: AttendanceRedirect, }); const studentAttendanceRoute = createRoute({
{inst().enrollment_count}
{t("courses.exams")}
{examCount()}