simon | 3f5f3e7 | 2022-11-08 21:01:57 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 Savoir-faire Linux Inc. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU Affero General Public License as |
| 6 | * published by the Free Software Foundation; either version 3 of the |
| 7 | * License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU Affero General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Affero General Public |
| 15 | * License along with this program. If not, see |
| 16 | * <https://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | import { createBrowserRouter, createRoutesFromElements, Outlet, Route } from 'react-router-dom'; |
| 19 | |
| 20 | import App from './App'; |
| 21 | import ContactList from './components/ContactList'; |
| 22 | import AuthProvider from './contexts/AuthProvider'; |
| 23 | import WebSocketProvider from './contexts/WebSocketProvider'; |
| 24 | import AccountSettings from './pages/AccountSettings'; |
| 25 | import CallInterface from './pages/CallInterface'; |
| 26 | import Messenger from './pages/Messenger'; |
| 27 | import ServerSetup from './pages/ServerSetup'; |
| 28 | import Welcome from './pages/Welcome'; |
| 29 | import { ThemeDemonstrator } from './themes/ThemeDemonstrator'; |
| 30 | import { RouteParams } from './utils/hooks'; |
| 31 | |
| 32 | export type MessengerRouteParams = RouteParams<{ conversationId?: string; contactId?: string }, Record<string, never>>; |
| 33 | export type CallRouteParams = RouteParams<{ conversationId: string }, { video?: 'true' }>; |
| 34 | |
| 35 | export const router = createBrowserRouter( |
| 36 | createRoutesFromElements( |
| 37 | <Route path="/" element={<App />}> |
| 38 | <Route path="login" element={<Welcome />} /> |
| 39 | <Route path="theme" element={<ThemeDemonstrator />} /> |
| 40 | <Route |
| 41 | element={ |
| 42 | <AuthProvider> |
| 43 | <WebSocketProvider> |
| 44 | <Outlet /> |
| 45 | </WebSocketProvider> |
| 46 | </AuthProvider> |
| 47 | } |
| 48 | > |
| 49 | <Route path="addContact/:contactId" element={<Messenger />} /> |
| 50 | <Route path="conversation/:conversationId" element={<Messenger />} /> |
| 51 | <Route path="call/:conversationId" element={<CallInterface />} /> |
| 52 | <Route path="settings" element={<AccountSettings />} /> |
| 53 | <Route path="contacts" element={<ContactList />} /> |
| 54 | <Route index element={<Messenger />} /> |
| 55 | </Route> |
| 56 | <Route path="setup" element={<ServerSetup />} /> |
| 57 | </Route> |
| 58 | ) |
| 59 | ); |