Use global navigation history stack
The readers history stack was different to the one from the rest of the app, resulting in an infinite loop when using the closing the reader and using the back button in the manga page, since the back button just opened the reader again.
Regression introduced with 4bb458778e
This commit is contained in:
@@ -10,6 +10,8 @@ import React, { useContext, useEffect } from 'react';
|
||||
import { INavbarOverride } from '@/typings';
|
||||
|
||||
type ContextType = {
|
||||
history: string[];
|
||||
|
||||
// Default back button url
|
||||
defaultBackTo: string | undefined;
|
||||
setDefaultBackTo: React.Dispatch<React.SetStateAction<string | undefined>>;
|
||||
@@ -28,6 +30,7 @@ type ContextType = {
|
||||
};
|
||||
|
||||
export const NavBarContext = React.createContext<ContextType>({
|
||||
history: [],
|
||||
defaultBackTo: undefined,
|
||||
setDefaultBackTo: (): void => {},
|
||||
title: 'Suwayomi',
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
import React, { useCallback, useMemo, useState } from 'react';
|
||||
import { INavbarOverride } from '@/typings';
|
||||
import { NavBarContext } from '@/components/context/NavbarContext';
|
||||
import { useHistory } from '@/util/useHistory.ts';
|
||||
|
||||
interface IProps {
|
||||
children: React.ReactNode;
|
||||
@@ -23,6 +24,8 @@ export function NavBarContextProvider({ children }: IProps) {
|
||||
value: <div />,
|
||||
});
|
||||
|
||||
const history = useHistory();
|
||||
|
||||
const updateTitle = useCallback(
|
||||
(newTitle: string | React.ReactNode, browserTitle: string = typeof newTitle === 'string' ? newTitle : '') => {
|
||||
document.title = `${browserTitle} - Suwayomi`;
|
||||
@@ -33,6 +36,7 @@ export function NavBarContextProvider({ children }: IProps) {
|
||||
|
||||
const value = useMemo(
|
||||
() => ({
|
||||
history,
|
||||
defaultBackTo,
|
||||
setDefaultBackTo,
|
||||
title,
|
||||
@@ -42,7 +46,7 @@ export function NavBarContextProvider({ children }: IProps) {
|
||||
override,
|
||||
setOverride,
|
||||
}),
|
||||
[defaultBackTo, setDefaultBackTo, title, updateTitle, action, setAction, override, setOverride],
|
||||
[history, defaultBackTo, setDefaultBackTo, title, updateTitle, action, setAction, override, setOverride],
|
||||
);
|
||||
return <NavBarContext.Provider value={value}>{children}</NavBarContext.Provider>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user