Skip to content

Commit 9b2296d

Browse files
feat: add lunalink and enjoy route inference (#561)
1 parent a4fff2b commit 9b2296d

13 files changed

+89
-38
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"*.{ts,tsx,js,jsx,json}": "prettier --write"
4343
},
4444
"dependencies": {
45+
"@bearstudio/lunalink": "0.1.2",
4546
"@chakra-ui/anatomy": "2.2.2",
4647
"@chakra-ui/next-js": "2.2.0",
4748
"@chakra-ui/react": "2.8.2",

pnpm-lock.yaml

+49-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/features/account/routes.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { ROUTES_APP } from '@/features/app/routes';
33

44
export const ROUTES_ACCOUNT = {
55
app: {
6-
root: () => `${ROUTES_APP.baseUrl()}/account`,
6+
root: () => `${ROUTES_APP.baseUrl()}/account` as const,
77
},
88
admin: {
9-
root: () => `${ROUTES_ADMIN.baseUrl()}/account`,
10-
profile: () => `${ROUTES_ACCOUNT.admin.root()}/profile`,
11-
email: () => `${ROUTES_ACCOUNT.admin.root()}/email`,
9+
root: () => `${ROUTES_ADMIN.baseUrl()}/account` as const,
10+
profile: () => `${ROUTES_ACCOUNT.admin.root()}/profile` as const,
11+
email: () => `${ROUTES_ACCOUNT.admin.root()}/email` as const,
1212
},
1313
} as const;

src/features/admin/routes.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
export const ROUTES_ADMIN = {
2-
root: () => '/admin',
2+
root: () => '/admin' as const,
33
// This check seems useless at first but is not. It it a guard to avoid double
44
// slash in the URL if it is changed one day or another. So don't remove it
55
// and keep it this way.
6-
baseUrl: () => (ROUTES_ADMIN.root() === '/' ? '' : ROUTES_ADMIN.root()),
6+
baseUrl: () =>
7+
// @ts-expect-error see comment above
8+
ROUTES_ADMIN.root() === ('/' as const) ? '' : ROUTES_ADMIN.root(),
79
} as const;

src/features/app/routes.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
export const ROUTES_APP = {
2-
root: () => '/app',
2+
root: () => '/app' as const,
33
// This check seems useless at first but is not. It it a guard to avoid double
44
// slash in the URL if it is changed one day or another. So don't remove it
55
// and keep it this way.
6-
baseUrl: () => (ROUTES_APP.root() === '/' ? '' : ROUTES_APP.root()),
6+
baseUrl: () =>
7+
// @ts-expect-error see comment above
8+
ROUTES_APP.root() === '/' ? ('' as const) : ROUTES_APP.root(),
79
} as const;

src/features/management/routes.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import { ROUTES_ADMIN } from '@/features/admin/routes';
22

33
export const ROUTES_MANAGEMENT = {
44
admin: {
5-
root: () => `${ROUTES_ADMIN.baseUrl()}/management`,
5+
root: () => `${ROUTES_ADMIN.baseUrl()}/management` as const,
66
},
77
} as const;

src/features/repositories/AdminRepositoryActions.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22

3+
import { lunalink } from '@bearstudio/lunalink';
34
import {
45
Menu,
56
MenuButton,
@@ -54,14 +55,18 @@ export const AdminRepositoryActions = ({
5455
<MenuList>
5556
<MenuItem
5657
as={Link}
57-
href={ROUTES_REPOSITORIES.admin.repository({ id: repository.id })}
58+
href={lunalink(ROUTES_REPOSITORIES.admin.repository(), {
59+
id: repository.id,
60+
})}
5861
icon={<Icon icon={LuEye} fontSize="lg" color="gray.400" />}
5962
>
6063
{t('repositories:list.actions.view')}
6164
</MenuItem>
6265
<MenuItem
6366
as={Link}
64-
href={ROUTES_REPOSITORIES.admin.update({ id: repository.id })}
67+
href={lunalink(ROUTES_REPOSITORIES.admin.update(), {
68+
id: repository.id,
69+
})}
6570
icon={<Icon icon={LuPenLine} fontSize="lg" color="gray.400" />}
6671
>
6772
{t('common:actions.edit')}

src/features/repositories/PageAdminRepositories.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22

3+
import { lunalink } from '@bearstudio/lunalink';
34
import {
45
Button,
56
Flex,
@@ -105,7 +106,7 @@ export default function PageAdminRepositories() {
105106
<DataListText fontWeight="bold">
106107
<LinkOverlay
107108
as={Link}
108-
href={ROUTES_REPOSITORIES.admin.repository({
109+
href={lunalink(ROUTES_REPOSITORIES.admin.repository(), {
109110
id: repository.id,
110111
})}
111112
>

src/features/repositories/PageAdminRepository.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22

3+
import { lunalink } from '@bearstudio/lunalink';
34
import {
45
Box,
56
Card,
@@ -65,8 +66,8 @@ export default function PageAdminRepository() {
6566
<>
6667
<ResponsiveIconButton
6768
as={Link}
68-
href={ROUTES_REPOSITORIES.admin.update({
69-
id: params?.id?.toString() ?? 'unknown',
69+
href={lunalink(ROUTES_REPOSITORIES.admin.update(), {
70+
id: params.id?.toString() ?? 'unknown',
7071
})}
7172
isDisabled={!params?.id}
7273
icon={<LuPenLine />}

src/features/repositories/routes.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ import { ROUTES_APP } from '@/features/app/routes';
33

44
export const ROUTES_REPOSITORIES = {
55
app: {
6-
root: () => `${ROUTES_APP.baseUrl()}/repositories`,
6+
root: () => `${ROUTES_APP.baseUrl()}/repositories` as const,
77
},
88
admin: {
9-
root: () => `${ROUTES_ADMIN.baseUrl()}/repositories`,
10-
create: () => `${ROUTES_REPOSITORIES.admin.root()}/create`,
11-
repository: (params: { id: string }) =>
12-
`${ROUTES_REPOSITORIES.admin.root()}/${params.id}`,
13-
update: (params: { id: string }) =>
14-
`${ROUTES_REPOSITORIES.admin.root()}/${params.id}/update`,
9+
root: () => `${ROUTES_ADMIN.baseUrl()}/repositories` as const,
10+
create: () => `${ROUTES_REPOSITORIES.admin.root()}/create` as const,
11+
repository: () => `${ROUTES_REPOSITORIES.admin.root()}/:id` as const,
12+
update: () => `${ROUTES_REPOSITORIES.admin.root()}/:id/update` as const,
1513
},
1614
} as const;

src/features/users/AdminUserActions.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22

3+
import { lunalink } from '@bearstudio/lunalink';
34
import {
45
Menu,
56
MenuButton,
@@ -100,7 +101,7 @@ export const AdminUserActions = ({ user, ...rest }: AdminUserActionProps) => {
100101
<MenuList>
101102
<MenuItem
102103
as={Link}
103-
href={ROUTES_USERS.admin.user({ id: user.id })}
104+
href={lunalink(ROUTES_USERS.admin.user(), { id: user.id })}
104105
icon={<Icon icon={LuPenLine} fontSize="lg" color="gray.400" />}
105106
>
106107
{t('common:actions.edit')}

src/features/users/PageAdminUsers.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { ElementRef, useRef } from 'react';
22

3+
import { lunalink } from '@bearstudio/lunalink';
34
import {
45
Avatar,
56
Button,
@@ -127,7 +128,9 @@ export default function PageAdminUsers() {
127128
)}
128129
<LinkOverlay
129130
as={Link}
130-
href={ROUTES_USERS.admin.user({ id: user.id })}
131+
href={lunalink(ROUTES_USERS.admin.user(), {
132+
id: user.id,
133+
})}
131134
>
132135
{user.name ?? user.email}
133136
</LinkOverlay>

src/features/users/routes.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import { ROUTES_MANAGEMENT } from '@/features/management/routes';
22

33
export const ROUTES_USERS = {
44
admin: {
5-
root: () => `${ROUTES_MANAGEMENT.admin.root()}/users`,
6-
create: () => `${ROUTES_USERS.admin.root()}/create`,
7-
user: (params: { id: string }) =>
8-
`${ROUTES_USERS.admin.root()}/${params.id}`,
5+
root: () => `${ROUTES_MANAGEMENT.admin.root()}/users` as const,
6+
create: () => `${ROUTES_USERS.admin.root()}/create` as const,
7+
user: () => `${ROUTES_USERS.admin.root()}/:id` as const,
98
},
109
} as const;

0 commit comments

Comments
 (0)