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

111 lines
3.8 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 Logs from '../../containers/Logs';
import Footer from '../ui/Footer';
2018-09-14 12:37:35 +00:00
import Toasts from '../Toasts';
2018-08-30 14:25:33 +00:00
import Status from '../ui/Status';
import Topline from '../ui/Topline';
import EncryptionTopline from '../ui/EncryptionTopline';
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-09-21 12:20:41 +00:00
this.props.getVersion();
2018-08-30 14:25:33 +00:00
}
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();
};
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-08-30 14:25:33 +00:00
render() {
2019-01-30 13:24:17 +00:00
const { dashboard, encryption } = this.props;
2018-09-21 12:20:41 +00:00
const updateAvailable =
!dashboard.processingVersions &&
dashboard.isCoreRunning &&
dashboard.isUpdateAvailable;
2018-08-30 14:25:33 +00:00
return (
<HashRouter hashType='noslash'>
<Fragment>
2018-09-21 12:20:41 +00:00
{updateAvailable &&
<Topline type="info">
{dashboard.announcement} <a href={dashboard.announcementUrl} target="_blank" rel="noopener noreferrer">Click here</a> for more info.
</Topline>
}
{!encryption.processing &&
<EncryptionTopline notAfter={encryption.not_after} />
2018-09-21 12:20:41 +00:00
}
<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 &&
<div className="row row-cards">
<div className="col-lg-12">
<Status handleStatusChange={this.handleStatusChange} />
</div>
</div>
}
{!dashboard.processing && dashboard.isCoreRunning &&
<Fragment>
<Route path="/" exact component={Dashboard} />
<Route path="/settings" component={Settings} />
<Route path="/filters" component={Filters} />
<Route path="/logs" component={Logs} />
</Fragment>
}
</div>
<Footer />
2018-09-14 12:37:35 +00:00
<Toasts />
2018-08-30 14:25:33 +00:00
</Fragment>
</HashRouter>
);
}
}
App.propTypes = {
getDnsStatus: PropTypes.func,
enableDns: PropTypes.func,
dashboard: PropTypes.object,
isCoreRunning: PropTypes.bool,
2018-09-14 12:37:35 +00:00
error: PropTypes.string,
2018-09-21 12:20:41 +00:00
getVersion: PropTypes.func,
2018-11-22 14:56:57 +00:00
changeLanguage: PropTypes.func,
encryption: PropTypes.object,
2018-08-30 14:25:33 +00:00
};
export default withNamespaces()(App);