2020-05-31 13:47:57 +02:00
|
|
|
import React from 'react';
|
2020-10-25 18:48:23 +00:00
|
|
|
import HomePage from './pages/HomePage/HomePage';
|
|
|
|
import RandomPage from './pages/RandomPage/RandomPage';
|
|
|
|
import GlobalInfos from './GlobalInfos';
|
2020-05-31 20:24:35 +02:00
|
|
|
|
2020-06-01 20:46:28 +02:00
|
|
|
// include bootstraps css
|
2020-05-31 13:47:57 +02:00
|
|
|
import 'bootstrap/dist/css/bootstrap.min.css';
|
2020-10-25 18:48:23 +00:00
|
|
|
import style from './App.module.css';
|
2020-07-24 22:47:21 +02:00
|
|
|
|
2020-10-25 18:48:23 +00:00
|
|
|
import SettingsPage from './pages/SettingsPage/SettingsPage';
|
|
|
|
import CategoryPage from './pages/CategoryPage/CategoryPage';
|
2020-05-31 13:47:57 +02:00
|
|
|
|
2020-08-12 17:50:25 +00:00
|
|
|
/**
|
|
|
|
* The main App handles the main tabs and which content to show
|
|
|
|
*/
|
2020-05-31 13:47:57 +02:00
|
|
|
class App extends React.Component {
|
2020-08-05 17:55:51 +00:00
|
|
|
newElement = null;
|
|
|
|
|
2020-05-31 20:24:35 +02:00
|
|
|
constructor(props, context) {
|
|
|
|
super(props, context);
|
2020-07-13 22:56:43 +02:00
|
|
|
this.state = {
|
2020-10-25 18:48:23 +00:00
|
|
|
page: 'default',
|
2020-07-13 22:56:43 +02:00
|
|
|
generalSettingsLoaded: false,
|
2020-07-15 20:08:22 +02:00
|
|
|
passwordsupport: null,
|
2020-10-25 18:48:23 +00:00
|
|
|
mediacentername: 'OpenMediaCenter'
|
2020-07-13 22:56:43 +02:00
|
|
|
};
|
2020-06-01 17:58:48 +02:00
|
|
|
|
|
|
|
// bind this to the method for being able to call methods such as this.setstate
|
2020-06-21 23:08:46 +02:00
|
|
|
this.changeRootElement = this.changeRootElement.bind(this);
|
|
|
|
this.returnToLastElement = this.returnToLastElement.bind(this);
|
2020-12-11 18:23:13 +00:00
|
|
|
|
|
|
|
// set the main navigation viewbinding to the singleton
|
|
|
|
GlobalInfos.setViewBinding(this.constructViewBinding());
|
2020-05-31 13:47:57 +02:00
|
|
|
}
|
|
|
|
|
2020-07-13 22:56:43 +02:00
|
|
|
componentDidMount() {
|
|
|
|
const updateRequest = new FormData();
|
|
|
|
updateRequest.append('action', 'loadInitialData');
|
|
|
|
|
2020-08-12 17:50:25 +00:00
|
|
|
fetch('/api/settings.php', {method: 'POST', body: updateRequest})
|
2020-07-13 22:56:43 +02:00
|
|
|
.then((response) => response.json()
|
|
|
|
.then((result) => {
|
2020-07-28 18:17:17 +02:00
|
|
|
// set theme
|
2020-08-05 22:00:55 +02:00
|
|
|
GlobalInfos.enableDarkTheme(result.DarkMode);
|
2020-07-28 18:17:17 +02:00
|
|
|
|
2020-07-13 22:56:43 +02:00
|
|
|
this.setState({
|
|
|
|
generalSettingsLoaded: true,
|
2020-07-15 20:08:22 +02:00
|
|
|
passwordsupport: result.passwordEnabled,
|
|
|
|
mediacentername: result.mediacenter_name
|
2020-07-13 22:56:43 +02:00
|
|
|
});
|
2020-07-26 14:27:56 +02:00
|
|
|
// set tab title to received mediacenter name
|
|
|
|
document.title = result.mediacenter_name;
|
2020-07-13 22:56:43 +02:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2020-08-12 17:50:25 +00:00
|
|
|
/**
|
|
|
|
* create a viewbinding to call APP functions from child elements
|
|
|
|
* @returns a set of callback functions
|
|
|
|
*/
|
2020-07-16 19:13:54 +02:00
|
|
|
constructViewBinding() {
|
2020-07-13 22:56:43 +02:00
|
|
|
return {
|
|
|
|
changeRootElement: this.changeRootElement,
|
2020-07-15 20:08:22 +02:00
|
|
|
returnToLastElement: this.returnToLastElement
|
2020-07-13 22:56:43 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-08-12 17:50:25 +00:00
|
|
|
/**
|
|
|
|
* load the selected component into the main view
|
|
|
|
* @returns {JSX.Element} body element of selected page
|
|
|
|
*/
|
2020-06-02 22:52:28 +02:00
|
|
|
MainBody() {
|
|
|
|
let page;
|
2020-10-25 18:48:23 +00:00
|
|
|
if (this.state.page === 'default') {
|
2020-12-11 18:23:13 +00:00
|
|
|
page = <HomePage/>;
|
2020-06-02 22:52:28 +02:00
|
|
|
this.mypage = page;
|
2020-10-25 18:48:23 +00:00
|
|
|
} else if (this.state.page === 'random') {
|
2020-12-11 18:23:13 +00:00
|
|
|
page = <RandomPage/>;
|
2020-06-02 22:52:28 +02:00
|
|
|
this.mypage = page;
|
2020-10-25 18:48:23 +00:00
|
|
|
} else if (this.state.page === 'settings') {
|
2020-06-04 22:19:18 +02:00
|
|
|
page = <SettingsPage/>;
|
|
|
|
this.mypage = page;
|
2020-10-25 18:48:23 +00:00
|
|
|
} else if (this.state.page === 'categories') {
|
2020-12-11 18:23:13 +00:00
|
|
|
page = <CategoryPage/>;
|
2020-06-07 11:37:50 +02:00
|
|
|
this.mypage = page;
|
2020-10-25 18:48:23 +00:00
|
|
|
} else if (this.state.page === 'video') {
|
2020-06-02 22:52:28 +02:00
|
|
|
// show videoelement if neccessary
|
2020-06-21 23:08:46 +02:00
|
|
|
page = this.newElement;
|
2020-06-07 21:42:01 +02:00
|
|
|
|
|
|
|
console.log(page);
|
2020-10-25 18:48:23 +00:00
|
|
|
} else if (this.state.page === 'lastpage') {
|
2020-06-02 22:52:28 +02:00
|
|
|
// return back to last page
|
|
|
|
page = this.mypage;
|
|
|
|
} else {
|
|
|
|
page = <div>unimplemented yet!</div>;
|
|
|
|
}
|
|
|
|
return (page);
|
|
|
|
}
|
|
|
|
|
2020-05-31 13:47:57 +02:00
|
|
|
render() {
|
2020-08-05 22:00:55 +02:00
|
|
|
const themeStyle = GlobalInfos.getThemeStyle();
|
2020-07-26 18:17:29 +02:00
|
|
|
// add the main theme to the page body
|
2020-07-28 18:17:17 +02:00
|
|
|
document.body.className = themeStyle.backgroundcolor;
|
2020-05-31 13:47:57 +02:00
|
|
|
return (
|
2020-08-30 22:01:54 +00:00
|
|
|
<div className={style.app}>
|
2020-07-26 18:17:29 +02:00
|
|
|
<div className={[style.navcontainer, themeStyle.backgroundcolor, themeStyle.textcolor, themeStyle.hrcolor].join(' ')}>
|
2020-07-24 22:47:21 +02:00
|
|
|
<div className={style.navbrand}>{this.state.mediacentername}</div>
|
|
|
|
|
2020-10-25 18:48:23 +00:00
|
|
|
<div className={[style.navitem, themeStyle.navitem, this.state.page === 'default' ? style.navitemselected : {}].join(' ')}
|
|
|
|
onClick={() => this.setState({page: 'default'})}>Home
|
2020-07-24 22:47:21 +02:00
|
|
|
</div>
|
2020-10-25 18:48:23 +00:00
|
|
|
<div className={[style.navitem, themeStyle.navitem, this.state.page === 'random' ? style.navitemselected : {}].join(' ')}
|
|
|
|
onClick={() => this.setState({page: 'random'})}>Random Video
|
2020-07-24 22:47:21 +02:00
|
|
|
</div>
|
2020-10-25 18:48:23 +00:00
|
|
|
<div className={[style.navitem, themeStyle.navitem, this.state.page === 'categories' ? style.navitemselected : {}].join(' ')}
|
|
|
|
onClick={() => this.setState({page: 'categories'})}>Categories
|
2020-07-24 22:47:21 +02:00
|
|
|
</div>
|
2020-10-25 18:48:23 +00:00
|
|
|
<div className={[style.navitem, themeStyle.navitem, this.state.page === 'settings' ? style.navitemselected : {}].join(' ')}
|
|
|
|
onClick={() => this.setState({page: 'settings'})}>Settings
|
2020-07-24 22:47:21 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-10-25 18:48:23 +00:00
|
|
|
{this.state.generalSettingsLoaded ? this.MainBody() : 'loading'}
|
2020-05-31 13:47:57 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-08-12 17:50:25 +00:00
|
|
|
/**
|
|
|
|
* render a new root element into the main body
|
|
|
|
*/
|
2020-06-21 23:08:46 +02:00
|
|
|
changeRootElement(element) {
|
|
|
|
this.newElement = element;
|
2020-06-07 21:42:01 +02:00
|
|
|
|
2020-06-01 17:58:48 +02:00
|
|
|
this.setState({
|
2020-10-25 18:48:23 +00:00
|
|
|
page: 'video'
|
2020-06-01 17:58:48 +02:00
|
|
|
});
|
|
|
|
}
|
2020-06-01 19:09:32 +02:00
|
|
|
|
2020-08-12 17:50:25 +00:00
|
|
|
/**
|
|
|
|
* return from page to the previous page before a change
|
|
|
|
*/
|
2020-06-21 23:08:46 +02:00
|
|
|
returnToLastElement() {
|
2020-06-01 19:09:32 +02:00
|
|
|
this.setState({
|
2020-10-25 18:48:23 +00:00
|
|
|
page: 'lastpage'
|
2020-06-01 19:09:32 +02:00
|
|
|
});
|
|
|
|
}
|
2020-05-31 13:47:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default App;
|