import React, { useState, useEffect } from "react";
import { Route, Switch, NavLink, useRouteMatch } from "react-router-dom";
import "./error.scss";
import "./adminpage.scss";
import { Icon, LoadingPage, CSSTransition } from "../components/";
import { Admin } from "../model";
import { notify } from "../helpers/";
import {
HomePage, BackendPage, SettingsPage, LogPage, SetupPage, LoginPage,
} from "./adminpage/";
import { t } from "../locales/";
function AdminOnly(WrappedComponent) {
let initIsAdmin = null;
return function AdminOnlyComponent(props) {
const [isAdmin, setIsAdmin] = useState(initIsAdmin);
const refresh = () => {
Admin.isAdmin().then((t) => {
initIsAdmin = t;
setIsAdmin(t);
}).catch((err) => {
notify.send("Error: " + (err && err.message), "error");
});
};
useEffect(() => {
refresh();
const timeout = window.setInterval(refresh, 5 * 1000);
return () => clearInterval(timeout);
}, []);
if (isAdmin === true) {
return (