mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-27 03:41:11 +01:00
Typesafe routing and CM line height issue
This commit is contained in:
39
src-web/hooks/useRoutes.ts
Normal file
39
src-web/hooks/useRoutes.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
export type RouteParamsWorkspace = {
|
||||
workspaceId: string;
|
||||
};
|
||||
|
||||
export type RouteParamsRequest = RouteParamsWorkspace & {
|
||||
requestId: string;
|
||||
};
|
||||
|
||||
export const routePaths = {
|
||||
workspaces() {
|
||||
return '/workspaces';
|
||||
},
|
||||
workspace({ workspaceId } = { workspaceId: ':workspaceId' } as RouteParamsWorkspace) {
|
||||
return `/workspaces/${workspaceId}`;
|
||||
},
|
||||
request(
|
||||
{ workspaceId, requestId } = {
|
||||
workspaceId: ':workspaceId',
|
||||
requestId: ':requestId',
|
||||
} as RouteParamsRequest,
|
||||
) {
|
||||
return `${this.workspace({ workspaceId })}/requests/${requestId}`;
|
||||
},
|
||||
};
|
||||
|
||||
export function useRoutes() {
|
||||
return {
|
||||
navigate<T extends keyof typeof routePaths>(
|
||||
path: T,
|
||||
params: Parameters<(typeof routePaths)[T]>[0],
|
||||
) {
|
||||
// Not sure how to make TS work here, but it's good from the
|
||||
// outside caller perspective.
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
routePaths[path](params as any);
|
||||
},
|
||||
paths: routePaths,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user