Skip to content

Commit 5de97bd

Browse files
committed
TanStack Router cleaned up - twas a journey
1 parent c44213c commit 5de97bd

File tree

14 files changed

+124
-159
lines changed

14 files changed

+124
-159
lines changed

frontend/src/routeTree.gen.ts

Lines changed: 93 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@ import { Route as SignupImport } from './routes/signup'
1515
import { Route as ResetPasswordImport } from './routes/reset-password'
1616
import { Route as RecoverPasswordImport } from './routes/recover-password'
1717
import { Route as LoginImport } from './routes/login'
18-
import { Route as LayoutImport } from './routes/_layout'
19-
import { Route as LayoutIndexImport } from './routes/_layout/index'
20-
import { Route as LayoutSettingsImport } from './routes/_layout/settings'
21-
import { Route as LayoutPathsImport } from './routes/_layout/paths'
22-
import { Route as LayoutItemsImport } from './routes/_layout/items'
23-
import { Route as LayoutAdminImport } from './routes/_layout/admin'
24-
import { Route as PathsCreateIndexImport } from './routes/paths/create/index'
25-
import { Route as PathsPathIdIndexImport } from './routes/paths/$pathId/index'
18+
import { Route as AuthenticatedImport } from './routes/_authenticated'
19+
import { Route as AuthenticatedIndexImport } from './routes/_authenticated/index'
20+
import { Route as AuthenticatedSettingsImport } from './routes/_authenticated/settings'
21+
import { Route as AuthenticatedItemsImport } from './routes/_authenticated/items'
22+
import { Route as AuthenticatedAdminImport } from './routes/_authenticated/admin'
23+
import { Route as AuthenticatedPathsIndexImport } from './routes/_authenticated/paths/index'
24+
import { Route as AuthenticatedLearnIndexImport } from './routes/_authenticated/learn/index'
25+
import { Route as AuthenticatedPathsCreateImport } from './routes/_authenticated/paths/create'
26+
import { Route as AuthenticatedPathsPathIdImport } from './routes/_authenticated/paths/$pathId'
27+
import { Route as AuthenticatedLearnChatImport } from './routes/_authenticated/learn/chat'
28+
import { Route as AuthenticatedLearnPathIdImport } from './routes/_authenticated/learn/$pathId'
2629

2730
// Create/Update Routes
2831

@@ -46,52 +49,67 @@ const LoginRoute = LoginImport.update({
4649
getParentRoute: () => rootRoute,
4750
} as any)
4851

