navidrome/ui/src/App.js

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

123 lines
3.3 KiB
JavaScript
Raw Normal View History

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