forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits

record-list-path.ts24 lines, 912 bytesHistoryRawDownload
1import { ApiError } from "@/api/client";
2
3/** A read that failed because the record is not there (deleted, or a bad link). */
4export function isNotFoundError(err: unknown): boolean {
5 return err instanceof ApiError && err.status === 404;
6}
7
8// Detail routes whose parent path is not a list page of their own.
9const LIST_OVERRIDES: Record<string, string> = {
10 "/instances": "/courses",
11};
12
13/**
14 * The list a detail URL belongs to: its path minus the last segment
15 * (`/management/classes/abc` → `/management/classes`), when that is a route
16 * the app has; otherwise the home page.
17 */
18export function listPathFor(pathname: string, hasRoute: (path: string) => boolean): string {
19 const trimmed = pathname.replace(/\/+$/, "");
20 const parent = trimmed.slice(0, trimmed.lastIndexOf("/"));
21 if (!parent) return "/";
22 const target = LIST_OVERRIDES[parent] ?? parent;
23 return hasRoute(target) ? target : "/";
24}