Back button implementation (#47)

* Added the back button to the main Ui

* Changed the naviation in the reader ui so that when the next or previous chapter links are clicked, instead of adding the a new history entry, it will replace the current History entry and rereder the Reader component

* - Made changes so that if history is of length 1 then the backbutton will take you to /library
- made use of the startsWith method so that if we use url for the saving the last viewed category there won't be a need to change this
- changed a few relative imports to absolute imports

* Back button won't show for any route that has an icon in the  sidebar
This commit is contained in:
abhijeetChawla
2021-10-26 13:49:23 +05:30
committed by GitHub
parent 663232cd99
commit b9b5b2818c
2 changed files with 27 additions and 4 deletions

View File

@@ -20,10 +20,12 @@ import ExtensionIcon from '@mui/icons-material/Extension';
import ExploreIcon from '@mui/icons-material/Explore'; import ExploreIcon from '@mui/icons-material/Explore';
import GetAppIcon from '@mui/icons-material/GetApp'; import GetAppIcon from '@mui/icons-material/GetApp';
import SettingsIcon from '@mui/icons-material/Settings'; import SettingsIcon from '@mui/icons-material/Settings';
import ArrowBack from '@mui/icons-material/ArrowBack';
import { useHistory } from 'react-router-dom';
import NavBarContext from 'context/NavbarContext'; import NavBarContext from 'context/NavbarContext';
import DarkTheme from 'context/DarkTheme'; import DarkTheme from 'context/DarkTheme';
import PermanentSideBar from './PermanentSideBar';
import TemporaryDrawer from './TemporaryDrawer'; import TemporaryDrawer from './TemporaryDrawer';
import PermanentSideBar from './PermanentSideBar';
const useStyles = makeStyles((theme) => ({ const useStyles = makeStyles((theme) => ({
root: { root: {
@@ -72,6 +74,7 @@ export default function NavBar() {
const { title, action, override } = useContext(NavBarContext); const { title, action, override } = useContext(NavBarContext);
const theme = useTheme(); const theme = useTheme();
const isMobileWidth = useMediaQuery(theme.breakpoints.down('sm')); const isMobileWidth = useMediaQuery(theme.breakpoints.down('sm'));
const history = useHistory();
const { darkTheme } = useContext(DarkTheme); const { darkTheme } = useContext(DarkTheme);
@@ -83,7 +86,7 @@ export default function NavBar() {
<div className={classes.root}> <div className={classes.root}>
<AppBar position="fixed" color={darkTheme ? 'default' : 'primary'}> <AppBar position="fixed" color={darkTheme ? 'default' : 'primary'}>
<Toolbar> <Toolbar>
{isMobileWidth && ( {isMobileWidth ? (
<IconButton <IconButton
edge="start" edge="start"
className={classes.menuButton} className={classes.menuButton}
@@ -95,7 +98,25 @@ export default function NavBar() {
> >
<MenuIcon /> <MenuIcon />
</IconButton> </IconButton>
)} )
: (
!navbarItems.some(({ path }) => path === history.location.pathname)
&& (
<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>
)
)}
<Typography variant={isMobileWidth ? 'h6' : 'h5'} className={classes.title}> <Typography variant={isMobileWidth ? 'h6' : 'h5'} className={classes.title}>
{title} {title}
</Typography> </Typography>

View File

@@ -228,7 +228,7 @@ export default function ReaderNavBar(props: IProps) {
color="inherit" color="inherit"
aria-label="menu" aria-label="menu"
disableRipple disableRipple
onClick={() => history.push(`/manga/${manga.id}`)} onClick={() => history.goBack()}
size="large" size="large"
> >
<CloseIcon /> <CloseIcon />
@@ -344,6 +344,7 @@ export default function ReaderNavBar(props: IProps) {
{chapter.index > 1 {chapter.index > 1
&& ( && (
<Link <Link
replace
style={{ gridArea: 'prev' }} style={{ gridArea: 'prev' }}
to={`/manga/${manga.id}/chapter/${chapter.index - 1}`} to={`/manga/${manga.id}/chapter/${chapter.index - 1}`}
> >
@@ -358,6 +359,7 @@ export default function ReaderNavBar(props: IProps) {
{chapter.index < chapter.chapterCount {chapter.index < chapter.chapterCount
&& ( && (
<Link <Link
replace
style={{ gridArea: 'next' }} style={{ gridArea: 'next' }}
to={`/manga/${manga.id}/chapter/${chapter.index + 1}`} to={`/manga/${manga.id}/chapter/${chapter.index + 1}`}
> >