hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits
| 1 | /** |
| 2 | * Which backend module a route's page is built on, by path prefix. A school |
| 3 | * with that module switched off gets `403 {error, module}` from every call the |
| 4 | * page would make, so the shell shows a "switched off" screen instead of |
| 5 | * rendering a page that can only fail. Routes built on core surfaces (home, |
| 6 | * calendar, users, settings, profile) map to nothing and always render. |
| 7 | * |
| 8 | * Longest prefix wins, so the `/management/*` and `/students/*` entries are |
| 9 | * matched ahead of the shorter ones. |
| 10 | */ |
| 11 | const ROUTE_MODULES: ReadonlyArray<readonly [prefix: string, module: string]> = [ |
| 12 | ["/management/student-attendance", "attendance"], |
| 13 | ["/management/student-marks", "marks"], |
| 14 | ["/management/pomodoros", "pomodoro"], |
| 15 | ["/management/payments", "payments"], |
| 16 | ["/management/staff-work", "work"], |
| 17 | ["/management/classes", "classes"], |
| 18 | ["/students/attendance", "attendance"], |
| 19 | ["/students/exams", "marks"], |
| 20 | ["/students/study", "pomodoro"], |
| 21 | // Note Studio works on course notes (lists them, runs RAG/podcast over them). |
| 22 | ["/ai/studio", "course_notes"], |
| 23 | ["/question-bank", "bank_questions"], |
| 24 | ["/appointments", "appointments"], |
| 25 | ["/whiteboards", "boards"], |
| 26 | ["/attendance", "attendance"], |
| 27 | ["/exam-room", "exams"], |
| 28 | ["/questions", "questions"], |
| 29 | ["/messages", "messages"], |
| 30 | ["/homework", "homework"], |
| 31 | ["/pomodoro", "pomodoro"], |
| 32 | ["/payments", "payments"], |
| 33 | ["/courses", "courses"], |
| 34 | ["/studies", "courses"], |
| 35 | ["/events", "events"], |
| 36 | ["/clubs", "courses"], |
| 37 | ["/exams", "exams"], |
| 38 | ["/marks", "marks"], |
| 39 | ["/meals", "meals"], |
| 40 | ["/notes", "notes"], |
| 41 | ["/work", "work"], |
| 42 | ]; |
| 43 | |
| 44 | export function routeModule(pathname: string): string | null { |
| 45 | let best: readonly [string, string] | null = null; |
| 46 | for (const entry of ROUTE_MODULES) { |
| 47 | const [prefix] = entry; |
| 48 | if ((pathname === prefix || pathname.startsWith(`${prefix}/`)) && (!best || prefix.length > best[0].length)) best = entry; |
| 49 | } |
| 50 | return best?.[1] ?? null; |
| 51 | } |