Skip to content
This repository was archived by the owner on Aug 13, 2024. It is now read-only.

Commit 5429e0f

Browse files
committed
feat: use a safe typed routeur
1 parent c615a23 commit 5429e0f

File tree

9 files changed

+67
-29
lines changed

9 files changed

+67
-29
lines changed

docker-compose.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ services:
66
depends_on:
77
backend:
88
condition: service_started
9+
910
backend:
1011
image: torii-backend:latest
1112
restart: always
@@ -16,4 +17,4 @@ services:
1617
volumes:
1718
- type: bind
1819
source: ./backend
19-
target: /tmp
20+
target: /tmp

frontend/Caddyfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
file_server {
55
hide .git
66
}
7-
}
7+
}

frontend/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ WORKDIR /app
88
USER nobody
99
COPY --chown=nobody:nobody --from=builder /app/dist/ dist/
1010
COPY --chown=nobody:nobody Caddyfile .
11-
ENTRYPOINT ["caddy","run"]
11+
ENTRYPOINT ["caddy","run"]

frontend/components.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
"components": "@/components",
1414
"utils": "@/lib/utils"
1515
}
16-
}
16+
}

frontend/package-lock.json

Lines changed: 42 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"@headlessui/react": "^1.7.17",
1414
"@heroicons/react": "^2.0.18",
1515
"@radix-ui/react-slot": "^1.0.2",
16+
"@swan-io/chicane": "^1.4.1",
1617
"@tailwindcss/forms": "^0.5.7",
1718
"@tanstack/react-query": "^5.13.4",
1819
"class-variance-authority": "^0.7.0",
@@ -25,7 +26,8 @@
2526
"react-router-dom": "^6.20.1",
2627
"sort-by": "^1.2.0",
2728
"tailwind-merge": "^2.1.0",
28-
"tailwindcss-animate": "^1.0.7"
29+
"tailwindcss-animate": "^1.0.7",
30+
"ts-pattern": "^5.0.6"
2931
},
3032
"devDependencies": {
3133
"@tanstack/react-query": "^5.13.4",

frontend/src/error-page.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ export default function ErrorPage() {
66

77
return (<div id="error-page">
88
<h1>Oops!</h1>
9+
910
<p>Sorry, an unexpected error has occurred.</p>
11+
1012
<p>
1113
<i>{error.statusText || error.message}</i>
1214
</p>

frontend/src/main.tsx

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,31 @@
11
import React from 'react'
22
import ReactDOM from 'react-dom/client'
33
import './main.css'
4-
import {QueryClient, QueryClientProvider,} from '@tanstack/react-query'
5-
import {createBrowserRouter, RouterProvider,} from "react-router-dom";
4+
import {QueryClient, QueryClientProvider} from '@tanstack/react-query'
65

7-
import Root from "./routes/root";
8-
// @ts-ignore
96
import ErrorPage from "@/error-page.jsx";
107
import AppShell from "@/components/AppShell.tsx";
8+
import { createRouter } from "@swan-io/chicane";
9+
import { match } from "ts-pattern";
1110

12-
const router = createBrowserRouter([
13-
{
14-
path: "/",
15-
element: <Root/>,
16-
errorElement: <ErrorPage/>,
17-
children: [
18-
{
19-
index: true,
20-
element: <AppShell/>,
21-
},
22-
// {
23-
// path: "/catalogs/:catalogSlug/services",
24-
// Component: AppShell,
25-
// }
26-
],
27-
},
28-
]);
11+
const Router = createRouter({
12+
Home: "/",
13+
});
14+
15+
const App = () => {
16+
const route = Router.useRoute(["Home"]);
17+
18+
return match(route)
19+
.with({ name: "Home" }, () => <AppShell/>)
20+
.otherwise(() => <ErrorPage/>);
21+
};
2922

3023
const queryClient = new QueryClient()
3124

3225
ReactDOM.createRoot(document.getElementById('root')!).render(
3326
<React.StrictMode>
3427
<QueryClientProvider client={queryClient}>
35-
<RouterProvider router={router}/>
28+
<App />
3629
</QueryClientProvider>
3730
</React.StrictMode>,
3831
)

frontend/src/routes/root.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import AppShell from "@/components/AppShell.tsx";
22

3-
43
export default function Root() {
54
return <AppShell/>
65
}

0 commit comments

Comments
 (0)