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 Index from "./Index/Index.js";
|
2019-10-19 17:57:56 +01:00
|
|
|
import Maths from "./Maths/Maths.js";
|
2019-07-29 11:44:10 +01:00
|
|
|
import Playlists from "./Playlist/Playlists.js";
|
2019-10-19 20:35:37 +01:00
|
|
|
import PlaylistView from "./Playlist/View/View.js";
|
2019-07-30 16:25:01 +01:00
|
|
|
import Settings from "./Settings/Settings.js";
|
|
|
|
import Admin from "./Admin/Admin.js";
|
|
|
|
|
|
|
|
import NotFound from "./Error/NotFound.js";
|
|
|
|
|
2019-08-05 22:55:07 +01:00
|
|
|
import showMessage from "./Toast.js"
|
|
|
|
|
2019-07-30 16:25:01 +01:00
|
|
|
const axios = require('axios');
|
2019-07-26 14:18:32 +01:00
|
|
|
|
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,
|
|
|
|
spotify_linked: null
|
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
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-07-26 14:18:32 +01:00
|
|
|
render(){
|
|
|
|
return (
|
|
|
|
<Router>
|
2019-07-29 11:44:10 +01:00
|
|
|
<div className="card pad-12">
|
2019-07-30 16:25:01 +01:00
|
|
|
<table className="sidebar pad-3">
|
|
|
|
<tbody>
|
2020-01-24 15:59:52 +00:00
|
|
|
<tr><td><span><Link to="/app">Home</Link></span></td></tr>
|
|
|
|
<tr><td><Link to="/app/playlists">Playlists</Link></td></tr>
|
|
|
|
<tr><td><Link to="/app/maths/count">Maths</Link></td></tr>
|
|
|
|
<tr><td><Link to="/app/settings/password">Settings</Link></td></tr>
|
|
|
|
{ this.state.type == 'admin' && <tr><td><Link to="/app/admin/lock">Admin</Link></td></tr> }
|
|
|
|
<tr><td><a href="/auth/logout">Logout</a></td></tr>
|
2019-07-30 16:25:01 +01:00
|
|
|
<tr><td><a href="https://sarsoo.xyz">sarsoo.xyz</a></td></tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
2019-07-29 11:44:10 +01:00
|
|
|
|
|
|
|
<div className="pad-9">
|
2019-07-30 16:25:01 +01:00
|
|
|
<Switch>
|
|
|
|
<Route path="/app" exact component={Index} />
|
2019-07-31 20:31:01 +01:00
|
|
|
<Route path="/app/playlists" component={Playlists} />
|
2019-10-19 17:57:56 +01:00
|
|
|
<Route path="/app/maths" component={Maths} />
|
2019-07-31 20:31:01 +01:00
|
|
|
<Route path="/app/settings" component={Settings} />
|
2019-07-30 16:25:01 +01:00
|
|
|
{ this.state.type == 'admin' && <Route path="/app/admin" component={Admin} /> }
|
|
|
|
<Route path='/app/playlist/:name' component={PlaylistView} />
|
|
|
|
<Route component={NotFound} />
|
|
|
|
</Switch>
|
2019-07-29 11:44:10 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-07-31 20:31:01 +01:00
|
|
|
<footer>
|
|
|
|
<a href="https://github.com/Sarsoo/spotify-web">view source code</a>
|
|
|
|
</footer>
|
2019-07-26 14:18:32 +01:00
|
|
|
</Router>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-01-24 15:59:52 +00:00
|
|
|
export default MusicTools;
|