quintodrome/ui/src/App.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

131 lines
3.4 KiB
JavaScript
Raw Normal View History

import React, { useEffect } from 'react'
import ReactGA from 'react-ga'
import { Provider } from 'react-redux'
2020-03-31 10:04:10 -08:00
import { createHashHistory } from 'history'
import { Admin as RAAdmin, Resource } from 'react-admin'
import { HotKeys } from 'react-hotkeys'
2020-01-20 05:54:29 -09:00
import dataProvider from './dataProvider'
import authProvider from './authProvider'
2020-06-19 06:51:39 -08:00
import { Layout, Login, Logout } from './layout'
import transcoding from './transcoding'
2020-03-12 05:38:07 -08:00
import player from './player'
2020-01-19 16:40:18 -09:00
import user from './user'
import song from './song'
import album from './album'
import artist from './artist'
2020-05-05 14:28:55 -08:00
import playlist from './playlist'
import { Player } from './audioplayer'
import customRoutes from './routes'
import {
themeReducer,
addToPlaylistDialogReducer,
expandInfoDialogReducer,
listenBrainzTokenDialogReducer,
playerReducer,
albumViewReducer,
activityReducer,
2020-11-19 19:06:09 -09:00
settingsReducer,
} from './reducers'
2020-03-31 10:04:10 -08:00
import createAdminStore from './store/createAdminStore'
2020-05-02 13:44:24 -08:00
import { i18nProvider } from './i18n'
import config from './config'
2021-11-29 14:49:29 -09:00
import { setDispatch, startEventStream } from './eventStream'
2021-02-03 14:29:33 -09:00
import { keyMap } from './hotkeys'
import useChangeThemeColor from './useChangeThemeColor'
2020-11-13 14:40:33 -09:00
2020-03-31 10:04:10 -08:00
const history = createHashHistory()
if (config.gaTrackingId) {
ReactGA.initialize(config.gaTrackingId)
history.listen((location) => {
ReactGA.pageview(location.pathname)
})
ReactGA.pageview(window.location.pathname)
}
const adminStore = createAdminStore({
authProvider,
dataProvider,
history,
customReducers: {
player: playerReducer,
albumView: albumViewReducer,
theme: themeReducer,
addToPlaylistDialog: addToPlaylistDialogReducer,
expandInfoDialog: expandInfoDialogReducer,
listenBrainzTokenDialog: listenBrainzTokenDialogReducer,
activity: activityReducer,
settings: settingsReducer,
},
})
2020-04-08 09:20:02 -08:00
const App = () => (
<Provider store={adminStore}>
<Admin />
</Provider>
)
const Admin = (props) => {
useChangeThemeColor()
useEffect(() => {
if (config.devActivityPanel) {
2021-11-29 14:49:29 -09:00
setDispatch(adminStore.dispatch)
authProvider.checkAuth().then(() => startEventStream(adminStore.dispatch))
}
}, [])
return (
<RAAdmin
2021-01-31 14:50:27 -09:00
disableTelemetry
2020-04-08 09:20:02 -08:00
dataProvider={dataProvider}
authProvider={authProvider}
i18nProvider={i18nProvider}
customRoutes={customRoutes}
history={history}
layout={Layout}
loginPage={Login}
2020-06-19 06:51:39 -08:00
logoutButton={Logout}
{...props}
>
2020-04-08 09:20:02 -08:00
{(permissions) => [
2020-07-28 04:49:28 -08:00
<Resource name="album" {...album} options={{ subMenu: 'albumList' }} />,
<Resource name="artist" {...artist} />,
<Resource name="song" {...song} />,
<Resource
name="playlist"
{...playlist}
options={{ subMenu: 'playlist' }}
/>,
<Resource name="user" {...user} options={{ subMenu: 'settings' }} />,
2020-04-08 09:20:02 -08:00
<Resource
name="player"
{...player}
options={{ subMenu: 'settings' }}
/>,
permissions === 'admin' ? (
2020-03-31 10:04:10 -08:00
<Resource
2020-04-08 09:20:02 -08:00
name="transcoding"
{...transcoding}
options={{ subMenu: 'settings' }}
2020-04-08 09:20:02 -08:00
/>
) : (
<Resource name="transcoding" />
),
2020-05-01 14:29:50 -08:00
<Resource name="translation" />,
2021-07-16 15:41:49 -08:00
<Resource name="genre" />,
2020-05-11 17:27:00 -08:00
<Resource name="playlistTrack" />,
<Resource name="keepalive" />,
2020-04-26 10:50:44 -08:00
<Player />,
2020-04-08 09:20:02 -08:00
]}
</RAAdmin>
)
}
2021-02-03 14:29:33 -09:00
const AppWithHotkeys = () => (
<HotKeys keyMap={keyMap}>
<App />
</HotKeys>
)
export default AppWithHotkeys