badguardhome/client/src/components/App/index.js

139 lines
5.1 KiB
JavaScript
Raw Normal View History

2018-08-30 14:25:33 +00:00
import React, { Component, Fragment } from 'react';
import { HashRouter, Route } from 'react-router-dom';
import PropTypes from 'prop-types';
import { withNamespaces } from 'react-i18next';
import LoadingBar from 'react-redux-loading-bar';
2018-08-30 14:25:33 +00:00
import 'react-table/react-table.css';
import '../ui/Tabler.css';
import '../ui/ReactTable.css';
import './index.css';
import Header from '../../containers/Header';
import Dashboard from '../../containers/Dashboard';
import Settings from '../../containers/Settings';
import Filters from '../../containers/Filters';
import Dns from '../../containers/Dns';
import Encryption from '../../containers/Encryption';
import Dhcp from '../../containers/Dhcp';
import Clients from '../../containers/Clients';
2018-08-30 14:25:33 +00:00
import Logs from '../../containers/Logs';
import SetupGuide from '../../containers/SetupGuide';
2018-09-14 12:37:35 +00:00
import Toasts from '../Toasts';
import Footer from '../ui/Footer';
2018-08-30 14:25:33 +00:00
import Status from '../ui/Status';
2019-02-20 13:54:14 +00:00
import UpdateTopline from '../ui/UpdateTopline';
2019-05-16 14:24:30 +00:00
import UpdateOverlay from '../ui/UpdateOverlay';
import EncryptionTopline from '../ui/EncryptionTopline';
2019-05-23 09:32:51 +00:00
import Icons from '../ui/Icons';
2018-11-22 14:56:57 +00:00
import i18n from '../../i18n';
2018-08-30 14:25:33 +00:00
class App extends Component {
componentDidMount() {
this.props.getDnsStatus();
}
2018-11-22 14:56:57 +00:00
componentDidUpdate(prevProps) {
if (this.props.dashboard.language !== prevProps.dashboard.language) {
this.setLanguage();
}
}
2018-08-30 14:25:33 +00:00
handleStatusChange = () => {
this.props.enableDns();
};
2019-05-16 14:24:30 +00:00
handleUpdate = () => {
this.props.getUpdate();
};
2019-05-16 14:24:30 +00:00
2018-11-22 14:56:57 +00:00
setLanguage = () => {
const { processing, language } = this.props.dashboard;
if (!processing) {
if (language) {
2018-11-22 14:56:57 +00:00
i18n.changeLanguage(language);
}
}
i18n.on('languageChanged', (lang) => {
this.props.changeLanguage(lang);
});
};
2018-11-22 14:56:57 +00:00
2018-08-30 14:25:33 +00:00
render() {
2019-09-05 16:07:14 +00:00
const { dashboard, encryption, getVersion } = this.props;
2019-06-25 14:56:50 +00:00
const updateAvailable = dashboard.isCoreRunning && dashboard.isUpdateAvailable;
2018-09-21 12:20:41 +00:00
2018-08-30 14:25:33 +00:00
return (
<HashRouter hashType="noslash">
2018-08-30 14:25:33 +00:00
<Fragment>
{updateAvailable && (
2019-05-16 14:24:30 +00:00
<Fragment>
<UpdateTopline
url={dashboard.announcementUrl}
version={dashboard.newVersion}
canAutoUpdate={dashboard.canAutoUpdate}
getUpdate={this.handleUpdate}
processingUpdate={dashboard.processingUpdate}
/>
<UpdateOverlay processingUpdate={dashboard.processingUpdate} />
</Fragment>
)}
{!encryption.processing && (
<EncryptionTopline notAfter={encryption.not_after} />
)}
<LoadingBar className="loading-bar" updateTime={1000} />
2018-08-30 14:25:33 +00:00
<Route component={Header} />
<div className="container container--wrap">
{!dashboard.processing && !dashboard.isCoreRunning && (
2018-08-30 14:25:33 +00:00
<div className="row row-cards">
<div className="col-lg-12">
<Status handleStatusChange={this.handleStatusChange} />
</div>
</div>
)}
{!dashboard.processing && dashboard.isCoreRunning && (
2018-08-30 14:25:33 +00:00
<Fragment>
<Route path="/" exact component={Dashboard} />
<Route path="/settings" component={Settings} />
<Route path="/dns" component={Dns} />
<Route path="/encryption" component={Encryption} />
<Route path="/dhcp" component={Dhcp} />
<Route path="/clients" component={Clients} />
2018-08-30 14:25:33 +00:00
<Route path="/filters" component={Filters} />
<Route path="/logs" component={Logs} />
<Route path="/guide" component={SetupGuide} />
2018-08-30 14:25:33 +00:00
</Fragment>
)}
2018-08-30 14:25:33 +00:00
</div>
2019-09-05 16:07:14 +00:00
<Footer
dnsVersion={dashboard.dnsVersion}
dnsPort={dashboard.dnsPort}
processingVersion={dashboard.processingVersion}
getVersion={getVersion}
/>
2018-09-14 12:37:35 +00:00
<Toasts />
2019-05-23 09:32:51 +00:00
<Icons />
2018-08-30 14:25:33 +00:00
</Fragment>
</HashRouter>
);
}
}
App.propTypes = {
getDnsStatus: PropTypes.func,
2019-05-16 14:24:30 +00:00
getUpdate: PropTypes.func,
2018-08-30 14:25:33 +00:00
enableDns: PropTypes.func,
dashboard: PropTypes.object,
isCoreRunning: PropTypes.bool,
2018-09-14 12:37:35 +00:00
error: PropTypes.string,
2018-11-22 14:56:57 +00:00
changeLanguage: PropTypes.func,
encryption: PropTypes.object,
2019-09-05 16:07:14 +00:00
getVersion: PropTypes.func,
2018-08-30 14:25:33 +00:00
};
export default withNamespaces()(App);