2020-06-14 12:38:35 +02:00
|
|
|
import React from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
|
|
|
import './include/index.css';
|
|
|
|
import './include/adminlte.min.css';
|
|
|
|
import API from './api.js';
|
|
|
|
import Header from './header.js';
|
|
|
|
import Sidebar from './sidebar.js';
|
|
|
|
import UserOverview from './users.js';
|
|
|
|
import Overview from './overview.js'
|
|
|
|
import Icon from "./icon";
|
|
|
|
import Dialog from "./dialog";
|
|
|
|
|
|
|
|
class AdminDashboard extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.api = new API();
|
|
|
|
this.state = {
|
|
|
|
currentView: "dashboard",
|
|
|
|
loaded: false,
|
2020-06-14 22:35:01 +02:00
|
|
|
dialog: { }
|
2020-06-14 12:38:35 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
onChangeView(view) {
|
2020-06-14 22:35:01 +02:00
|
|
|
this.setState({ ...this.state, currentView: view || "dashboard", dialog: { } });
|
2020-06-14 12:38:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
showDialog(props) {
|
2020-06-14 22:35:01 +02:00
|
|
|
props = props || { };
|
2020-06-14 12:38:35 +02:00
|
|
|
this.setState({ ...this.state, dialog: props });
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
|
|
|
if (!this.state.loaded) {
|
|
|
|
this.api.fetchUser().then(Success => {
|
|
|
|
if (!Success) {
|
|
|
|
document.location = "/admin";
|
|
|
|
} else {
|
|
|
|
this.setState({...this.state, loaded: true});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return <b>Loading… <Icon icon={"spinner"} /></b>
|
|
|
|
}
|
|
|
|
|
2020-06-14 22:35:01 +02:00
|
|
|
console.log("index.render, state=", this.state);
|
|
|
|
return <>
|
|
|
|
<Header />
|
|
|
|
<Sidebar currentView={this.state.currentView} onChangeView={this.onChangeView.bind(this)} showDialog={this.showDialog.bind(this)} api={this.api} />
|
|
|
|
<div className={"content-wrapper p-2"}>
|
|
|
|
<section className={"content"}>
|
|
|
|
{this.createContent()}
|
|
|
|
<Dialog {...this.state.dialog}/>
|
|
|
|
</section>
|
|
|
|
</div>
|
|
|
|
</>
|
2020-06-14 12:38:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
createContent() {
|
|
|
|
if (this.state.currentView === "users") {
|
|
|
|
return <UserOverview />
|
|
|
|
} else {
|
|
|
|
return <Overview />
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ReactDOM.render(
|
|
|
|
<AdminDashboard />,
|
|
|
|
document.getElementById('root')
|
|
|
|
);
|