2021-03-26 04:17:02 +04:30
|
|
|
/*
|
|
|
|
|
* 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-10-29 17:51:43 +05:30
|
|
|
import React, { useContext } from 'react';
|
2021-09-09 17:51:22 +04:30
|
|
|
import makeStyles from '@mui/styles/makeStyles';
|
|
|
|
|
import AppBar from '@mui/material/AppBar';
|
|
|
|
|
import Toolbar from '@mui/material/Toolbar';
|
|
|
|
|
import Typography from '@mui/material/Typography';
|
|
|
|
|
import IconButton from '@mui/material/IconButton';
|
2021-10-24 21:34:38 +05:30
|
|
|
import { useMediaQuery } from '@mui/material';
|
|
|
|
|
import { useTheme } from '@mui/material/styles';
|
|
|
|
|
import CollectionsBookmarkIcon from '@mui/icons-material/CollectionsBookmark';
|
2021-10-30 17:29:27 +03:30
|
|
|
import CollectionsOutlinedBookmarkIcon from '@mui/icons-material/CollectionsBookmarkOutlined';
|
2021-10-24 21:34:38 +05:30
|
|
|
import NewReleasesIcon from '@mui/icons-material/NewReleases';
|
2021-10-30 17:29:27 +03:30
|
|
|
import NewReleasesOutlinedIcon from '@mui/icons-material/NewReleasesOutlined';
|
2021-10-24 21:34:38 +05:30
|
|
|
import ExploreIcon from '@mui/icons-material/Explore';
|
2021-10-30 17:29:27 +03:30
|
|
|
import ExploreOutlinedIcon from '@mui/icons-material/ExploreOutlined';
|
2021-10-30 16:34:09 +03:30
|
|
|
import ExtensionIcon from '@mui/icons-material/Extension';
|
2021-10-24 21:34:38 +05:30
|
|
|
import GetAppIcon from '@mui/icons-material/GetApp';
|
2021-10-30 17:29:27 +03:30
|
|
|
import GetAppOutlinedIcon from '@mui/icons-material/GetAppOutlined';
|
2021-10-24 21:34:38 +05:30
|
|
|
import SettingsIcon from '@mui/icons-material/Settings';
|
2021-10-26 13:49:23 +05:30
|
|
|
import ArrowBack from '@mui/icons-material/ArrowBack';
|
|
|
|
|
import { useHistory } from 'react-router-dom';
|
2021-10-30 16:10:34 +03:30
|
|
|
import NavBarContext from 'components/context/NavbarContext';
|
|
|
|
|
import DarkTheme from 'components/context/DarkTheme';
|
2021-10-30 18:20:03 +03:30
|
|
|
import ExtensionOutlinedIcon from './CustomExtensionOutlinedIcon';
|
2021-10-30 16:10:34 +03:30
|
|
|
import DesktopSideBar from './navigation/DesktopSideBar';
|
|
|
|
|
import MobileBottomBar from './navigation/MobileBottomBar';
|
2020-12-24 15:02:03 +03:30
|
|
|
|
|
|
|
|
const useStyles = makeStyles((theme) => ({
|
|
|
|
|
root: {
|
|
|
|
|
flexGrow: 1,
|
|
|
|
|
},
|
|
|
|
|
menuButton: {
|
|
|
|
|
marginRight: theme.spacing(2),
|
|
|
|
|
},
|
|
|
|
|
title: {
|
|
|
|
|
flexGrow: 1,
|
|
|
|
|
},
|
|
|
|
|
}));
|
|
|
|
|
|
2021-10-24 21:34:38 +05:30
|
|
|
const navbarItems: Array<NavbarItem> = [
|
|
|
|
|
{
|
|
|
|
|
path: '/library',
|
|
|
|
|
title: 'Library',
|
2021-10-30 17:29:27 +03:30
|
|
|
SelectedIconComponent: CollectionsBookmarkIcon,
|
|
|
|
|
IconComponent: CollectionsOutlinedBookmarkIcon,
|
2021-10-30 16:34:09 +03:30
|
|
|
show: 'both',
|
|
|
|
|
}, {
|
2021-10-24 21:34:38 +05:30
|
|
|
path: '/updates',
|
|
|
|
|
title: 'Updates',
|
2021-10-30 17:29:27 +03:30
|
|
|
SelectedIconComponent: NewReleasesIcon,
|
|
|
|
|
IconComponent: NewReleasesOutlinedIcon,
|
2021-10-30 16:34:09 +03:30
|
|
|
show: 'both',
|
|
|
|
|
}, {
|
|
|
|
|
path: '/sources',
|
|
|
|
|
title: 'Sources',
|
2021-10-30 17:29:27 +03:30
|
|
|
SelectedIconComponent: ExploreIcon,
|
|
|
|
|
IconComponent: ExploreOutlinedIcon,
|
2021-10-30 16:34:09 +03:30
|
|
|
show: 'desktop',
|
|
|
|
|
}, {
|
|
|
|
|
path: '/extensions',
|
|
|
|
|
title: 'Extensions',
|
2021-10-30 17:29:27 +03:30
|
|
|
SelectedIconComponent: ExtensionIcon,
|
|
|
|
|
IconComponent: ExtensionOutlinedIcon,
|
2021-10-30 16:34:09 +03:30
|
|
|
show: 'desktop',
|
2021-10-24 21:34:38 +05:30
|
|
|
}, {
|
2021-10-26 14:57:11 +03:30
|
|
|
path: '/browse',
|
|
|
|
|
title: 'Browse',
|
2021-10-30 17:29:27 +03:30
|
|
|
SelectedIconComponent: ExploreIcon,
|
|
|
|
|
IconComponent: ExploreOutlinedIcon,
|
2021-10-30 16:34:09 +03:30
|
|
|
show: 'mobile',
|
2021-10-24 21:34:38 +05:30
|
|
|
}, {
|
2021-10-26 12:13:37 +03:30
|
|
|
path: '/downloads',
|
2021-10-29 17:51:43 +05:30
|
|
|
title: 'Downloads',
|
2021-10-30 17:29:27 +03:30
|
|
|
SelectedIconComponent: GetAppIcon,
|
|
|
|
|
IconComponent: GetAppOutlinedIcon,
|
2021-10-30 16:34:09 +03:30
|
|
|
show: 'both',
|
2021-10-24 21:34:38 +05:30
|
|
|
}, {
|
|
|
|
|
path: '/settings',
|
|
|
|
|
title: 'Settings',
|
2021-10-30 17:29:27 +03:30
|
|
|
SelectedIconComponent: SettingsIcon,
|
2021-10-24 21:34:38 +05:30
|
|
|
IconComponent: SettingsIcon,
|
2021-10-30 16:34:09 +03:30
|
|
|
show: 'both',
|
2021-10-24 21:34:38 +05:30
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
2021-10-30 16:10:34 +03:30
|
|
|
export default function DefaultNavBar() {
|
2020-12-24 15:02:03 +03:30
|
|
|
const classes = useStyles();
|
2021-03-18 21:46:24 +03:30
|
|
|
const { title, action, override } = useContext(NavBarContext);
|
2021-10-30 16:10:34 +03:30
|
|
|
const { darkTheme } = useContext(DarkTheme);
|
|
|
|
|
|
2021-10-24 21:34:38 +05:30
|
|
|
const theme = useTheme();
|
2021-10-26 13:49:23 +05:30
|
|
|
const history = useHistory();
|
2021-01-23 01:20:16 +03:30
|
|
|
|
2021-10-30 16:10:34 +03:30
|
|
|
const isMobileWidth = useMediaQuery(theme.breakpoints.down('sm'));
|
|
|
|
|
const isMainRoute = navbarItems.some(({ path }) => path === history.location.pathname);
|
2021-01-23 01:20:16 +03:30
|
|
|
|
2021-10-30 16:10:34 +03:30
|
|
|
// Allow default navbar to be overrided
|
2021-10-30 15:19:49 +03:30
|
|
|
if (override.status) return override.value;
|
|
|
|
|
|
|
|
|
|
let navbar = <></>;
|
|
|
|
|
if (isMobileWidth) {
|
2021-10-30 16:34:09 +03:30
|
|
|
if (isMainRoute) {
|
|
|
|
|
navbar = <MobileBottomBar navBarItems={navbarItems.filter((it) => it.show !== 'desktop')} />;
|
2021-10-30 15:19:49 +03:30
|
|
|
}
|
|
|
|
|
} else {
|
2021-10-30 16:34:09 +03:30
|
|
|
navbar = <DesktopSideBar navBarItems={navbarItems.filter((it) => it.show !== 'mobile')} />;
|
2021-10-30 15:19:49 +03:30
|
|
|
}
|
|
|
|
|
|
2020-12-24 15:02:03 +03:30
|
|
|
return (
|
2021-09-09 17:51:22 +04:30
|
|
|
<div className={classes.root}>
|
|
|
|
|
<AppBar position="fixed" color={darkTheme ? 'default' : 'primary'}>
|
|
|
|
|
<Toolbar>
|
2021-10-29 17:51:43 +05:30
|
|
|
{
|
|
|
|
|
!navbarItems.some(({ path }) => path === history.location.pathname)
|
2021-10-26 13:49:23 +05:30
|
|
|
&& (
|
|
|
|
|
<IconButton
|
|
|
|
|
edge="start"
|
|
|
|
|
className={classes.menuButton}
|
|
|
|
|
color="inherit"
|
|
|
|
|
aria-label="menu"
|
|
|
|
|
disableRipple
|
|
|
|
|
// when page is opened in new tab backbutton will
|
|
|
|
|
// take you to the library
|
|
|
|
|
onClick={() => (history.length === 1 ? history.push('/library') : history.goBack())}
|
|
|
|
|
size="large"
|
|
|
|
|
>
|
|
|
|
|
<ArrowBack />
|
|
|
|
|
</IconButton>
|
|
|
|
|
)
|
2021-10-29 17:51:43 +05:30
|
|
|
}
|
2021-10-24 21:34:38 +05:30
|
|
|
<Typography variant={isMobileWidth ? 'h6' : 'h5'} className={classes.title}>
|
2021-09-09 17:51:22 +04:30
|
|
|
{title}
|
|
|
|
|
</Typography>
|
|
|
|
|
{action}
|
|
|
|
|
</Toolbar>
|
|
|
|
|
</AppBar>
|
2021-10-30 15:19:49 +03:30
|
|
|
{navbar}
|
2021-09-09 17:51:22 +04:30
|
|
|
</div>
|
2020-12-24 15:02:03 +03:30
|
|
|
);
|
|
|
|
|
}
|