Files
radicle-explorer/src/lib/router/definitions.ts
T
Rūdolfs Ošiņš 4a5e67dd2b Improve authentication error modal
We tell users to check their firewall and ad blocker settings in case
they bump into authentication problems. This also separates out the
modal to be only used by the session view.
2024-02-26 13:03:44 +00:00

85 lines
2.0 KiB
TypeScript

import type {
ResponseError,
ResponseParseError,
} from "@httpd-client/lib/fetcher";
import type { HomeRoute, HomeLoadedRoute } from "@app/views/home/router";
import type {
ProjectLoadedRoute,
ProjectRoute,
} from "@app/views/projects/router";
import type { NodesRoute, NodesLoadedRoute } from "@app/views/nodes/router";
import { loadHomeRoute } from "@app/views/home/router";
import { loadProjectRoute } from "@app/views/projects/router";
import { loadNodeRoute } from "@app/views/nodes/router";
interface BootingRoute {
resource: "booting";
}
export interface NotFoundRoute {
resource: "notFound";
params: { title: string };
}
export interface SessionRoute {
resource: "session";
params: {
id: string;
signature: string;
publicKey: string;
apiAddr: string;
path?: string;
};
}
export type ErrorParam = Error | ResponseParseError | ResponseError | undefined;
export interface ErrorRoute {
resource: "error";
params: {
title: string;
description: string;
error: ErrorParam;
};
}
export type Route =
| BootingRoute
| HomeRoute
| ErrorRoute
| NotFoundRoute
| ProjectRoute
| NodesRoute
| SessionRoute;
export type LoadedRoute =
| BootingRoute
| HomeLoadedRoute
| ErrorRoute
| NotFoundRoute
| ProjectLoadedRoute
| NodesLoadedRoute
| SessionRoute;
export async function loadRoute(route: Route): Promise<LoadedRoute> {
if (route.resource === "nodes") {
return await loadNodeRoute(route.params);
} else if (route.resource === "home") {
return await loadHomeRoute();
} else if (
route.resource === "project.source" ||
route.resource === "project.history" ||
route.resource === "project.commit" ||
route.resource === "project.issues" ||
route.resource === "project.newIssue" ||
route.resource === "project.issue" ||
route.resource === "project.patches" ||
route.resource === "project.patch"
) {
return await loadProjectRoute(route);
} else {
return route;
}
}