Updates #613. Squashed commit of the following: commit 9a3ba15bdb8476dde045631362d76572a68a4e5c Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jan 19 12:46:48 2023 +0700 client: review dark theme colors commit c456cdcb6ffec044917b0396ad3cfa8b5c3bce10 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jan 18 23:46:32 2023 +0700 client: review dark theme colors commit 4b042ba4f433c89488b18ec38f5864d5ffaf8657 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jan 18 23:34:37 2023 +0700 client: review dark theme colors commit 1ff34f751b4d9342495070af85f3dae86c285aee Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jan 18 18:59:46 2023 +0700 client: default language commit ca9abc11a8c155c78f73903906ed452e95764e99 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jan 18 12:23:50 2023 +0700 client: default language commit 01a057a40e879d1bc2013989d6eb56a296ba16a3 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jan 18 11:53:58 2023 +0700 client: review dark theme colors commit aa3658f35c49f8ae19077b333075207082383a17 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Jan 18 11:14:08 2023 +0700 client: review dark theme colors commit 8df726382155fcc3b2e6e632d53f42d0be638c77 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jan 17 13:41:21 2023 +0700 client: dark theme colors commit bd84ae46272743874d2350291b22b90b7fbedf0e Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jan 17 13:05:46 2023 +0700 client: dark theme colors commit 136ea5608a1a22b6a54a362741b2fdd708f345e2 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Tue Jan 17 10:51:22 2023 +0700 all: docs commit 784be8741b730a12d665d7e2a29c140c0746e927 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Jan 16 17:59:26 2023 +0700 client: imp code commit a83de0948fe034e7be35c04a607b1171915c0263 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Jan 16 14:13:54 2023 +0700 client: dark theme login commit 6c4ef19da01efc6a1e4ea76085b7b7382c331eca Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Jan 16 13:27:35 2023 +0700 client: dark theme css commit 5cf564ea1203e9472d200975ee98d93b6b868210 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Jan 16 13:18:00 2023 +0700 client: imp code commit 1bbbd20972345c08e944b7c4bb0330c0d30d827a Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Jan 16 12:49:03 2023 +0700 client: imp code commit cb07680d3cd7acdbdb7bdc9d9abaa388a9df8e4c Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Jan 16 12:24:14 2023 +0700 client: auto theme handling commit d34910d4dd5edb694b6da55a2260b4fea784e7e0 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Fri Jan 13 23:31:24 2023 +0700 home: imp docs commit 8abe4f6f7182dc3dbcbbe73652294ee6584a4f2f Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Thu Jan 12 18:35:48 2023 +0700 client: theme dropdown
217 lines
5.8 KiB
JavaScript
217 lines
5.8 KiB
JavaScript
import React, { useEffect } from 'react';
|
|
import { HashRouter, Route } from 'react-router-dom';
|
|
import LoadingBar from 'react-redux-loading-bar';
|
|
import { hot } from 'react-hot-loader/root';
|
|
|
|
import 'react-table/react-table.css';
|
|
import '../ui/Tabler.css';
|
|
import '../ui/ReactTable.css';
|
|
import './index.css';
|
|
|
|
import { shallowEqual, useDispatch, useSelector } from 'react-redux';
|
|
|
|
import propTypes from 'prop-types';
|
|
import Toasts from '../Toasts';
|
|
import Footer from '../ui/Footer';
|
|
import Status from '../ui/Status';
|
|
import UpdateTopline from '../ui/UpdateTopline';
|
|
import UpdateOverlay from '../ui/UpdateOverlay';
|
|
import EncryptionTopline from '../ui/EncryptionTopline';
|
|
import Icons from '../ui/Icons';
|
|
import i18n from '../../i18n';
|
|
import Loading from '../ui/Loading';
|
|
import {
|
|
FILTERS_URLS,
|
|
MENU_URLS,
|
|
SETTINGS_URLS,
|
|
THEMES,
|
|
} from '../../helpers/constants';
|
|
import { getLogsUrlParams, setHtmlLangAttr, setUITheme } from '../../helpers/helpers';
|
|
import Header from '../Header';
|
|
import { changeLanguage, getDnsStatus } from '../../actions';
|
|
|
|
import Dashboard from '../../containers/Dashboard';
|
|
import SetupGuide from '../../containers/SetupGuide';
|
|
import Settings from '../../containers/Settings';
|
|
import Dns from '../../containers/Dns';
|
|
import Encryption from '../../containers/Encryption';
|
|
import Dhcp from '../Settings/Dhcp';
|
|
import Clients from '../../containers/Clients';
|
|
import DnsBlocklist from '../../containers/DnsBlocklist';
|
|
import DnsAllowlist from '../../containers/DnsAllowlist';
|
|
import DnsRewrites from '../../containers/DnsRewrites';
|
|
import CustomRules from '../../containers/CustomRules';
|
|
import Services from '../Filters/Services';
|
|
import Logs from '../Logs';
|
|
|
|
const ROUTES = [
|
|
{
|
|
path: MENU_URLS.root,
|
|
component: Dashboard,
|
|
exact: true,
|
|
},
|
|
{
|
|
path: [`${MENU_URLS.logs}${getLogsUrlParams(':search?', ':response_status?')}`, MENU_URLS.logs],
|
|
component: Logs,
|
|
},
|
|
{
|
|
path: MENU_URLS.guide,
|
|
component: SetupGuide,
|
|
},
|
|
{
|
|
path: SETTINGS_URLS.settings,
|
|
component: Settings,
|
|
},
|
|
{
|
|
path: SETTINGS_URLS.dns,
|
|
component: Dns,
|
|
},
|
|
{
|
|
path: SETTINGS_URLS.encryption,
|
|
component: Encryption,
|
|
},
|
|
{
|
|
path: SETTINGS_URLS.dhcp,
|
|
component: Dhcp,
|
|
},
|
|
{
|
|
path: SETTINGS_URLS.clients,
|
|
component: Clients,
|
|
},
|
|
{
|
|
path: FILTERS_URLS.dns_blocklists,
|
|
component: DnsBlocklist,
|
|
},
|
|
{
|
|
path: FILTERS_URLS.dns_allowlists,
|
|
component: DnsAllowlist,
|
|
},
|
|
{
|
|
path: FILTERS_URLS.dns_rewrites,
|
|
component: DnsRewrites,
|
|
},
|
|
{
|
|
path: FILTERS_URLS.custom_rules,
|
|
component: CustomRules,
|
|
},
|
|
{
|
|
path: FILTERS_URLS.blocked_services,
|
|
component: Services,
|
|
},
|
|
];
|
|
|
|
const renderRoute = ({ path, component, exact }, idx) => <Route
|
|
key={idx}
|
|
exact={exact}
|
|
path={path}
|
|
component={component}
|
|
/>;
|
|
|
|
const App = () => {
|
|
const dispatch = useDispatch();
|
|
const {
|
|
language,
|
|
isCoreRunning,
|
|
isUpdateAvailable,
|
|
processing,
|
|
theme,
|
|
} = useSelector((state) => state.dashboard, shallowEqual);
|
|
|
|
const { processing: processingEncryption } = useSelector((
|
|
state,
|
|
) => state.encryption, shallowEqual);
|
|
|
|
const updateAvailable = isCoreRunning && isUpdateAvailable;
|
|
|
|
useEffect(() => {
|
|
dispatch(getDnsStatus());
|
|
}, []);
|
|
|
|
const setLanguage = () => {
|
|
if (!processing) {
|
|
if (language) {
|
|
i18n.changeLanguage(language);
|
|
setHtmlLangAttr(language);
|
|
}
|
|
}
|
|
|
|
i18n.on('languageChanged', (lang) => {
|
|
dispatch(changeLanguage(lang));
|
|
});
|
|
};
|
|
|
|
useEffect(() => {
|
|
setLanguage();
|
|
}, [language]);
|
|
|
|
const handleAutoTheme = (e, accountTheme) => {
|
|
if (accountTheme !== THEMES.auto) {
|
|
return;
|
|
}
|
|
|
|
if (e.matches) {
|
|
setUITheme(THEMES.dark);
|
|
} else {
|
|
setUITheme(THEMES.light);
|
|
}
|
|
};
|
|
|
|
useEffect(() => {
|
|
if (theme !== THEMES.auto) {
|
|
setUITheme(theme);
|
|
|
|
return;
|
|
}
|
|
|
|
const colorSchemeMedia = window.matchMedia('(prefers-color-scheme: dark)');
|
|
const prefersDark = colorSchemeMedia.matches;
|
|
setUITheme(prefersDark ? THEMES.dark : THEMES.light);
|
|
|
|
if (colorSchemeMedia.addEventListener !== undefined) {
|
|
colorSchemeMedia.addEventListener('change', (e) => {
|
|
handleAutoTheme(e, theme);
|
|
});
|
|
} else {
|
|
// Deprecated addListener for older versions of Safari.
|
|
colorSchemeMedia.addListener((e) => {
|
|
handleAutoTheme(e, theme);
|
|
});
|
|
}
|
|
}, [theme]);
|
|
|
|
const reloadPage = () => {
|
|
window.location.reload();
|
|
};
|
|
|
|
return <HashRouter hashType="noslash">
|
|
{updateAvailable && <>
|
|
<UpdateTopline />
|
|
<UpdateOverlay />
|
|
</>}
|
|
{!processingEncryption && <EncryptionTopline />}
|
|
<LoadingBar className="loading-bar" updateTime={1000} />
|
|
<Header />
|
|
<div className="container container--wrap pb-5">
|
|
{processing && <Loading />}
|
|
{!isCoreRunning && <div className="row row-cards">
|
|
<div className="col-lg-12">
|
|
<Status reloadPage={reloadPage} message="dns_start" />
|
|
<Loading />
|
|
</div>
|
|
</div>}
|
|
{!processing && isCoreRunning && ROUTES.map(renderRoute)}
|
|
</div>
|
|
<Footer />
|
|
<Toasts />
|
|
<Icons />
|
|
</HashRouter>;
|
|
};
|
|
|
|
renderRoute.propTypes = {
|
|
path: propTypes.oneOfType([propTypes.string, propTypes.arrayOf(propTypes.string)]).isRequired,
|
|
component: propTypes.element.isRequired,
|
|
exact: propTypes.bool,
|
|
};
|
|
|
|
export default hot(App);
|