2019-07-26 14:18:32 +01:00
|
|
|
import React, { Component } from "react";
|
2019-07-30 16:25:01 +01:00
|
|
|
import { BrowserRouter as Router, Route, Link, Switch, Redirect} from "react-router-dom";
|
2019-07-26 14:18:32 +01:00
|
|
|
|
2019-07-30 16:25:01 +01:00
|
|
|
import NotFound from "./Error/NotFound.js";
|
|
|
|
|
2019-08-05 22:55:07 +01:00
|
|
|
import showMessage from "./Toast.js"
|
|
|
|
|
2020-01-26 17:37:40 +00:00
|
|
|
import GlobalTheme from './Theme.js';
|
|
|
|
|
|
|
|
import { Typography } from '@material-ui/core';
|
|
|
|
import { ThemeProvider } from '@material-ui/core/styles';
|
|
|
|
import AppBar from '@material-ui/core/AppBar';
|
|
|
|
import Toolbar from '@material-ui/core/Toolbar';
|
|
|
|
import IconButton from '@material-ui/core/IconButton';
|
|
|
|
import MenuIcon from '@material-ui/icons/Menu';
|
|
|
|
|
|
|
|
import Drawer from '@material-ui/core/Drawer';
|
|
|
|
import List from '@material-ui/core/List';
|
|
|
|
import Divider from '@material-ui/core/Divider';
|
|
|
|
import ChevronLeftIcon from '@material-ui/icons/ChevronLeft';
|
|
|
|
import ListItem from '@material-ui/core/ListItem';
|
|
|
|
import ListItemIcon from '@material-ui/core/ListItemIcon';
|
|
|
|
import ListItemText from '@material-ui/core/ListItemText';
|
|
|
|
import HomeIcon from '@material-ui/icons/Home';
|
|
|
|
import { Build, PieChart, QueueMusic, ExitToApp, AccountCircle, KeyboardBackspace } from '@material-ui/icons'
|
|
|
|
|
2019-07-30 16:25:01 +01:00
|
|
|
const axios = require('axios');
|
2019-07-26 14:18:32 +01:00
|
|
|
|
2020-01-26 20:33:09 +00:00
|
|
|
const LazyIndex = React.lazy(() => import("./Index/Index"))
|
|
|
|
const LazyMaths = React.lazy(() => import("./Maths/Maths"))
|
|
|
|
const LazyPlaylists = React.lazy(() => import("./Playlist/Playlists"))
|
|
|
|
const LazyPlaylistView = React.lazy(() => import("./Playlist/View/View"))
|
|
|
|
const LazySettings = React.lazy(() => import("./Settings/Settings"))
|
|
|
|
const LazyAdmin = React.lazy(() => import("./Admin/Admin"))
|
|
|
|
|
2020-01-24 15:59:52 +00:00
|
|
|
class MusicTools extends Component {
|
2019-07-26 14:18:32 +01:00
|
|
|
|
2019-07-30 16:25:01 +01:00
|
|
|
constructor(props){
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2019-07-31 12:24:10 +01:00
|
|
|
type: null,
|
2020-01-26 17:37:40 +00:00
|
|
|
spotify_linked: null,
|
|
|
|
drawerOpen: false
|
2019-07-30 16:25:01 +01:00
|
|
|
}
|
2020-01-26 17:37:40 +00:00
|
|
|
this.setOpen = this.setOpen.bind(this);
|
2019-07-30 16:25:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.getUserInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
this.userInfoCancelToken.cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
getUserInfo(){
|
|
|
|
this.userInfoCancelToken = axios.CancelToken.source();
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
axios.get('/api/user', {
|
|
|
|
cancelToken: this.userInfoCancelToken.token
|
|
|
|
})
|
|
|
|
.then((response) => {
|
|
|
|
self.setState({
|
2019-07-31 12:24:10 +01:00
|
|
|
type: response.data.type,
|
|
|
|
spotify_linked: response.data.spotify_linked
|
2019-07-30 16:25:01 +01:00
|
|
|
})
|
2019-08-05 22:55:07 +01:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
showMessage(`error getting user info (${error.response.status})`);
|
2019-07-30 16:25:01 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-01-26 17:37:40 +00:00
|
|
|
setOpen(bool){
|
|
|
|
this.setState({
|
|
|
|
drawerOpen: bool
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-07-26 14:18:32 +01:00
|
|
|
render(){
|
|
|
|
return (
|
|
|
|
<Router>
|
2019-07-29 11:44:10 +01:00
|
|
|
<div className="card pad-12">
|
2020-01-26 17:37:40 +00:00
|
|
|
<ThemeProvider theme={GlobalTheme}>
|
|
|
|
<AppBar position="static">
|
|
|
|
<Toolbar>
|
|
|
|
<IconButton edge="start" color="inherit" aria-label="menu" onClick={(e) => this.setOpen(true)}>
|
|
|
|
<MenuIcon />
|
|
|
|
</IconButton>
|
|
|
|
<Typography variant="h6">
|
2020-01-26 20:33:09 +00:00
|
|
|
<Link to='/app/playlists' style={{textDecoration: 'none'}}>Music Tools</Link>
|
2020-01-26 17:37:40 +00:00
|
|
|
</Typography>
|
|
|
|
</Toolbar>
|
|
|
|
</AppBar>
|
|
|
|
<Drawer
|
|
|
|
variant="persistent"
|
|
|
|
anchor="left"
|
|
|
|
open={this.state.drawerOpen}
|
|
|
|
>
|
|
|
|
<div>
|
|
|
|
<IconButton onClick={(e) => this.setOpen(false)}>
|
|
|
|
<ChevronLeftIcon />
|
|
|
|
</IconButton>
|
|
|
|
</div>
|
|
|
|
<Divider />
|
|
|
|
<List>
|
|
|
|
<ListItem button key="home" component={Link} to='/app'>
|
|
|
|
<ListItemIcon><HomeIcon /></ListItemIcon>
|
|
|
|
<ListItemText primary="Home" />
|
|
|
|
</ListItem>
|
|
|
|
<ListItem button key="playlists" component={Link} to='/app/playlists'>
|
|
|
|
<ListItemIcon><QueueMusic /></ListItemIcon>
|
|
|
|
<ListItemText primary="Playlists" />
|
|
|
|
</ListItem>
|
|
|
|
<ListItem button key="maths" component={Link} to='/app/maths/count'>
|
|
|
|
<ListItemIcon><PieChart /></ListItemIcon>
|
|
|
|
<ListItemText primary="Maths" />
|
|
|
|
</ListItem>
|
|
|
|
<ListItem button key="settings" component={Link} to='/app/settings/password'>
|
|
|
|
<ListItemIcon><Build /></ListItemIcon>
|
|
|
|
<ListItemText primary="Settings" />
|
|
|
|
</ListItem>
|
|
|
|
{ this.state.type == 'admin' &&
|
|
|
|
<ListItem button key="admin" component={Link} to='/app/admin/lock'>
|
|
|
|
<ListItemIcon><AccountCircle /></ListItemIcon>
|
|
|
|
<ListItemText primary="Admin" />
|
|
|
|
</ListItem>
|
|
|
|
}
|
|
|
|
<ListItem button key="logout" component={Link} to='/auth/logout'>
|
|
|
|
<ListItemIcon><KeyboardBackspace /></ListItemIcon>
|
|
|
|
<ListItemText primary="Logout" />
|
|
|
|
</ListItem>
|
|
|
|
<ListItem button key="sarsoo.xyz" component={Link} to='https://sarsoo.xyz'>
|
|
|
|
<ListItemIcon><ExitToApp /></ListItemIcon>
|
|
|
|
<ListItemText primary="sarsoo.xyz" />
|
|
|
|
</ListItem>
|
|
|
|
</List>
|
|
|
|
</Drawer>
|
|
|
|
</ThemeProvider>
|
2020-01-26 20:33:09 +00:00
|
|
|
<div className="full-width">
|
2019-07-30 16:25:01 +01:00
|
|
|
<Switch>
|
2020-01-26 20:33:09 +00:00
|
|
|
<React.Suspense fallback={<LoadingMessage/>}>
|
|
|
|
<Route path="/app" exact component={LazyIndex} />
|
|
|
|
<Route path="/app/playlists" component={LazyPlaylists} />
|
|
|
|
<Route path="/app/maths" component={LazyMaths} />
|
|
|
|
<Route path="/app/settings" component={LazySettings} />
|
|
|
|
{ this.state.type == 'admin' && <Route path="/app/admin" component={LazyAdmin} /> }
|
|
|
|
<Route path='/app/playlist/:name' component={LazyPlaylistView} />
|
|
|
|
</React.Suspense>
|
2019-07-30 16:25:01 +01:00
|
|
|
<Route component={NotFound} />
|
|
|
|
</Switch>
|
2019-07-29 11:44:10 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-07-26 14:18:32 +01:00
|
|
|
</Router>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-01-26 20:33:09 +00:00
|
|
|
function LoadingMessage(props) {
|
|
|
|
return <ThemeProvider theme={GlobalTheme}><Typography variant="h5" component="h2" className="ui-text center-text">Loading...</Typography></ThemeProvider>;
|
|
|
|
}
|
|
|
|
|
2020-01-24 15:59:52 +00:00
|
|
|
export default MusicTools;
|