-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathroutes.ts
More file actions
68 lines (63 loc) · 1.88 KB
/
Copy pathroutes.ts
File metadata and controls
68 lines (63 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// ==== Contract routes constants ====
export type ContractTabId = 'home' | 'create' | 'deploy' | 'interact' | 'faucet' | 'contracts' | 'assets';
export const CONTRACT_TABS: { value: ContractTabId; label: string; href: string }[] = [
{
value: 'home',
label: 'Playground',
href: '/d/playground',
},
{
value: 'create',
label: 'Editor',
href: '/d/playground/create',
},
{
value: 'deploy',
label: 'Deploy',
href: '/d/playground/deploy',
},
{
value: 'interact',
label: 'Interact',
href: '/d/playground/interact',
},
{
value: 'contracts',
label: 'Contracts',
href: '/d/playground/contracts',
},
{
value: 'faucet',
label: 'Faucet',
href: '/d/playground/faucet',
},
{
value: 'assets',
label: 'Assets',
href: '/d/playground/assets',
},
] as const;
// ==== App routes ====
export const routes = {
home: '/',
playground: {
index: CONTRACT_TABS.find((tab) => tab.value === 'home')!.href,
create: CONTRACT_TABS.find((tab) => tab.value === 'create')!.href,
deploy: CONTRACT_TABS.find((tab) => tab.value === 'deploy')!.href,
interact: CONTRACT_TABS.find((tab) => tab.value === 'interact')!.href,
faucet: CONTRACT_TABS.find((tab) => tab.value === 'faucet')!.href,
assets: CONTRACT_TABS.find((tab) => tab.value === 'assets')!.href,
contracts: CONTRACT_TABS.find((tab) => tab.value === 'contracts')!.href,
},
} as const;
type RouteValue = string | Record<string, unknown> | ((...args: string[]) => string);
type FlattenRoutes<T extends Record<string, RouteValue>, Prefix extends string = ''> = {
[K in keyof T]: T[K] extends (...args: string[]) => string
? T[K]
: T[K] extends string
? `${Prefix}${T[K]}`
: T[K] extends Record<string, RouteValue>
? FlattenRoutes<T[K], `${Prefix}${K & string}/`>
: never;
}[keyof T];
export type AppRoute = FlattenRoutes<typeof routes>;