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:
@@ -15,7 +15,6 @@ import { Avatar, Box, CardContent, Grid, styled } from '@mui/material';
|
|||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { IMangaCard } from '@/typings';
|
import { IMangaCard } from '@/typings';
|
||||||
import requestManager from '@/lib/RequestManager';
|
import requestManager from '@/lib/RequestManager';
|
||||||
import { BACK } from '@/util/useBackTo';
|
|
||||||
import useLocalStorage from '@/util/useLocalStorage';
|
import useLocalStorage from '@/util/useLocalStorage';
|
||||||
import { GridLayout, useLibraryOptionsContext } from '@/components/context/LibraryOptionsContext';
|
import { GridLayout, useLibraryOptionsContext } from '@/components/context/LibraryOptionsContext';
|
||||||
import SpinnerImage from '@/components/util/SpinnerImage';
|
import SpinnerImage from '@/components/util/SpinnerImage';
|
||||||
@@ -89,7 +88,7 @@ const MangaCard = React.forwardRef<HTMLDivElement, IProps>((props: IProps, ref)
|
|||||||
|
|
||||||
const [ItemWidth] = useLocalStorage<number>('ItemWidth', 300);
|
const [ItemWidth] = useLocalStorage<number>('ItemWidth', 300);
|
||||||
|
|
||||||
const mangaLinkTo = { pathname: `/manga/${id}/`, state: { backLink: BACK } };
|
const mangaLinkTo = `/manga/${id}/`;
|
||||||
|
|
||||||
if (gridLayout !== GridLayout.List) {
|
if (gridLayout !== GridLayout.List) {
|
||||||
const columns = Math.ceil(dimensions / ItemWidth);
|
const columns = Math.ceil(dimensions / ItemWidth);
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { IChapter, IDownloadChapter } from '@/typings';
|
import { IChapter, IDownloadChapter } from '@/typings';
|
||||||
import requestManager from '@/lib/RequestManager';
|
import requestManager from '@/lib/RequestManager';
|
||||||
import { getUploadDateString } from '@/util/date';
|
import { getUploadDateString } from '@/util/date';
|
||||||
import { BACK } from '@/util/useBackTo';
|
|
||||||
import DownloadStateIndicator from '@/components/molecules/DownloadStateIndicator';
|
import DownloadStateIndicator from '@/components/molecules/DownloadStateIndicator';
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
@@ -113,7 +112,6 @@ const ChapterCard: React.FC<IProps> = (props: IProps) => {
|
|||||||
<CardActionArea
|
<CardActionArea
|
||||||
component={Link}
|
component={Link}
|
||||||
to={`/manga/${chapter.mangaId}/chapter/${chapter.index}`}
|
to={`/manga/${chapter.mangaId}/chapter/${chapter.index}`}
|
||||||
state={{ backLink: BACK }}
|
|
||||||
style={{
|
style={{
|
||||||
color: theme.palette.text[chapter.read ? 'disabled' : 'primary'],
|
color: theme.palette.text[chapter.read ? 'disabled' : 'primary'],
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import { Link } from 'react-router-dom';
|
|||||||
import { PlayArrow } from '@mui/icons-material';
|
import { PlayArrow } from '@mui/icons-material';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { IChapter } from '@/typings';
|
import { IChapter } from '@/typings';
|
||||||
import { BACK } from '@/util/useBackTo';
|
|
||||||
import StyledFab from '@/components/util/StyledFab';
|
import StyledFab from '@/components/util/StyledFab';
|
||||||
|
|
||||||
interface ResumeFABProps {
|
interface ResumeFABProps {
|
||||||
@@ -27,13 +26,7 @@ export default function ResumeFab(props: ResumeFABProps) {
|
|||||||
mangaId,
|
mangaId,
|
||||||
} = props;
|
} = props;
|
||||||
return (
|
return (
|
||||||
<StyledFab
|
<StyledFab component={Link} variant="extended" color="primary" to={`/manga/${mangaId}/chapter/${index}`}>
|
||||||
component={Link}
|
|
||||||
variant="extended"
|
|
||||||
color="primary"
|
|
||||||
to={`/manga/${mangaId}/chapter/${index}`}
|
|
||||||
state={{ backLink: BACK }}
|
|
||||||
>
|
|
||||||
<PlayArrow />
|
<PlayArrow />
|
||||||
{index === 1 ? t('global.button.start') : t('global.button.resume')}
|
{index === 1 ? t('global.button.start') : t('global.button.resume')}
|
||||||
</StyledFab>
|
</StyledFab>
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import ArrowBack from '@mui/icons-material/ArrowBack';
|
|||||||
import { Link, useLocation, useNavigate } from 'react-router-dom';
|
import { Link, useLocation, useNavigate } from 'react-router-dom';
|
||||||
import { createPortal } from 'react-dom';
|
import { createPortal } from 'react-dom';
|
||||||
import { NavbarItem } from '@/typings';
|
import { NavbarItem } from '@/typings';
|
||||||
import useBackTo from '@/util/useBackTo';
|
|
||||||
import NavBarContext from '@/components/context/NavbarContext';
|
import NavBarContext from '@/components/context/NavbarContext';
|
||||||
import ExtensionOutlinedIcon from '@/components/util/CustomExtensionOutlinedIcon';
|
import ExtensionOutlinedIcon from '@/components/util/CustomExtensionOutlinedIcon';
|
||||||
import DesktopSideBar from '@/components/navbar/navigation/DesktopSideBar';
|
import DesktopSideBar from '@/components/navbar/navigation/DesktopSideBar';
|
||||||
@@ -86,8 +85,7 @@ const navbarItems: Array<NavbarItem> = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
export default function DefaultNavBar() {
|
export default function DefaultNavBar() {
|
||||||
const { title, action, override } = useContext(NavBarContext);
|
const { title, action, override, defaultBackTo: backToUrl } = useContext(NavBarContext);
|
||||||
const backTo = useBackTo();
|
|
||||||
|
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@@ -109,7 +107,7 @@ export default function DefaultNavBar() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleBack = () => {
|
const handleBack = () => {
|
||||||
if (backTo.url != null) return;
|
if (backToUrl != null) return;
|
||||||
navigate(-1);
|
navigate(-1);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -119,8 +117,8 @@ export default function DefaultNavBar() {
|
|||||||
<Toolbar>
|
<Toolbar>
|
||||||
{!isMainRoute && (
|
{!isMainRoute && (
|
||||||
<IconButton
|
<IconButton
|
||||||
component={backTo.url ? Link : 'button'}
|
component={backToUrl ? Link : 'button'}
|
||||||
to={backTo.url}
|
to={backToUrl}
|
||||||
edge="start"
|
edge="start"
|
||||||
sx={{ marginRight: theme.spacing(2) }}
|
sx={{ marginRight: theme.spacing(2) }}
|
||||||
color="inherit"
|
color="inherit"
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import ListItemSecondaryAction from '@mui/material/ListItemSecondaryAction';
|
|||||||
import Collapse from '@mui/material/Collapse';
|
import Collapse from '@mui/material/Collapse';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { ChapterOffset, IChapter, IManga, IMangaCard, IReaderSettings } from '@/typings';
|
import { ChapterOffset, IChapter, IManga, IMangaCard, IReaderSettings } from '@/typings';
|
||||||
import useBackTo from '@/util/useBackTo';
|
|
||||||
import ReaderSettingsOptions from '@/components/reader/ReaderSettingsOptions';
|
import ReaderSettingsOptions from '@/components/reader/ReaderSettingsOptions';
|
||||||
|
|
||||||
const Root = styled('div')(({ theme }) => ({
|
const Root = styled('div')(({ theme }) => ({
|
||||||
@@ -126,7 +125,6 @@ interface IProps {
|
|||||||
export default function ReaderNavBar(props: IProps) {
|
export default function ReaderNavBar(props: IProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const backTo = useBackTo();
|
|
||||||
const location = useLocation<{
|
const location = useLocation<{
|
||||||
prevDrawerOpen?: boolean;
|
prevDrawerOpen?: boolean;
|
||||||
prevSettingsCollapseOpen?: boolean;
|
prevSettingsCollapseOpen?: boolean;
|
||||||
@@ -188,9 +186,9 @@ export default function ReaderNavBar(props: IProps) {
|
|||||||
}, [handleScroll]); // handleScroll changes on every render
|
}, [handleScroll]); // handleScroll changes on every render
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
if (backTo.back) navigate(-1);
|
// this works because opening previous/next chapter will replace the current history element.
|
||||||
else if (backTo.url) navigate(backTo.url);
|
// in case this gets changed this has to be updated
|
||||||
else navigate(`/manga/${manga.id}`);
|
navigate(-1);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { IChapter, IQueue } from '@/typings';
|
import { IChapter, IQueue } from '@/typings';
|
||||||
import requestManager from '@/lib/RequestManager';
|
import requestManager from '@/lib/RequestManager';
|
||||||
import StrictModeDroppable from '@/lib/StrictModeDroppable';
|
import StrictModeDroppable from '@/lib/StrictModeDroppable';
|
||||||
import { BACK } from '@/util/useBackTo';
|
|
||||||
import makeToast from '@/components/util/Toast';
|
import makeToast from '@/components/util/Toast';
|
||||||
import { NavbarToolbar } from '@/components/navbar/DefaultNavBar';
|
import { NavbarToolbar } from '@/components/navbar/DefaultNavBar';
|
||||||
import DownloadStateIndicator from '@/components/molecules/DownloadStateIndicator';
|
import DownloadStateIndicator from '@/components/molecules/DownloadStateIndicator';
|
||||||
@@ -120,7 +119,6 @@ const DownloadQueue: React.FC = () => {
|
|||||||
<CardActionArea
|
<CardActionArea
|
||||||
component={Link}
|
component={Link}
|
||||||
to={`/manga/${item.chapter.mangaId}`}
|
to={`/manga/${item.chapter.mangaId}`}
|
||||||
state={{ backLink: BACK }}
|
|
||||||
sx={{
|
sx={{
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) Contributors to the Suwayomi project
|
|
||||||
*
|
|
||||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* 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/.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { useLocation } from 'react-router-dom';
|
|
||||||
import { useNavBarContext } from '@/components/context/NavbarContext';
|
|
||||||
|
|
||||||
export const BACK = '__BACK__';
|
|
||||||
|
|
||||||
const useBackTo = (): { url?: string; back: boolean } => {
|
|
||||||
const location = useLocation<{ backLink?: string }>();
|
|
||||||
const { defaultBackTo } = useNavBarContext();
|
|
||||||
|
|
||||||
const url = location.state?.backLink ?? defaultBackTo;
|
|
||||||
return {
|
|
||||||
url: url === BACK ? undefined : url,
|
|
||||||
back: url === BACK,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export default useBackTo;
|
|
||||||
Reference in New Issue
Block a user