hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits
| 1 | import { Link, useLocation } from "@tanstack/solid-router"; |
| 2 | import { type ParentProps, Show } from "solid-js"; |
| 3 | import { IconHome, IconPackage } from "@/components/ui/icons"; |
| 4 | import { PageSpinner } from "@/components/ui/page-spinner"; |
| 5 | import { moduleLabel } from "@/lib/module-labels"; |
| 6 | import { routeModule } from "@/lib/route-module"; |
| 7 | import { useModules } from "@/stores/modules-context"; |
| 8 | import { useT } from "@/stores/preferences-context"; |
| 9 | |
| 10 | /** |
| 11 | * Stands in for a page whose module the school has switched off. Without it |
| 12 | * the page mounts, every call 403s, and the user lands on a blank or error |
| 13 | * screen — typically from a bookmark, a stale tab, or a module turned off |
| 14 | * mid-session. Unknown module state (loading, lookup failed) renders the page. |
| 15 | */ |
| 16 | export function ModuleGate(props: ParentProps) { |
| 17 | const t = useT(); |
| 18 | const location = useLocation(); |
| 19 | const modules = useModules(); |
| 20 | const off = () => { |
| 21 | const module = routeModule(location().pathname); |
| 22 | const enabled = modules.enabled(); |
| 23 | return module && enabled && !enabled.includes(module) ? module : null; |
| 24 | }; |
| 25 | |
| 26 | // Until the school's list arrives a module page would fire its reads blind; |
| 27 | // a spinner for that first beat keeps an off module from ever being asked. |
| 28 | return ( |
| 29 | <Show when={!(routeModule(location().pathname) && modules.loading())} fallback={<PageSpinner />}> |
| 30 | <Show when={off()} fallback={props.children}> |
| 31 | {(module) => ( |
| 32 | <div class="flex min-h-[50vh] items-center justify-center px-4 py-16"> |
| 33 | <div class="w-full max-w-[440px] space-y-5 rounded-xl border border-border-line bg-surface-base p-8 text-center shadow-[0_10px_24px_-4px_rgba(0,0,0,0.10)]"> |
| 34 | <div class="mx-auto flex h-14 w-14 items-center justify-center rounded-full bg-muted text-text-subtle"> |
| 35 | <IconPackage class="h-6 w-6" /> |
| 36 | </div> |
| 37 | <div class="space-y-2"> |
| 38 | <p class="text-base font-semibold text-text-strong">{t("modules.offTitle", { module: moduleLabel(module(), t) })}</p> |
| 39 | <p class="text-sm leading-[21px] text-text-subtle">{t("modules.offDescription")}</p> |
| 40 | </div> |
| 41 | <Link |
| 42 | to="/" |
| 43 | class="inline-flex h-9 items-center justify-center gap-1.5 whitespace-nowrap rounded-lg bg-primary px-3 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90" |
| 44 | > |
| 45 | <IconHome class="mr-1 h-4 w-4" /> |
| 46 | {t("common.goHome")} |
| 47 | </Link> |
| 48 | </div> |
| 49 | </div> |
| 50 | )} |
| 51 | </Show> |
| 52 | </Show> |
| 53 | ); |
| 54 | } |