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