diff --git a/src/api/getPomodoroByUser.ts b/src/api/getPomodoroByUser.ts new file mode 100644 index 0000000..155149d --- /dev/null +++ b/src/api/getPomodoroByUser.ts @@ -0,0 +1,7 @@ +import { client } from "./client"; +import { pageQuery, type PageParams } from "./page"; +import type { PomodoroLog } from "./types"; + +export function getPomodoroByUser(userId: string, params?: PageParams, signal?: AbortSignal): Promise { + return client(`/pomodoro/${userId}${pageQuery(params)}`, { signal }); +} diff --git a/src/api/getSessionById.ts b/src/api/getSessionById.ts new file mode 100644 index 0000000..210637a --- /dev/null +++ b/src/api/getSessionById.ts @@ -0,0 +1,6 @@ +import { client } from "./client"; +import type { CourseSession } from "./types"; + +export function getSessionById(id: string, signal?: AbortSignal): Promise { + return client(`/sessions/${id}`, { signal }); +} diff --git a/src/api/getSubjectById.ts b/src/api/getSubjectById.ts new file mode 100644 index 0000000..5edad40 --- /dev/null +++ b/src/api/getSubjectById.ts @@ -0,0 +1,6 @@ +import { client } from "./client"; +import type { Subject } from "./types"; + +export function getSubjectById(id: string, signal?: AbortSignal): Promise { + return client(`/subjects/${id}`, { signal }); +} diff --git a/src/api/getTermById.ts b/src/api/getTermById.ts new file mode 100644 index 0000000..196372f --- /dev/null +++ b/src/api/getTermById.ts @@ -0,0 +1,6 @@ +import { client } from "./client"; +import type { Term } from "./types"; + +export function getTermById(id: string, signal?: AbortSignal): Promise { + return client(`/terms/${id}`, { signal }); +} diff --git a/src/api/patchUserPreferences.ts b/src/api/patchUserPreferences.ts new file mode 100644 index 0000000..01b826b --- /dev/null +++ b/src/api/patchUserPreferences.ts @@ -0,0 +1,14 @@ +import { client } from "./client"; +import type { User, UserLanguage, UserTheme } from "./types"; + +export type PatchUserPreferencesBody = { + theme?: UserTheme | null; + language?: UserLanguage | null; +}; + +export function patchUserPreferences(id: string, body: PatchUserPreferencesBody): Promise { + return client(`/users/${id}/preferences`, { + method: "PATCH", + body, + }); +} diff --git a/src/components/layout/app-shell.tsx b/src/components/layout/app-shell.tsx index d8b6481..47f7988 100644 --- a/src/components/layout/app-shell.tsx +++ b/src/components/layout/app-shell.tsx @@ -43,6 +43,7 @@ export function AppShell(props: ParentProps) { if (path === "/work") return `${t("nav.group.reports")} / ${t("nav.work")}`; if (path === "/management/student-marks") return `${t("nav.group.reports")} / ${t("nav.studentMarks")}`; if (path === "/management/student-attendance") return `${t("nav.group.reports")} / ${t("nav.studentAttendance")}`; + if (path === "/management/pomodoros") return `${t("nav.group.reports")} / ${t("nav.studentPomodoro")}`; if (path === "/management/staff-work") return `${t("nav.group.reports")} / ${t("nav.staffWork")}`; if (path === "/management/settings") return `${t("nav.group.settings")} / ${t("nav.settings")}`; if (path === "/management/terms") return `${t("nav.group.settings")} / ${t("nav.terms")}`; diff --git a/src/components/layout/side-nav.tsx b/src/components/layout/side-nav.tsx index 5192b20..8986c6c 100644 --- a/src/components/layout/side-nav.tsx +++ b/src/components/layout/side-nav.tsx @@ -85,6 +85,7 @@ const NAV_GROUPS: NavGroup[] = [ items: [ { to: "/management/student-marks", labelKey: "nav.studentMarks", Icon: IconChart, minRole: "teacher" }, { to: "/management/student-attendance", labelKey: "nav.studentAttendance", Icon: IconClipboardCheck, minRole: "teacher" }, + { to: "/management/pomodoros", labelKey: "nav.studentPomodoro", Icon: IconClock, minRole: "teacher" }, { to: "/work", labelKey: "nav.work", Icon: IconBriefcase, minRole: "teacher", maxRole: "manager" }, { to: "/management/staff-work", labelKey: "nav.staffWork", Icon: IconBriefcase, minRole: "manager" }, ], diff --git a/src/components/users/user-preferences-actions.tsx b/src/components/users/user-preferences-actions.tsx new file mode 100644 index 0000000..b92e3ca --- /dev/null +++ b/src/components/users/user-preferences-actions.tsx @@ -0,0 +1,39 @@ +import { Show, createSignal } from "solid-js"; +import type { User, UserLanguage, UserTheme } from "@/api/types"; +import { Button } from "@/components/ui/button"; +import { IconCheck } from "@/components/ui/icons"; +import { Select } from "@/components/ui/select"; +import { useT } from "@/stores/preferences-context"; + +export function UserPreferencesActions(props: { + user: User; + onPreferencesChange: (userId: string, body: { theme?: UserTheme | null; language?: UserLanguage | null }) => Promise; +}) { + const t = useT(); + const [theme, setTheme] = createSignal(props.user.theme ?? ""); + const [language, setLanguage] = createSignal(props.user.language ?? ""); + const dirty = () => theme() !== (props.user.theme ?? "") || language() !== (props.user.language ?? ""); + + return ( +
+
+ + +
+ + + +
+ ); +} diff --git a/src/components/users/user-table.tsx b/src/components/users/user-table.tsx index 9793e68..ae6a126 100644 --- a/src/components/users/user-table.tsx +++ b/src/components/users/user-table.tsx @@ -1,6 +1,6 @@ import { createMemo, createSignal, Show } from "solid-js"; import type { ColumnDef } from "@tanstack/solid-table"; -import type { Role, User } from "@/api/types"; +import type { Role, User, UserLanguage, UserTheme } from "@/api/types"; import type { MessageKey } from "@/i18n/messages"; import { Select } from "@/components/ui/select"; import { Button } from "@/components/ui/button"; @@ -8,6 +8,7 @@ import { Badge } from "@/components/ui/badge"; import { ConfirmDialog } from "@/components/ui/confirm-dialog"; import { DataTable } from "@/components/ui/data-table"; import { IconCheck } from "@/components/ui/icons"; +import { UserPreferencesActions } from "@/components/users/user-preferences-actions"; import { ROLES } from "@/lib/roles"; import { cn } from "@/lib/cn"; import { useT } from "@/stores/preferences-context"; @@ -74,6 +75,7 @@ export function UserTable(props: { users: User[]; currentUserId: string; onRoleChange: (userId: string, role: Role) => Promise; + onPreferencesChange?: (userId: string, body: { theme?: UserTheme | null; language?: UserLanguage | null }) => Promise; }) { const t = useT(); const searchUser = (user: User, query: string) => @@ -114,6 +116,14 @@ export function UserTable(props: { header: t("admin.id"), meta: { cellClass: "mono truncate text-xs text-muted-foreground" }, }, + { + id: "preferences", + header: t("nav.preferences"), + meta: { headerClass: "w-56", cellClass: "w-56" }, + cell: (cell) => props.onPreferencesChange + ? + : "—", + }, { id: "update", header: t("common.update"), @@ -125,6 +135,6 @@ export function UserTable(props: { ]); return ( - + ); } diff --git a/src/i18n/messages.ts b/src/i18n/messages.ts index 97756b3..521fe80 100644 --- a/src/i18n/messages.ts +++ b/src/i18n/messages.ts @@ -26,6 +26,7 @@ export type MessageKey = | "nav.users" | "nav.studentMarks" | "nav.studentAttendance" + | "nav.studentPomodoro" | "nav.settings" | "nav.terms" | "nav.guide" @@ -344,6 +345,8 @@ export type MessageKey = | "pomodoro.finished" | "pomodoro.history" | "pomodoro.empty" + | "pomodoro.lookup" + | "pomodoro.forUser" | "pomodoro.startedAt" | "pomodoro.finishedAt" | "pomodoro.duration" @@ -630,6 +633,7 @@ const en: Dict = { "nav.users": "Users", "nav.studentMarks": "Student marks", "nav.studentAttendance": "Student attendance", + "nav.studentPomodoro": "Pomodoros", "nav.settings": "Settings", "nav.terms": "Terms", "nav.guide": "Guide", @@ -950,6 +954,8 @@ const en: Dict = { "pomodoro.finished": "Focus session finished.", "pomodoro.history": "Recent sessions", "pomodoro.empty": "No focus sessions yet.", + "pomodoro.lookup": "Select a student to review their pomodoro focus history.", + "pomodoro.forUser": "Pomodoros for {user}", "pomodoro.startedAt": "Started", "pomodoro.finishedAt": "Finished", "pomodoro.duration": "Duration", @@ -1231,7 +1237,7 @@ const tr: Dict = { "ai.send": "Gönder", "ai.unavailable": "Çelebi henüz bağlı değil. Gerçek yanıtlar için backend AI endpoint’i gerekli.", "nav.home": "Ana sayfa", - "nav.notes": "Notlar", + "nav.notes": "Defter", "nav.events": "Etkinlikler", "nav.exams": "Sınavlar", "nav.courses": "Ders", @@ -1246,6 +1252,7 @@ const tr: Dict = { "nav.users": "Kullanıcılar", "nav.studentMarks": "Notlar", "nav.studentAttendance": "Yoklamalar", + "nav.studentPomodoro": "Pomodorolar", "nav.settings": "Ayarlar", "nav.terms": "Dönemler", "nav.guide": "Rehber", @@ -1566,6 +1573,8 @@ const tr: Dict = { "pomodoro.finished": "Odak oturumu bitti.", "pomodoro.history": "Son oturumlar", "pomodoro.empty": "Henüz odak oturumu yok.", + "pomodoro.lookup": "Öğrencinin pomodoro odak geçmişini görmek için öğrenci seç.", + "pomodoro.forUser": "{user} için pomodorolar", "pomodoro.startedAt": "Başlangıç", "pomodoro.finishedAt": "Bitiş", "pomodoro.duration": "Süre", diff --git a/src/pages/admin-users-page.tsx b/src/pages/admin-users-page.tsx index 3df1353..c4b2e9c 100644 --- a/src/pages/admin-users-page.tsx +++ b/src/pages/admin-users-page.tsx @@ -1,8 +1,9 @@ import { For, Show, Suspense, createResource, createSignal } from "solid-js"; import { getUsers } from "@/api/getUsers"; +import { patchUserPreferences } from "@/api/patchUserPreferences"; import { patchUserRole } from "@/api/patchUserRole"; import { formatApiError } from "@/api/client"; -import type { Role, User } from "@/api/types"; +import type { Role, User, UserLanguage, UserTheme } from "@/api/types"; import { RouteGuard } from "@/components/layout/route-guard"; import { PageHeader } from "@/components/layout/page-header"; import { UserTable } from "@/components/users/user-table"; @@ -45,6 +46,17 @@ function AdminUsersContent() { } }; + const onPreferencesChange = async (userId: string, body: { theme?: UserTheme | null; language?: UserLanguage | null }) => { + setError(""); + try { + await patchUserPreferences(userId, body); + await refetch(); + setFlash(t("common.saved")); + } catch (err) { + setError(formatApiError(err)); + } + }; + return (
@@ -76,7 +88,7 @@ function AdminUsersContent() { }> 0} fallback={{t("admin.noUsers")}}> - + diff --git a/src/pages/dashboard-page.tsx b/src/pages/dashboard-page.tsx index c44f566..f353d49 100644 --- a/src/pages/dashboard-page.tsx +++ b/src/pages/dashboard-page.tsx @@ -216,8 +216,9 @@ function DashboardContent() { { Icon: IconCalendar, titleKey: "nav.events", to: "/events", descKey: "dashboard.portal.eventsDesc", stat: evc, minRole: "teacher" }, { Icon: IconChart, titleKey: "nav.studentMarks", to: "/management/student-marks", descKey: "dashboard.portal.studentMarksDesc", minRole: "teacher" }, { Icon: IconClipboardCheck, titleKey: "nav.studentAttendance", to: "/management/student-attendance", descKey: "dashboard.portal.attendanceDesc", minRole: "teacher" }, - { Icon: IconNote, titleKey: "nav.notes", to: "/notes", descKey: "dashboard.portal.notesDesc", stat: nc }, + { Icon: IconClock, titleKey: "nav.studentPomodoro", to: "/management/pomodoros", descKey: "dashboard.portal.pomodoroDesc", minRole: "teacher" }, { Icon: IconBriefcase, titleKey: "nav.work", to: "/work", descKey: "dashboard.portal.workDesc", minRole: "teacher" }, + { Icon: IconNote, titleKey: "nav.notes", to: "/notes", descKey: "dashboard.portal.notesDesc", stat: nc }, ); return list; } @@ -229,9 +230,10 @@ function DashboardContent() { { Icon: IconUsers, titleKey: "nav.clubs", to: "/clubs", descKey: "dashboard.portal.clubsDesc", stat: clc }, { Icon: IconExam, titleKey: "nav.exams", to: "/exams", descKey: "dashboard.portal.examsDesc", stat: ec }, { Icon: IconCalendar, titleKey: "nav.events", to: "/events", descKey: "dashboard.portal.eventsDesc", stat: evc }, - { Icon: IconNote, titleKey: "nav.notes", to: "/notes", descKey: "dashboard.portal.notesDesc", stat: nc }, { Icon: IconChart, titleKey: "nav.studentMarks", to: "/management/student-marks", descKey: "dashboard.portal.studentMarksDesc", minRole: "teacher" }, { Icon: IconClipboardCheck, titleKey: "nav.studentAttendance", to: "/management/student-attendance", descKey: "dashboard.portal.attendanceDesc", minRole: "teacher" }, + { Icon: IconClock, titleKey: "nav.studentPomodoro", to: "/management/pomodoros", descKey: "dashboard.portal.pomodoroDesc", minRole: "teacher" }, + { Icon: IconNote, titleKey: "nav.notes", to: "/notes", descKey: "dashboard.portal.notesDesc", stat: nc }, { Icon: IconSettings, titleKey: "nav.settings", to: "/management/settings", descKey: "dashboard.portal.settingsDesc", minRole: "manager" }, { Icon: IconCalendarDays, titleKey: "nav.terms", to: "/management/terms", descKey: "dashboard.portal.termsDesc", minRole: "manager" }, ); @@ -248,6 +250,7 @@ function DashboardContent() { const orderedPortalCards = createMemo(() => { const cards = portalCards(); const byId = new Map(cards.map((card) => [card.to, card])); + if (portalOrder().some((id) => !byId.has(id)) || portalOrder().length !== cards.length) return cards; const ordered = portalOrder().flatMap((id) => byId.get(id) ? [byId.get(id)!] : []); const seen = new Set(ordered.map((card) => card.to)); return [...ordered, ...cards.filter((card) => !seen.has(card.to))]; diff --git a/src/pages/student-pomodoro-page.tsx b/src/pages/student-pomodoro-page.tsx new file mode 100644 index 0000000..668a677 --- /dev/null +++ b/src/pages/student-pomodoro-page.tsx @@ -0,0 +1,190 @@ +import { Show, createMemo, createResource, createSignal } from "solid-js"; +import type { ColumnDef } from "@tanstack/solid-table"; +import { getPomodoroByUser } from "@/api/getPomodoroByUser"; +import { getUserSearch } from "@/api/getUserSearch"; +import type { PersonRef, PomodoroSession } from "@/api/types"; +import { ApiError, formatApiError } from "@/api/client"; +import { RouteGuard } from "@/components/layout/route-guard"; +import { PageHeader } from "@/components/layout/page-header"; +import { Alert } from "@/components/ui/alert"; +import { DataTable, DataTableSkeleton } from "@/components/ui/data-table"; +import { ErrorAlert } from "@/components/ui/error-alert"; +import { IconEye } from "@/components/ui/icons"; +import { SidePanel } from "@/components/ui/side-panel"; +import { TableRowActions } from "@/components/ui/table-row-actions"; +import { formatDateTime, formatDurationMinutes } from "@/lib/format"; +import { personLabel } from "@/lib/person"; +import { usePreferences, useT } from "@/stores/preferences-context"; + +const PAGE_SIZE = 12; + +export default function StudentPomodoroPage() { + return ( + + + + ); +} + +function StudentPomodoroContent() { + const t = useT(); + const { locale } = usePreferences(); + const [viewUser, setViewUser] = createSignal(null); + const [error, setError] = createSignal(""); + + const [list] = createResource( + async () => { + try { + setError(""); + return (await getUserSearch("", undefined, "student")).items; + } catch (err) { + setError(formatApiError(err)); + return []; + } + }, + { initialValue: [] }, + ); + + const [log, { refetch: refetchLog }] = createResource( + () => viewUser()?.id ?? null, + async (id) => { + if (!id) return null; + try { + return await getPomodoroByUser(id, { limit: 20 }); + } catch (err) { + if (err instanceof ApiError && err.status === 404) { + setError(t("common.notFound")); + return null; + } + setError(formatApiError(err)); + return null; + } + }, + ); + + const total = () => list().length; + const rows = () => list(); + const listLoading = () => list.loading; + const searchPerson = (person: PersonRef, query: string) => + [person.username, person.display_name, person.id].join(" ").toLocaleLowerCase().includes(query.toLocaleLowerCase()); + const studentColumns = createMemo[]>(() => [ + { + accessorKey: "username", + header: t("admin.username"), + cell: (cell) => {cell.row.original.username}, + }, + { + accessorKey: "display_name", + header: t("profile.name"), + cell: (cell) => {cell.row.original.display_name || "—"}, + }, + { + accessorKey: "id", + header: t("admin.id"), + cell: (cell) => {cell.row.original.id}, + }, + { + id: "actions", + header: t("common.actions"), + meta: { headerClass: "w-14 text-center" }, + cell: (cell) => ( + , + onSelect: () => { + setError(""); + setViewUser(cell.row.original); + }, + }, + ]} + /> + ), + }, + ]); + const logColumns = createMemo[]>(() => [ + { + accessorKey: "started_at", + header: t("pomodoro.startedAt"), + cell: (cell) => {formatDateTime(cell.row.original.started_at, locale())}, + }, + { + accessorKey: "finished_at", + header: t("pomodoro.finishedAt"), + cell: (cell) => {formatDateTime(cell.row.original.finished_at, locale())}, + }, + { + accessorKey: "duration_ms", + header: t("pomodoro.duration"), + cell: (cell) => formatDurationMinutes(cell.row.original.duration_ms, locale()), + }, + ]); + + return ( +
+ + +
+
+
+

{t("nav.studentPomodoro")}

+

+ {rows().length} / {total()} +

+
+
+ + + {error()} + + + }> + + +
+ + { + if (!open) { + setViewUser(null); + setError(""); + } + }} + title={t("pomodoro.forUser", { user: personLabel(viewUser()) })} + description={t("pomodoro.lookup")} + > +
+ + void refetchLog()} /> + + +

{t("common.loading")}

+
+ + {(p) => ( +
+
+

{t("pomodoro.total")}

+

{formatDurationMinutes(p().total_focus_ms, locale())}

+
+ +
+ )} +
+
+
+
+ ); +} diff --git a/src/routes/router.tsx b/src/routes/router.tsx index d68e749..2789707 100644 --- a/src/routes/router.tsx +++ b/src/routes/router.tsx @@ -36,6 +36,7 @@ const MarksPage = lazyRoute(() => import("@/pages/marks-page")); const MessagesPage = lazyRoute(() => import("@/pages/messages-page")); const PomodoroPage = lazyRoute(() => import("@/pages/pomodoro-page")); const StudentMarksPage = lazyRoute(() => import("@/pages/student-marks-page")); +const StudentPomodoroPage = lazyRoute(() => import("@/pages/student-pomodoro-page")); const AttendancePage = lazyRoute(() => import("@/pages/attendance-page")); const StudentAttendancePage = lazyRoute(() => import("@/pages/student-attendance-page")); const WorkLogPage = lazyRoute(() => import("@/pages/work-log-page")); @@ -173,6 +174,12 @@ const studentMarksRoute = createRoute({ component: StudentMarksPage, }); +const studentPomodoroRoute = createRoute({ + getParentRoute: () => rootRoute, + path: "/management/pomodoros", + component: StudentPomodoroPage, +}); + const attendanceRoute = createRoute({ getParentRoute: () => rootRoute, path: "/attendance", @@ -252,6 +259,7 @@ const routeTree = rootRoute.addChildren([ messagesRoute, pomodoroRoute, studentMarksRoute, + studentPomodoroRoute, attendanceRoute, studentAttendanceRoute, workRoute,