import "./dark.sass"; // TODO: lazyload
import "./index.sass";
import "./overscrollColourFixer.ts";
import { useEffect } from "react";
import ReactDOM from "react-dom";
import {
BrowserRouter as Router,
Switch,
Route,
Redirect,
useLocation,
} from "react-router-dom";
import { ProvideAuth, HandleOAuthLogin, useAuth } from "./useAuth";
import Login from "./pages/Login";
import Dashboard from "./pages/Dashboard";
import CrateView from "./pages/crate/CrateView";
import ListSshKeys from "./pages/ssh-keys/ListSshKeys";
import AddSshKeys from "./pages/ssh-keys/AddSshKeys";
import ListOrganisations from "./pages/organisations/ListOrganisations";
import OrganisationView from "./pages/crate/OrganisationView";
import CreateOrganisation from "./pages/organisations/CreateOrganisation";
import User from "./pages/User";
import Search from "./pages/Search";
import { backgroundFix } from "./overscrollColourFixer";
import Register from "./pages/Register";
if (
window.matchMedia &&
window.matchMedia("(prefers-color-scheme: dark)").matches
) {
document.querySelector("body")?.classList.add("dark");
}
window
.matchMedia("(prefers-color-scheme: dark)")
.addEventListener("change", (e) => {
const body = document.querySelector("body");
body?.classList.toggle("dark", e.matches);
backgroundFix(body);
});
function App() {
return (
}
/>
}
/>
}
/>
}
/>
}
/>
}
/>
}
/>
} />
}
/>
}
/>
}
/>
}
/>
}
/>
}
/>
} />
);
}
ReactDOM.render(, document.getElementById("root"));
function PublicRoute({
component: Component,
unauthedOnly,
...rest
}: {
component: ({
match,
location,
}: {
match: any;
location: ReturnType;
}) => JSX.Element;
unauthedOnly: boolean;
} & { [r: string]: any }) {
const auth = useAuth();
return (
{
// TODO: check if valid key
if (!unauthedOnly || !auth || !auth?.getAuthKey()) {
return ;
} else {
return (
);
}
}}
/>
);
}
function PrivateRoute({
component: Component,
...rest
}: {
component: ({
match,
location,
}: {
match: any;
location: ReturnType;
}) => JSX.Element;
} & { [r: string]: any }) {
const auth = useAuth();
const isAuthenticated = auth?.getAuthKey();
useEffect(() => {
if (!isAuthenticated) {
auth?.logout();
}
}, [isAuthenticated]);
return (
{
// TODO: check if valid key
if (auth && isAuthenticated) {
return ;
} else {
return (
);
}
}}
/>
);
}