Files
suwayomi-material-you-webui/webUI/react/src/App.tsx

134 lines
5.2 KiB
TypeScript
Raw Normal View History

/*
* Copyright (C) Contributors to the Suwayomi project
*
* This Source Code Form is subject to the terms of the Mozilla Public
2021-01-26 23:32:12 +03:30
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
2021-01-22 17:00:33 +03:30
import React, { useState } from 'react';
2020-12-24 03:21:18 +03:30
import {
2021-02-20 02:41:30 +03:30
BrowserRouter as Router, Redirect, Route, Switch,
2020-12-24 17:19:49 +03:30
} from 'react-router-dom';
2021-01-23 02:32:18 +03:30
import { Container } from '@material-ui/core';
2021-01-23 01:20:16 +03:30
import CssBaseline from '@material-ui/core/CssBaseline';
import { createMuiTheme, ThemeProvider } from '@material-ui/core/styles';
2020-12-24 17:19:49 +03:30
import NavBar from './components/NavBar';
2021-01-19 14:47:07 +03:30
import Sources from './screens/Sources';
import Extensions from './screens/Extensions';
2021-02-20 01:23:52 +03:30
import SourceMangas from './screens/SourceMangas';
2021-01-19 20:20:28 +03:30
import Manga from './screens/Manga';
2021-01-20 01:05:24 +03:30
import Reader from './screens/Reader';
2021-01-22 18:07:31 +03:30
import Search from './screens/SearchSingle';
2021-03-08 21:04:42 +03:30
import NavbarContext from './context/NavbarContext';
2021-01-23 01:20:16 +03:30
import DarkTheme from './context/DarkTheme';
2021-02-13 21:12:18 +03:30
import Library from './screens/Library';
2021-02-20 01:23:52 +03:30
import Settings from './screens/Settings';
import Categories from './screens/settings/Categories';
2021-04-10 00:44:13 +04:30
import Backup from './screens/settings/Backup';
2021-02-25 14:38:16 +03:30
import useLocalStorage from './util/useLocalStorage';
2020-12-24 16:50:50 +01:00
export default function App() {
2021-01-22 17:00:33 +03:30
const [title, setTitle] = useState<string>('Tachidesk');
2021-03-08 21:04:42 +03:30
const [action, setAction] = useState<any>(<div />);
2021-03-18 21:46:24 +03:30
const [override, setOverride] = useState<INavbarOverride>({ status: false, value: <div /> });
2021-02-25 14:38:16 +03:30
const [darkTheme, setDarkTheme] = useLocalStorage<boolean>('darkTheme', true);
2021-03-18 21:46:24 +03:30
2021-03-08 21:04:42 +03:30
const navBarContext = {
2021-03-18 21:46:24 +03:30
title, setTitle, action, setAction, override, setOverride,
2021-03-08 21:04:42 +03:30
};
2021-01-23 01:20:16 +03:30
const darkThemeContext = { darkTheme, setDarkTheme };
const theme = React.useMemo(
() => createMuiTheme({
palette: {
type: darkTheme ? 'dark' : 'light',
},
2021-01-23 02:53:00 +03:30
overrides: {
MuiCssBaseline: {
'@global': {
'*::-webkit-scrollbar': {
width: '10px',
background: darkTheme ? '#222' : '#e1e1e1',
},
'*::-webkit-scrollbar-thumb': {
background: darkTheme ? '#111' : '#aaa',
borderRadius: '5px',
},
},
},
},
2021-01-23 01:20:16 +03:30
}),
[darkTheme],
);
2021-01-22 17:00:33 +03:30
2020-12-24 16:50:50 +01:00
return (
<Router>
2021-01-23 01:20:16 +03:30
<ThemeProvider theme={theme}>
2021-03-08 21:04:42 +03:30
<NavbarContext.Provider value={navBarContext}>
2021-01-23 01:20:16 +03:30
<CssBaseline />
2021-02-20 02:57:52 +03:30
<NavBar />
2021-03-19 14:52:20 +03:30
<Container
id="appMainContainer"
maxWidth={false}
disableGutters
style={{ paddingTop: '64px' }}
>
2021-01-23 02:32:18 +03:30
<Switch>
<Route path="/sources/:sourceId/search/">
<Search />
</Route>
<Route path="/extensions">
<Extensions />
</Route>
<Route path="/sources/:sourceId/popular/">
2021-02-20 01:23:52 +03:30
<SourceMangas popular />
2021-01-23 02:32:18 +03:30
</Route>
<Route path="/sources/:sourceId/latest/">
2021-02-20 01:23:52 +03:30
<SourceMangas popular={false} />
2021-01-23 02:32:18 +03:30
</Route>
<Route path="/sources">
<Sources />
</Route>
2021-03-23 03:50:55 +04:30
<Route path="/manga/:mangaId/chapter/:chapterNum">
2021-03-18 21:46:24 +03:30
<></>
2021-01-23 02:32:18 +03:30
</Route>
<Route path="/manga/:id">
<Manga />
</Route>
2021-02-13 21:12:18 +03:30
<Route path="/library">
<Library />
</Route>
2021-02-20 01:23:52 +03:30
<Route path="/settings/categories">
<Categories />
</Route>
2021-04-10 00:44:13 +04:30
<Route path="/settings/backup">
<Backup />
</Route>
2021-02-20 01:23:52 +03:30
<Route path="/settings">
2021-02-20 02:57:52 +03:30
<DarkTheme.Provider value={darkThemeContext}>
<Settings />
</DarkTheme.Provider>
2021-02-20 01:23:52 +03:30
</Route>
2021-02-20 02:41:30 +03:30
<Route
exact
path="/"
render={() => (
<Redirect to="/library" />
)}
/>
2021-01-23 02:32:18 +03:30
</Switch>
</Container>
2021-03-18 21:46:24 +03:30
<Switch>
2021-03-23 03:50:55 +04:30
<Route path="/manga/:mangaId/chapter/:chapterIndex">
2021-03-18 21:46:24 +03:30
<Reader />
</Route>
</Switch>
2021-03-08 21:04:42 +03:30
</NavbarContext.Provider>
2021-01-23 01:20:16 +03:30
</ThemeProvider>
2020-12-24 16:50:50 +01:00
</Router>
);
}