2021-05-11 16:27:12 -08:00
|
|
|
import React, { useEffect } from 'react'
|
2020-07-03 08:53:35 -08:00
|
|
|
import ReactGA from 'react-ga'
|
2020-11-08 09:15:46 -09:00
|
|
|
import 'react-jinke-music-player/assets/index.css'
|
2020-11-07 20:06:48 -09:00
|
|
|
import { Provider, useDispatch } from 'react-redux'
|
2020-03-31 10:04:10 -08:00
|
|
|
import { createHashHistory } from 'history'
|
2020-11-07 20:06:48 -09:00
|
|
|
import { Admin as RAAdmin, Resource } from 'react-admin'
|
2021-05-11 16:11:54 -08:00
|
|
|
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'
|
2020-02-29 16:01:09 -09:00
|
|
|
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'
|
2020-01-22 06:19:13 -09:00
|
|
|
import song from './song'
|
2020-01-22 08:32:31 -09:00
|
|
|
import album from './album'
|
2020-01-22 09:02:19 -09:00
|
|
|
import artist from './artist'
|
2020-05-05 14:28:55 -08:00
|
|
|
import playlist from './playlist'
|
2020-11-08 09:15:46 -09:00
|
|
|
import { Player } from './audioplayer'
|
2020-03-31 05:35:44 -08:00
|
|
|
import customRoutes from './routes'
|
2020-11-08 09:15:46 -09:00
|
|
|
import {
|
|
|
|
|
themeReducer,
|
|
|
|
|
addToPlaylistDialogReducer,
|
|
|
|
|
playQueueReducer,
|
|
|
|
|
albumViewReducer,
|
2020-11-07 20:06:48 -09:00
|
|
|
activityReducer,
|
2020-11-19 19:06:09 -09:00
|
|
|
settingsReducer,
|
2020-11-08 09:15:46 -09:00
|
|
|
} 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'
|
2020-07-03 08:53:35 -08:00
|
|
|
import config from './config'
|
2020-11-20 16:22:22 -09:00
|
|
|
import { setDispatch, startEventStream } from './eventStream'
|
2021-02-03 14:29:33 -09:00
|
|
|
import { keyMap } from './hotkeys'
|
2021-05-11 16:11:54 -08:00
|
|
|
import useChangeThemeColor from './useChangeThemeColor'
|
2020-11-13 14:40:33 -09:00
|
|
|
|
2020-03-31 10:04:10 -08:00
|
|
|
const history = createHashHistory()
|
|
|
|
|
|
2020-07-03 08:53:35 -08:00
|
|
|
if (config.gaTrackingId) {
|
|
|
|
|
ReactGA.initialize(config.gaTrackingId)
|
|
|
|
|
history.listen((location) => {
|
|
|
|
|
ReactGA.pageview(location.pathname)
|
|
|
|
|
})
|
|
|
|
|
ReactGA.pageview(window.location.pathname)
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-08 09:20:02 -08:00
|
|
|
const App = () => (
|
|
|
|
|
<Provider
|
|
|
|
|
store={createAdminStore({
|
|
|
|
|
authProvider,
|
|
|
|
|
dataProvider,
|
|
|
|
|
history,
|
|
|
|
|
customReducers: {
|
|
|
|
|
queue: playQueueReducer,
|
|
|
|
|
albumView: albumViewReducer,
|
2020-04-26 10:50:44 -08:00
|
|
|
theme: themeReducer,
|
2020-05-25 10:50:46 -08:00
|
|
|
addToPlaylistDialog: addToPlaylistDialogReducer,
|
2020-11-07 20:06:48 -09:00
|
|
|
activity: activityReducer,
|
2020-11-19 19:06:09 -09:00
|
|
|
settings: settingsReducer,
|
2020-04-26 10:50:44 -08:00
|
|
|
},
|
2020-04-08 09:20:02 -08:00
|
|
|
})}
|
|
|
|
|
>
|
2020-11-07 20:06:48 -09:00
|
|
|
<Admin />
|
|
|
|
|
</Provider>
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const Admin = (props) => {
|
2021-05-11 16:11:54 -08:00
|
|
|
useChangeThemeColor()
|
2020-11-07 20:06:48 -09:00
|
|
|
const dispatch = useDispatch()
|
2021-05-11 16:27:12 -08:00
|
|
|
useEffect(() => {
|
|
|
|
|
if (config.devActivityPanel) {
|
|
|
|
|
setDispatch(dispatch)
|
|
|
|
|
authProvider
|
|
|
|
|
.checkAuth()
|
|
|
|
|
.then(() => startEventStream())
|
|
|
|
|
.catch(() => {}) // ignore if not logged in
|
|
|
|
|
}
|
|
|
|
|
}, [dispatch])
|
2020-11-07 20:06:48 -09:00
|
|
|
|
|
|
|
|
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}
|
2020-11-07 20:06:48 -09:00
|
|
|
{...props}
|
2020-02-08 09:43:14 -09:00
|
|
|
>
|
2020-04-08 09:20:02 -08:00
|
|
|
{(permissions) => [
|
2020-07-28 04:49:28 -08:00
|
|
|
<Resource name="album" {...album} options={{ subMenu: 'albumList' }} />,
|
2020-05-05 11:44:05 -08:00
|
|
|
<Resource name="artist" {...artist} options={{ subMenu: 'library' }} />,
|
2020-04-08 09:20:02 -08:00
|
|
|
<Resource name="song" {...song} options={{ subMenu: 'library' }} />,
|
2020-06-11 18:11:59 -08:00
|
|
|
<Resource
|
|
|
|
|
name="playlist"
|
|
|
|
|
{...playlist}
|
|
|
|
|
options={{ subMenu: 'library' }}
|
|
|
|
|
/>,
|
2021-04-28 18:35:25 -08:00
|
|
|
<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}
|
2020-02-29 16:01:09 -09:00
|
|
|
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" />,
|
2020-05-11 17:27:00 -08:00
|
|
|
<Resource name="playlistTrack" />,
|
2020-11-23 17:28:09 -09:00
|
|
|
<Resource name="keepalive" />,
|
2020-04-26 10:50:44 -08:00
|
|
|
<Player />,
|
2020-04-08 09:20:02 -08:00
|
|
|
]}
|
2020-11-07 20:06:48 -09:00
|
|
|
</RAAdmin>
|
|
|
|
|
)
|
|
|
|
|
}
|
2020-02-07 20:11:15 -09:00
|
|
|
|
2021-02-03 14:29:33 -09:00
|
|
|
const AppWithHotkeys = () => (
|
|
|
|
|
<HotKeys keyMap={keyMap}>
|
|
|
|
|
<App />
|
|
|
|
|
</HotKeys>
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
export default AppWithHotkeys
|