|
1 |
| -import { RouterProvider, Route, createBrowserRouter, createRoutesFromElements } from 'react-router-dom' |
2 | 1 | import * as Sentry from '@sentry/react'
|
| 2 | +import { createBrowserRouter, createRoutesFromElements, Navigate, Route, RouterProvider, useParams } from 'react-router-dom' |
3 | 3 |
|
4 | 4 | import { PUBLIC_URL } from '../config'
|
5 | 5 | import App from './App'
|
6 | 6 | import Admin from './components/Admin'
|
7 | 7 | import Chat from './components/Chat'
|
| 8 | +import Chats from './components/Chats' |
| 9 | +import { ChatV2 } from './components/ChatV2/ChatV2' |
8 | 10 | import Courses from './components/Courses'
|
9 | 11 | import Course from './components/Courses/Course'
|
| 12 | +import { NotFound } from './components/common/NotFound' |
| 13 | +import { ErrorPage } from './components/ErrorPage' |
10 | 14 | import NoAccess from './components/NoAccess'
|
11 |
| -import Chats from './components/Chats' |
12 |
| -import Statistics from './components/Statistics' |
13 | 15 | import Rag from './components/Rag/Rag'
|
14 |
| -import { ChatV2 } from './components/ChatV2/ChatV2' |
15 |
| -import { RagIndex } from './components/Rag/RagIndex' |
16 | 16 | import { RagFile } from './components/Rag/RagFile'
|
17 |
| -import { NotFound } from './components/common/NotFound' |
18 |
| -import { ErrorPage } from './components/ErrorPage' |
| 17 | +import { RagIndex } from './components/Rag/RagIndex' |
| 18 | +import Statistics from './components/Statistics' |
| 19 | +import useCurrentUser from './hooks/useCurrentUser' |
19 | 20 |
|
20 | 21 | const sentryCreateBrowserRouter = Sentry.wrapCreateBrowserRouterV6(createBrowserRouter)
|
21 | 22 |
|
| 23 | +const PreferenceRedirect = () => { |
| 24 | + const { user } = useCurrentUser() |
| 25 | + const { courseId } = useParams() |
| 26 | + const chatVersion = user?.preferences?.chatVersion ?? 1 |
| 27 | + return <Navigate to={chatVersion === 1 ? '/v1' : '/v2' + (courseId ? `/${courseId}` : '')} replace /> |
| 28 | +} |
| 29 | + |
22 | 30 | const router = sentryCreateBrowserRouter(
|
23 | 31 | createRoutesFromElements(
|
24 | 32 | <Route path="/" element={<App />} ErrorBoundary={ErrorPage}>
|
25 |
| - <Route index element={<Chat />} /> |
| 33 | + <Route index element={<PreferenceRedirect />} /> |
| 34 | + <Route path="/v1" element={<Chat />} /> |
26 | 35 | <Route path="/v2" element={<ChatV2 />} />
|
| 36 | + |
| 37 | + <Route path="/:courseId" element={<PreferenceRedirect />} /> |
27 | 38 | <Route path="/v2/:courseId" element={<ChatV2 />} />
|
28 |
| - <Route path="/:courseId" element={<Chat />} /> |
| 39 | + <Route path="/v1/:courseId" element={<Chat />} /> |
| 40 | + |
29 | 41 | <Route path="/courses" element={<Courses />} />
|
30 | 42 | <Route path="/courses/:id/*" element={<Course />} />
|
31 | 43 | <Route path="/admin/*" element={<Admin />} />
|
|
0 commit comments