49-
const LayoutRoute = LayoutImport.update({
50-
id: '/_layout',
52+
const AuthenticatedRoute = AuthenticatedImport.update({
53+
id: '/_authenticated',
5154
getParentRoute: () => rootRoute,
5255
} as any)
5356

54-
const LayoutIndexRoute = LayoutIndexImport.update({
57+
const AuthenticatedIndexRoute = AuthenticatedIndexImport.update({
5558
path: '/',
56-
getParentRoute: () => LayoutRoute,
59+
getParentRoute: () => AuthenticatedRoute,
5760
} as any)
5861

59-
const LayoutSettingsRoute = LayoutSettingsImport.update({
62+
const AuthenticatedSettingsRoute = AuthenticatedSettingsImport.update({
6063
path: '/settings',
61-
getParentRoute: () => LayoutRoute,
64+
getParentRoute: () => AuthenticatedRoute,
6265
} as any)
6366

64-
const LayoutPathsRoute = LayoutPathsImport.update({
65-
path: '/paths',
66-
getParentRoute: () => LayoutRoute,
67-
} as any)
68-
69-
const LayoutItemsRoute = LayoutItemsImport.update({
67+
const AuthenticatedItemsRoute = AuthenticatedItemsImport.update({
7068
path: '/items',
71-
getParentRoute: () => LayoutRoute,
69+
getParentRoute: () => AuthenticatedRoute,
7270
} as any)
7371

74-
const LayoutAdminRoute = LayoutAdminImport.update({
72+
const AuthenticatedAdminRoute = AuthenticatedAdminImport.update({
7573
path: '/admin',
76-
getParentRoute: () => LayoutRoute,
74+
getParentRoute: () => AuthenticatedRoute,
7775
} as any)
7876

79-
const PathsCreateIndexRoute = PathsCreateIndexImport.update({
80-
path: '/paths/create/',
81-
getParentRoute: () => rootRoute,
77+
const AuthenticatedPathsIndexRoute = AuthenticatedPathsIndexImport.update({
78+
path: '/paths/',
79+
getParentRoute: () => AuthenticatedRoute,
8280
} as any)
8381

84-
const PathsPathIdIndexRoute = PathsPathIdIndexImport.update({
85-
path: '/paths/$pathId/',
86-
getParentRoute: () => rootRoute,
82+
const AuthenticatedLearnIndexRoute = AuthenticatedLearnIndexImport.update({
83+
path: '/learn/',
84+
getParentRoute: () => AuthenticatedRoute,
85+
} as any)
86+
87+
const AuthenticatedPathsCreateRoute = AuthenticatedPathsCreateImport.update({
88+
path: '/paths/create',
89+
getParentRoute: () => AuthenticatedRoute,
90+
} as any)
91+
92+
const AuthenticatedPathsPathIdRoute = AuthenticatedPathsPathIdImport.update({
93+
path: '/paths/$pathId',
94+
getParentRoute: () => AuthenticatedRoute,
95+
} as any)
96+
97+
const AuthenticatedLearnChatRoute = AuthenticatedLearnChatImport.update({
98+
path: '/learn/chat',
99+
getParentRoute: () => AuthenticatedRoute,
100+
} as any)
101+
102+
const AuthenticatedLearnPathIdRoute = AuthenticatedLearnPathIdImport.update({
103+
path: '/learn/$pathId',
104+
getParentRoute: () => AuthenticatedRoute,
87105
} as any)
88106

89107
// Populate the FileRoutesByPath interface
90108

91109
declare module '@tanstack/react-router' {
92110
interface FileRoutesByPath {
93-
'/_layout': {
94-
preLoaderRoute: typeof LayoutImport
111+
'/_authenticated': {
112+
preLoaderRoute: typeof AuthenticatedImport
95113
parentRoute: typeof rootRoute
96114
}
97115
'/login': {
@@ -110,53 +128,68 @@ declare module '@tanstack/react-router' {
110128
preLoaderRoute: typeof SignupImport
111129
parentRoute: typeof rootRoute
112130
}
113-
'/_layout/admin': {
114-
preLoaderRoute: typeof LayoutAdminImport
115-
parentRoute: typeof LayoutImport
131+
'/_authenticated/admin': {
132+
preLoaderRoute: typeof AuthenticatedAdminImport
133+
parentRoute: typeof AuthenticatedImport
116134
}
117-
'/_layout/items': {
118-
preLoaderRoute: typeof LayoutItemsImport
119-
parentRoute: typeof LayoutImport
135+
'/_authenticated/items': {
136+
preLoaderRoute: typeof AuthenticatedItemsImport
137+
parentRoute: typeof AuthenticatedImport
120138
}
121-
'/_layout/paths': {
122-
preLoaderRoute: typeof LayoutPathsImport
123-
parentRoute: typeof LayoutImport
139+
'/_authenticated/settings': {
140+
preLoaderRoute: typeof AuthenticatedSettingsImport
141+
parentRoute: typeof AuthenticatedImport
124142
}
125-
'/_layout/settings': {
126-
preLoaderRoute: typeof LayoutSettingsImport
127-
parentRoute: typeof LayoutImport
143+
'/_authenticated/': {
144+
preLoaderRoute: typeof AuthenticatedIndexImport
145+
parentRoute: typeof AuthenticatedImport
128146
}
129-
'/_layout/': {
130-
preLoaderRoute: typeof LayoutIndexImport
131-
parentRoute: typeof LayoutImport
147+
'/_authenticated/learn/$pathId': {
148+
preLoaderRoute: typeof AuthenticatedLearnPathIdImport
149+
parentRoute: typeof AuthenticatedImport
132150
}
133-
'/paths/$pathId/': {
134-
preLoaderRoute: typeof PathsPathIdIndexImport
135-
parentRoute: typeof rootRoute
151+
'/_authenticated/learn/chat': {
152+
preLoaderRoute: typeof AuthenticatedLearnChatImport
153+
parentRoute: typeof AuthenticatedImport
136154
}
137-
'/paths/create/': {
138-
preLoaderRoute: typeof PathsCreateIndexImport
139-
parentRoute: typeof rootRoute
155+
'/_authenticated/paths/$pathId': {
156+
preLoaderRoute: typeof AuthenticatedPathsPathIdImport
157+
parentRoute: typeof AuthenticatedImport
158+
}
159+
'/_authenticated/paths/create': {
160+
preLoaderRoute: typeof AuthenticatedPathsCreateImport
161+
parentRoute: typeof AuthenticatedImport
162+
}
163+
'/_authenticated/learn/': {
164+
preLoaderRoute: typeof AuthenticatedLearnIndexImport
165+
parentRoute: typeof AuthenticatedImport
166+
}
167+
'/_authenticated/paths/': {
168+
preLoaderRoute: typeof AuthenticatedPathsIndexImport
169+
parentRoute: typeof AuthenticatedImport
140170
}
141171
}
142172
}
143173

144174
// Create and export the route tree
145175

146176
export const routeTree = rootRoute.addChildren([
147-
LayoutRoute.addChildren([
148-
LayoutAdminRoute,
149-
LayoutItemsRoute,
150-
LayoutPathsRoute,
151-
LayoutSettingsRoute,
152-
LayoutIndexRoute,
177+
AuthenticatedRoute.addChildren([
178+
AuthenticatedAdminRoute,
179+
AuthenticatedItemsRoute,
180+
AuthenticatedSettingsRoute,
181+
AuthenticatedIndexRoute,
182+
AuthenticatedLearnPathIdRoute,
183+
AuthenticatedLearnChatRoute,
184+
AuthenticatedPathsPathIdRoute,
185+
AuthenticatedPathsCreateRoute,
186+
AuthenticatedLearnIndexRoute,
187+
AuthenticatedPathsIndexRoute,
153188
]),
154189
LoginRoute,
155190
RecoverPasswordRoute,
156191
ResetPasswordRoute,
157192
SignupRoute,
158-
PathsPathIdIndexRoute,
159-
PathsCreateIndexRoute,
160193
])
161194

162195
/* prettier-ignore-end */

frontend/src/routes/_layout.tsx renamed to frontend/src/routes/_authenticated.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Sidebar from "../components/Common/Sidebar"
55
import UserMenu from "../components/Common/UserMenu"
66
import useAuth, { isLoggedIn } from "../hooks/useAuth"
77

8-
export const Route = createFileRoute("/_layout")({
8+
export const Route = createFileRoute("/_authenticated")({
99
component: Layout,
1010
beforeLoad: async () => {
1111
if (!isLoggedIn()) {

frontend/src/routes/_authenticated/_layout.tsx

Lines changed: 0 additions & 35 deletions
This file was deleted.

frontend/src/routes/_layout/admin.tsx renamed to frontend/src/routes/_authenticated/admin.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ import { createFileRoute, useNavigate } from "@tanstack/react-router"
1818
import { useEffect } from "react"
1919
import { z } from "zod"
2020

21-
import { type UserPublic, UsersService } from "../../client"
22-
import AddUser from "../../components/Admin/AddUser"
23-
import ActionsMenu from "../../components/Common/ActionsMenu"
24-
import Navbar from "../../components/Common/Navbar"
21+
import { type UserPublic, UsersService } from "../../client/index.ts"
22+
import AddUser from "../../components/Admin/AddUser.tsx"
23+
import ActionsMenu from "../../components/Common/ActionsMenu.tsx"
24+
import Navbar from "../../components/Common/Navbar.tsx"
2525
import { PaginationFooter } from "../../components/Common/PaginationFooter.tsx"
2626

2727
const usersSearchSchema = z.object({
2828
page: z.number().catch(1),
2929
})
3030

31-
export const Route = createFileRoute("/_layout/admin")({
31+
export const Route = createFileRoute("/_authenticated/admin")({
3232
component: Admin,
3333
validateSearch: (search) => usersSearchSchema.parse(search),
3434
})

frontend/src/routes/_layout/index.tsx renamed to frontend/src/routes/_authenticated/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createFileRoute } from "@tanstack/react-router"
33

44
import useAuth from "../../hooks/useAuth"
55

6-
export const Route = createFileRoute("/_layout/")({
6+
export const Route = createFileRoute("/_authenticated/")({
77
component: Dashboard,
88
})
99

frontend/src/routes/_layout/items.tsx renamed to frontend/src/routes/_authenticated/items.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ import { createFileRoute, useNavigate } from "@tanstack/react-router"
1515
import { useEffect } from "react"
1616
import { z } from "zod"
1717

18-
import { ItemsService } from "../../client"
19-
import ActionsMenu from "../../components/Common/ActionsMenu"
20-
import Navbar from "../../components/Common/Navbar"
21-
import AddItem from "../../components/Items/AddItem"
18+
import { ItemsService } from "../../client/index.ts"
19+
import ActionsMenu from "../../components/Common/ActionsMenu.tsx"
20+
import Navbar from "../../components/Common/Navbar.tsx"
21+
import AddItem from "../../components/Items/AddItem.tsx"
2222
import { PaginationFooter } from "../../components/Common/PaginationFooter.tsx"
2323

2424
const itemsSearchSchema = z.object({
2525
page: z.number().catch(1),
2626
})
2727

28-
export const Route = createFileRoute("/_layout/items")({
28+
export const Route = createFileRoute("/_authenticated/items")({
2929
component: Items,
3030
validateSearch: (search) => itemsSearchSchema.parse(search),
3131
})

frontend/src/routes/learn/$pathId/index.tsx renamed to frontend/src/routes/_authenticated/learn/$pathId.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, KeyboardEvent, ChangeEvent } from "react"
1+
import { useState } from "react"
22
import {
33
Box,
44
Container,
@@ -18,10 +18,10 @@ interface Message {
1818
content: string
1919
}
2020

21-
export const Route = createFileRoute("/learn/$pathId")({
21+
export const Route = createFileRoute("/_authenticated/learn/$pathId")({
2222
component: Learn,
23-
validateParams: (params) => ({
24-
pathId: z.string().parse(params.pathId),
23+
parseParams: (rawParams: Record<string, string>) => ({
24+
pathId: z.string().parse(rawParams.pathId),
2525
}),
2626
})
2727

@@ -106,10 +106,10 @@ function Learn() {
106106
<Flex>
107107
<Input
108108
value={input}
109-
onChange={(e: ChangeEvent<HTMLInputElement>) => setInput(e.target.value)}
109+
onChange={(e) => setInput(e.target.value)}
110110
placeholder="Type your message..."
111111
mr={2}
112-
onKeyPress={(e: KeyboardEvent<HTMLInputElement>) => {
112+
onKeyPress={(e) => {
113113
if (e.key === "Enter") {
114114
handleSubmit()
115115
}

frontend/src/routes/learn/chat/index.tsx renamed to frontend/src/routes/_authenticated/learn/chat.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
Box,
3-
Container,
43
Flex,
54
Textarea,
65
Button,
@@ -40,7 +39,7 @@ const ChatMessage = ({ message }: { message: ChatMessage }) => {
4039
)
4140
}
4241

43-
export const Route = createFileRoute('/learn/_layout/chat')({
42+
export const Route = createFileRoute("/_authenticated/learn/chat")({
4443
component: ChatRoute
4544
})
4645

frontend/src/routes/_layout/learn.tsx renamed to frontend/src/routes/_authenticated/learn/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { type ReactNode } from "react"
1212

1313
const learnSearchSchema = z.object({})
1414

15-
export const Route = createFileRoute('/_layout/learn')({
15+
export const Route = createFileRoute("/_authenticated/learn/")({
1616
component: Learn,
1717
validateSearch: (search) => learnSearchSchema.parse(search),
1818
})

frontend/src/routes/paths/$pathId/index.tsx renamed to frontend/src/routes/_authenticated/paths/$pathId.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,11 @@ const transformFormToApi = (formData: FormData): PathCreate => {
8383
}
8484
}
8585

86-
export const Route = createFileRoute("/paths/$pathId/")({
86+
export const Route = createFileRoute("/_authenticated/paths/$pathId")({
8787
component: EditPath,
88+
parseParams: (rawParams: Record<string, string>) => ({
89+
pathId: z.string().parse(rawParams.pathId),
90+
}),
8891
})
8992

9093
function EditPath() {

0 commit comments

Comments
 (0)