Feature/remove use back to util (#360)

* Remove "useBackTo"

Not needed

* Use browser back navigation to close the reader

This will cause the previous page (manga or updates) to be opened instead of always opening the manga page
This commit is contained in:
schroda
2023-06-08 14:25:24 +02:00
committed by GitHub
parent 87de016d6f
commit 63c1ac95eb
7 changed files with 9 additions and 50 deletions

View File

@@ -27,7 +27,6 @@ import ArrowBack from '@mui/icons-material/ArrowBack';
import { Link, useLocation, useNavigate } from 'react-router-dom';
import { createPortal } from 'react-dom';
import { NavbarItem } from '@/typings';
import useBackTo from '@/util/useBackTo';
import NavBarContext from '@/components/context/NavbarContext';
import ExtensionOutlinedIcon from '@/components/util/CustomExtensionOutlinedIcon';
import DesktopSideBar from '@/components/navbar/navigation/DesktopSideBar';
@@ -86,8 +85,7 @@ const navbarItems: Array<NavbarItem> = [
];
export default function DefaultNavBar() {
const { title, action, override } = useContext(NavBarContext);
const backTo = useBackTo();
const { title, action, override, defaultBackTo: backToUrl } = useContext(NavBarContext);
const theme = useTheme();
const navigate = useNavigate();
@@ -109,7 +107,7 @@ export default function DefaultNavBar() {
}
const handleBack = () => {
if (backTo.url != null) return;
if (backToUrl != null) return;
navigate(-1);
};
@@ -119,8 +117,8 @@ export default function DefaultNavBar() {
<Toolbar>
{!isMainRoute && (
<IconButton
component={backTo.url ? Link : 'button'}
to={backTo.url}
component={backToUrl ? Link : 'button'}
to={backToUrl}
edge="start"
sx={{ marginRight: theme.spacing(2) }}
color="inherit"

View File

@@ -25,7 +25,6 @@ import ListItemSecondaryAction from '@mui/material/ListItemSecondaryAction';
import Collapse from '@mui/material/Collapse';
import { useTranslation } from 'react-i18next';
import { ChapterOffset, IChapter, IManga, IMangaCard, IReaderSettings } from '@/typings';
import useBackTo from '@/util/useBackTo';
import ReaderSettingsOptions from '@/components/reader/ReaderSettingsOptions';
const Root = styled('div')(({ theme }) => ({
@@ -126,7 +125,6 @@ interface IProps {
export default function ReaderNavBar(props: IProps) {
const { t } = useTranslation();
const navigate = useNavigate();
const backTo = useBackTo();
const location = useLocation<{
prevDrawerOpen?: boolean;
prevSettingsCollapseOpen?: boolean;
@@ -188,9 +186,9 @@ export default function ReaderNavBar(props: IProps) {
}, [handleScroll]); // handleScroll changes on every render
const handleClose = () => {
if (backTo.back) navigate(-1);
else if (backTo.url) navigate(backTo.url);
else navigate(`/manga/${manga.id}`);
// this works because opening previous/next chapter will replace the current history element.
// in case this gets changed this has to be updated
navigate(-1);
};
return (