blob: e95a74d28a7fca1aea7fd4a5dd64072caef468a6 [file] [log] [blame]
simon26e79f72022-10-05 22:16:08 -04001/*
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 */
simond47ef9e2022-09-28 22:24:28 -040018'use strict';
19import './index.scss';
idillon5815c732022-09-16 13:54:45 -040020import './i18n';
Larbi Gharibe9af9732021-03-31 15:08:01 +010021
Michelle Sepkap Sime51c00452022-10-31 21:26:38 -040022import { ThemeProvider } from '@mui/material/styles';
idillon08f77172022-09-13 19:14:17 -040023import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
simon07b4eb02022-09-29 17:50:26 -040024import { StrictMode } from 'react';
25import { createRoot } from 'react-dom/client';
26import { Provider } from 'react-redux';
Michelle Sepkap Sime51c00452022-10-31 21:26:38 -040027import { createBrowserRouter, createRoutesFromElements, Route, RouterProvider } from 'react-router-dom';
idillon322e4ac2022-09-14 12:48:43 -040028import socketio from 'socket.io-client';
simon07b4eb02022-09-29 17:50:26 -040029
simon218d3d12022-10-01 17:27:01 -040030import App from './App';
Michelle Sepkap Sime51c00452022-10-31 21:26:38 -040031import ContactList from './components/ContactList';
simon35378692022-10-02 23:25:57 -040032import { SocketProvider } from './contexts/Socket';
Michelle Sepkap Simeb3dd3122022-11-03 02:12:39 -040033import AccountSelection from './pages/AccountSelection';
Michelle Sepkap Sime51c00452022-10-31 21:26:38 -040034import AccountSettings from './pages/AccountSettings';
Michelle Sepkap Simeb3dd3122022-11-03 02:12:39 -040035import CallInterface from './pages/CallInterface';
36import DeprecatedAccountSettings from './pages/DeprecatedAccountSettings';
Michelle Sepkap Sime51c00452022-10-31 21:26:38 -040037import Home from './pages/Home';
38import JamiMessenger from './pages/JamiMessenger';
Michelle Sepkap Simeb3dd3122022-11-03 02:12:39 -040039import Messenger from './pages/Messenger';
Michelle Sepkap Sime51c00452022-10-31 21:26:38 -040040import ServerSetup from './pages/ServerSetup';
simond8ca2f22022-10-11 23:30:55 -040041import { store } from './redux/store';
Michelle Sepkap Sime51c00452022-10-31 21:26:38 -040042import defaultTheme from './themes/Default';
43import { ThemeDemonstrator } from './themes/ThemeDemonstrator';
idillon08f77172022-09-13 19:14:17 -040044
45const queryClient = new QueryClient({
46 defaultOptions: {
47 queries: {
48 cacheTime: Infinity, // websocket is responsible to tell when data needs to be updated
49 },
50 },
simond47ef9e2022-09-28 22:24:28 -040051});
idillon5e897432022-09-16 13:28:09 -040052
simond47ef9e2022-09-28 22:24:28 -040053const socket = socketio();
idillon322e4ac2022-09-14 12:48:43 -040054
Michelle Sepkap Sime51c00452022-10-31 21:26:38 -040055const router = createBrowserRouter(
56 createRoutesFromElements(
57 <Route path="/" element={<App />}>
58 <Route index element={<Home />} />
59 <Route path="theme" element={<ThemeDemonstrator />} />
60 <Route path="account" element={<JamiMessenger />} />
61 <Route path="settings" element={<AccountSettings />} />
62 <Route path="contacts" element={<ContactList />} />
63 <Route path="setup" element={<ServerSetup />} />
Michelle Sepkap Simeb3dd3122022-11-03 02:12:39 -040064 {/* TODO: Remove this block after migration to new server*/}
65 <Route path="deprecated-account" element={<AccountSelection />} />
66 <Route path="deprecated-account/:accountId" element={<Messenger />}>
67 <Route path="addContact/:contactId" element={<Messenger />} />
68 <Route path="conversation/:conversationId" element={<Messenger />} />
69 <Route path="call/:conversationId" element={<CallInterface />} />
70 </Route>
71 <Route path="deprecated-account/:accountId/settings" element={<DeprecatedAccountSettings />} />
Michelle Sepkap Sime51c00452022-10-31 21:26:38 -040072 </Route>
73 )
74);
75
simond47ef9e2022-09-28 22:24:28 -040076const container = document.getElementById('root');
simon218d3d12022-10-01 17:27:01 -040077if (!container) {
78 throw new Error('Failed to get the root element');
79}
idillon169f64f2022-09-16 14:01:22 -040080const root = createRoot(container);
81root.render(
82 <Provider store={store}>
Adrien Béraud023f7cf2022-09-18 14:57:53 -040083 <StrictMode>
idillon08f77172022-09-13 19:14:17 -040084 <QueryClientProvider client={queryClient}>
idillon322e4ac2022-09-14 12:48:43 -040085 <SocketProvider socket={socket}>
Michelle Sepkap Sime51c00452022-10-31 21:26:38 -040086 <ThemeProvider theme={defaultTheme}>
87 <RouterProvider router={router} />
88 </ThemeProvider>
idillon322e4ac2022-09-14 12:48:43 -040089 </SocketProvider>
idillon08f77172022-09-13 19:14:17 -040090 </QueryClientProvider>
Adrien Béraud023f7cf2022-09-18 14:57:53 -040091 </StrictMode>
idillon169f64f2022-09-16 14:01:22 -040092 </Provider>
93);