-
-
Notifications
You must be signed in to change notification settings - Fork 649
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite all components to functional component using hooks Upgrade react-router to 7.1.0 Use reduxjs/toolkit and react-redux for state management Upgrade material to 6.3.0 Updated most dependencies to current versions
- Loading branch information
Showing
62 changed files
with
6,158 additions
and
4,412 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import React, {useEffect} from 'react'; | ||
import {createBrowserRouter, RouterProvider} from 'react-router-dom'; | ||
import Applications from './application/Applications.tsx'; | ||
import Clients from './client/Clients.tsx'; | ||
import {checkAuthLoader} from './common/Auth.ts'; | ||
import Messages from './message/Messages.tsx'; | ||
import {WebSocketStore} from './message/WebSocketStore.ts'; | ||
import RootLayout from './pages/root'; | ||
import Plugins from './plugin/Plugins.tsx'; | ||
import * as Notifications from './snack/browserNotification.ts'; | ||
import {useAppDispatch, useAppSelector} from './store'; | ||
import {messageActions} from './store/message-slice.ts'; | ||
import Login from './user/Login.tsx'; | ||
import Users from './user/Users.tsx'; | ||
|
||
const router = createBrowserRouter([ | ||
{ | ||
path: '/', | ||
element: <RootLayout />, | ||
children: [ | ||
{ | ||
index: true, | ||
element: <Messages />, | ||
loader: checkAuthLoader, | ||
}, | ||
{ | ||
path: 'messages', | ||
element: <Messages />, | ||
loader: checkAuthLoader, | ||
children: [ | ||
{ | ||
path: ':id', | ||
element: <Messages />, | ||
} | ||
] | ||
}, | ||
{ | ||
path: 'login', | ||
element: <Login />, | ||
}, | ||
{ | ||
path: 'applications', | ||
element: <Applications />, | ||
loader: checkAuthLoader, | ||
}, | ||
{ | ||
path: 'users', | ||
element: <Users />, | ||
loader: checkAuthLoader, | ||
}, | ||
{ | ||
path: 'clients', | ||
element: <Clients />, | ||
loader: checkAuthLoader, | ||
}, | ||
{ | ||
path: 'plugins', | ||
element: <Plugins />, | ||
loader: checkAuthLoader, | ||
children: [ | ||
{ | ||
path: ':id', | ||
// TODO: fix problem in PluginDetailView | ||
//element: <PluginDetailView />, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
]); | ||
|
||
const App = () => { | ||
const dispatch = useAppDispatch(); | ||
const loggedIn = useAppSelector((state) => state.auth.loggedIn); | ||
const ws = new WebSocketStore(); | ||
|
||
useEffect(() => { | ||
if (loggedIn) { | ||
ws.listen((message) => { | ||
dispatch(messageActions.add(message)); | ||
Notifications.notifyNewMessage(message); | ||
if (message.priority >= 4) { | ||
const src = 'static/notification.ogg'; | ||
const audio = new Audio(src); | ||
audio.play(); | ||
} | ||
}); | ||
window.onbeforeunload = () => { | ||
ws.close(); | ||
}; | ||
} else { | ||
ws.close(); | ||
} | ||
}, [dispatch, loggedIn]); | ||
|
||
|
||
return ( | ||
<RouterProvider router={router} /> | ||
); | ||
}; | ||
|
||
export default App; | ||
|
||
/* | ||
<Routes> | ||
{authenticating ? (<Route path="/" element={<LoadingSpinner />} />) : null} | ||
<Route path="/" element={<Messages />} /> | ||
<Route path="messages/:id" element={<Messages />} /> | ||
</Routes> | ||
*/ |
Oops, something went wrong.