"use client"; import React from "react"; import Link from "next/link"; import { CalendarDays, RefreshCw } from "lucide-react"; import { getYears } from "@/lib/frontend/apiClient"; import { branchPath, yearPath } from "@/lib/frontend/routes"; import { sortNumericStringsDesc } from "@/lib/frontend/explorer/sorters"; import { mapExplorerError } from "@/lib/frontend/explorer/errorMapping"; import { buildLoginUrl, LOGIN_REASONS } from "@/lib/frontend/authRedirect"; import { useExplorerQuery } from "@/lib/frontend/hooks/useExplorerQuery"; import ExplorerBreadcrumbs from "@/components/explorer/breadcrumbs/ExplorerBreadcrumbs"; import ExplorerPageShell from "@/components/explorer/ExplorerPageShell"; import ExplorerSectionCard from "@/components/explorer/ExplorerSectionCard"; import ExplorerLoading from "@/components/explorer/states/ExplorerLoading"; import ExplorerEmpty from "@/components/explorer/states/ExplorerEmpty"; import ExplorerError from "@/components/explorer/states/ExplorerError"; import ExplorerNotFound from "@/components/explorer/states/ExplorerNotFound"; import ForbiddenView from "@/components/system/ForbiddenView"; import { Button } from "@/components/ui/button"; /** * YearsExplorer * * Explorer entry level for a branch: shows available years. * * @param {{ branch: string }} props */ export default function YearsExplorer({ branch }) { const loadFn = React.useCallback(() => getYears(branch), [branch]); const { status, data, error, retry } = useExplorerQuery(loadFn, [loadFn]); const mapped = React.useMemo(() => mapExplorerError(error), [error]); React.useEffect(() => { if (mapped?.kind !== "unauthenticated") return; const next = typeof window !== "undefined" ? `${window.location.pathname}${window.location.search}` : branchPath(branch); window.location.replace( buildLoginUrl({ reason: LOGIN_REASONS.EXPIRED, next }) ); }, [mapped?.kind, branch]); const breadcrumbsNode = ; const actions = ( Aktualisieren ); if (status === "loading") { return ( ); } if (status === "error" && mapped) { if (mapped.kind === "forbidden") return ; if (mapped.kind === "notfound") { return ( ); } if (mapped.kind === "unauthenticated") { return ( ); } return ( ); } const years = Array.isArray(data?.years) ? data.years : []; const sorted = sortNumericStringsDesc(years); return ( {sorted.length} Jahr{sorted.length === 1 ? "" : "e"} } > {sorted.length === 0 ? ( ) : ( {sorted.map((y) => ( {y} ))} )} ); }