Files
suwayomi-material-you-webui/src/components/TemporaryDrawer.tsx

124 lines
5.3 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/. */
2020-12-24 16:50:50 +01:00
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Drawer from '@material-ui/core/Drawer';
import List from '@material-ui/core/List';
import ListItem from '@material-ui/core/ListItem';
import ListItemIcon from '@material-ui/core/ListItemIcon';
2021-05-23 13:48:02 +04:30
import CollectionsBookmarkIcon from '@material-ui/icons/CollectionsBookmark';
2021-08-10 09:40:43 +04:30
import CollectionsBookmarkOutlinedIcon from '@material-ui/icons/CollectionsBookmarkOutlined';
import VideoLibraryOutlinedIcon from '@material-ui/icons/VideoLibraryOutlined';
2021-05-23 13:48:02 +04:30
import ExploreIcon from '@material-ui/icons/Explore';
import ExtensionIcon from '@material-ui/icons/Extension';
2021-05-30 04:01:49 +04:30
import GetAppIcon from '@material-ui/icons/GetApp';
2020-12-24 16:50:50 +01:00
import ListItemText from '@material-ui/core/ListItemText';
2021-05-23 13:48:02 +04:30
import SettingsIcon from '@material-ui/icons/Settings';
2020-12-24 16:50:50 +01:00
import { Link } from 'react-router-dom';
2021-08-10 09:40:43 +04:30
import useLocalStorage from 'util/useLocalStorage';
2020-12-24 16:50:50 +01:00
const useStyles = makeStyles({
list: {
width: 250,
},
});
interface IProps {
drawerOpen: boolean
2020-12-25 06:36:34 +03:30
2021-05-15 17:18:57 +04:30
setDrawerOpen: React.Dispatch<React.SetStateAction<boolean>>
2020-12-24 16:50:50 +01:00
}
export default function TemporaryDrawer({ drawerOpen, setDrawerOpen }: IProps) {
const classes = useStyles();
2021-08-10 09:40:43 +04:30
const [workingMode, setWorkingMode] = useLocalStorage<'manga'|'anime'>('workingMode', 'manga');
const otherMode = () => {
if (workingMode === 'manga') return 'Anime';
return 'Manga';
};
const switchMode = () => {
if (workingMode === 'manga') setWorkingMode('anime');
else setWorkingMode('manga');
};
2020-12-24 16:50:50 +01:00
return (
<div>
<Drawer
open={drawerOpen}
anchor="left"
onClose={() => setDrawerOpen(false)}
>
2021-03-18 21:46:24 +03:30
<div
className={classes.list}
role="presentation"
onClick={() => setDrawerOpen(false)}
onKeyDown={() => setDrawerOpen(false)}
>
<List>
2021-08-10 09:40:43 +04:30
{workingMode === 'manga'
&& (
<Link to="/library" style={{ color: 'inherit', textDecoration: 'none' }}>
<ListItem button key="Library">
<ListItemIcon>
<CollectionsBookmarkIcon />
</ListItemIcon>
<ListItemText primary="Library" />
</ListItem>
</Link>
)}
<Link to={`/${workingMode}/extensions`} style={{ color: 'inherit', textDecoration: 'none' }}>
2021-03-18 21:46:24 +03:30
<ListItem button key="Extensions">
<ListItemIcon>
2021-05-23 13:48:02 +04:30
<ExtensionIcon />
2021-03-18 21:46:24 +03:30
</ListItemIcon>
2021-07-31 04:14:48 +04:30
<ListItemText primary="Extensions" />
</ListItem>
</Link>
2021-08-10 09:40:43 +04:30
<Link to={`/${workingMode}/sources`} style={{ color: 'inherit', textDecoration: 'none' }}>
2021-03-18 21:46:24 +03:30
<ListItem button key="Sources">
<ListItemIcon>
2021-05-23 13:48:02 +04:30
<ExploreIcon />
2021-03-18 21:46:24 +03:30
</ListItemIcon>
2021-07-31 04:14:48 +04:30
<ListItemText primary="Sources" />
2021-05-27 17:13:22 +04:30
</ListItem>
</Link>
2021-08-10 09:40:43 +04:30
{workingMode === 'manga'
&& (
<Link to="/manga/downloads" style={{ color: 'inherit', textDecoration: 'none' }}>
<ListItem button key="Manga Download Queue">
<ListItemIcon>
<GetAppIcon />
</ListItemIcon>
<ListItemText primary="Downloads" />
</ListItem>
</Link>
)}
2021-03-18 21:46:24 +03:30
<Link to="/settings" style={{ color: 'inherit', textDecoration: 'none' }}>
<ListItem button key="settings">
<ListItemIcon>
2021-05-23 13:48:02 +04:30
<SettingsIcon />
2021-03-18 21:46:24 +03:30
</ListItemIcon>
<ListItemText primary="Settings" />
</ListItem>
</Link>
2021-08-10 09:40:43 +04:30
<ListItem button key="SwitchMode" onClick={switchMode}>
<ListItemIcon>
{workingMode === 'manga' && <VideoLibraryOutlinedIcon />}
{workingMode === 'anime' && <CollectionsBookmarkOutlinedIcon />}
</ListItemIcon>
<ListItemText primary={`Switch to ${otherMode()}`} />
</ListItem>
2021-03-18 21:46:24 +03:30
</List>
</div>
2020-12-24 16:50:50 +01:00
</Drawer>
</div>
);
}