2021-04-20 22:23:35 +00:00
|
|
|
import {useState} from "react"
|
|
|
|
import classNames from "classnames"
|
|
|
|
import Style from "./App.module.css"
|
2021-04-21 13:08:54 +00:00
|
|
|
import Layout from "./components/Layout"
|
2021-04-21 13:37:12 +00:00
|
|
|
import ContextTheme from "./contexts/ContextTheme"
|
2021-04-21 16:00:21 +00:00
|
|
|
import { BrowserRouter } from "react-router-dom"
|
2021-04-21 16:21:30 +00:00
|
|
|
import { Route, Switch } from "react-router"
|
|
|
|
import PageHome from "./routes/PageHome"
|
|
|
|
import PageRepositories from "./routes/PageRepositories"
|
|
|
|
import PageAlerts from "./routes/PageAlerts"
|
|
|
|
import PageSettings from "./routes/PageSettings"
|
2021-04-22 16:06:50 +00:00
|
|
|
import PageSandbox from "./routes/PageSandbox"
|
2021-04-20 22:09:13 +00:00
|
|
|
|
2021-04-20 22:07:39 +00:00
|
|
|
|
2021-04-20 22:23:35 +00:00
|
|
|
export default function App() {
|
2021-04-22 14:45:09 +00:00
|
|
|
const loadTheme = () => {
|
|
|
|
if(localStorage) {
|
|
|
|
console.debug(`Loading theme from localStorage...`)
|
|
|
|
let value = localStorage.getItem("theme")
|
|
|
|
|
|
|
|
if(value) {
|
|
|
|
console.debug(`Loaded theme ${value}!`)
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.debug(`There is no theme stored in the localStorage; setting to "ThemeDark"...`)
|
|
|
|
return "ThemeDark"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.warn(`Can't load theme; localStorage doesn't seem to be available; setting to "ThemeDark"...`)
|
|
|
|
return "ThemeDark"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const [theme, _setTheme] = useState(loadTheme());
|
|
|
|
|
|
|
|
const setTheme = (value) => {
|
|
|
|
console.debug(`Changing theme to ${value}...`)
|
|
|
|
_setTheme(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
const saveTheme = (value) => {
|
|
|
|
if(localStorage) {
|
|
|
|
console.debug(`Saving theme ${value} to localStorage...`)
|
|
|
|
localStorage.setItem("theme", value)
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.warn(`Can't save theme; localStorage doesn't seem to be available...`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const setAndSaveTheme = (value) => {
|
|
|
|
setTheme(value)
|
|
|
|
saveTheme(value)
|
|
|
|
}
|
2021-04-20 22:23:35 +00:00
|
|
|
|
2021-04-20 22:09:13 +00:00
|
|
|
return (
|
2021-04-22 14:45:09 +00:00
|
|
|
<ContextTheme.Provider value={[theme, setAndSaveTheme]}>
|
2021-04-21 16:00:21 +00:00
|
|
|
<BrowserRouter>
|
|
|
|
|
2021-04-21 13:37:12 +00:00
|
|
|
<div className={classNames(Style.App, theme)}>
|
|
|
|
<Layout>
|
2021-04-21 16:21:30 +00:00
|
|
|
<Switch>
|
2021-04-22 16:06:50 +00:00
|
|
|
<Route path={"/repositories"} exact={true}>
|
2021-04-21 16:21:30 +00:00
|
|
|
<PageRepositories/>
|
|
|
|
</Route>
|
2021-04-22 16:06:50 +00:00
|
|
|
<Route path={"/alerts"} exact={true}>
|
2021-04-21 16:21:30 +00:00
|
|
|
<PageAlerts/>
|
|
|
|
</Route>
|
2021-04-22 16:06:50 +00:00
|
|
|
<Route path={"/settings"} exact={true}>
|
2021-04-21 16:21:30 +00:00
|
|
|
<PageSettings/>
|
|
|
|
</Route>
|
2021-04-22 16:06:50 +00:00
|
|
|
<Route path={"/sandbox"} exact={true}>
|
|
|
|
<PageSandbox/>
|
|
|
|
</Route>
|
|
|
|
<Route path={"/"} exact={true}>
|
2021-04-21 16:32:05 +00:00
|
|
|
<PageHome/>
|
|
|
|
</Route>
|
2021-04-21 16:21:30 +00:00
|
|
|
</Switch>
|
2021-04-21 13:37:12 +00:00
|
|
|
</Layout>
|
|
|
|
</div>
|
2021-04-21 16:00:21 +00:00
|
|
|
|
|
|
|
</BrowserRouter>
|
2021-04-21 13:37:12 +00:00
|
|
|
</ContextTheme.Provider>
|
2021-04-20 22:09:13 +00:00
|
|
|
)
|
2021-04-20 22:07:39 +00:00
|
|
|
}
|