navidrome/ui/src/App.js

96 lines
2.8 KiB
JavaScript
Raw Normal View History

import React from 'react'
2020-03-31 20:04:10 +02:00
import { Provider } from 'react-redux'
import { createHashHistory } from 'history'
import { Admin, resolveBrowserLocale, Resource } from 'react-admin'
2020-01-20 15:54:29 +01:00
import dataProvider from './dataProvider'
import authProvider from './authProvider'
2020-02-07 15:40:52 +01:00
import polyglotI18nProvider from 'ra-i18n-polyglot'
import messages from './i18n'
import { Layout, Login } 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-03-12 00:46:46 +01:00
import { Player, playQueueReducer } from './audioplayer'
import { albumViewReducer } from './album/albumState'
import customRoutes from './routes'
import themeReducer from './personal/themeReducer'
2020-03-31 20:04:10 +02:00
import createAdminStore from './store/createAdminStore'
2020-02-07 15:40:52 +01:00
const i18nProvider = polyglotI18nProvider(
(locale) => (messages[locale] ? messages[locale] : messages.en),
resolveBrowserLocale()
)
2020-03-31 20:04:10 +02:00
const history = createHashHistory()
const App = () => {
try {
const appConfig = JSON.parse(window.__APP_CONFIG__)
// This flags to the login process that it should create the first account instead
if (appConfig.firstTime) {
localStorage.setItem('initialAccountCreation', 'true')
}
2020-04-03 23:50:42 +02:00
localStorage.setItem('baseURL', appConfig.baseURL)
} catch (e) {}
return (
2020-03-31 20:04:10 +02:00
<Provider
store={createAdminStore({
authProvider,
dataProvider,
history,
customReducers: {
queue: playQueueReducer,
albumView: albumViewReducer,
theme: themeReducer
}
})}
>
2020-03-31 20:04:10 +02:00
<Admin
dataProvider={dataProvider}
authProvider={authProvider}
i18nProvider={i18nProvider}
customRoutes={customRoutes}
history={history}
layout={Layout}
loginPage={Login}
>
{(permissions) => [
<Resource
name="artist"
{...artist}
options={{ subMenu: 'library' }}
/>,
<Resource name="album" {...album} options={{ subMenu: 'library' }} />,
<Resource name="song" {...song} options={{ subMenu: 'library' }} />,
<Resource name="albumSong" />,
permissions === 'admin' ? (
<Resource name="user" {...user} options={{ subMenu: 'settings' }} />
) : null,
<Resource
2020-03-31 20:04:10 +02:00
name="player"
{...player}
options={{ subMenu: 'settings' }}
2020-03-31 20:04:10 +02:00
/>,
permissions === 'admin' ? (
<Resource
name="transcoding"
{...transcoding}
options={{ subMenu: 'settings' }}
/>
) : (
<Resource name="transcoding" />
),
<Player />
]}
</Admin>
</Provider>
)
}
export default App