Fix navbar back button behavior (#195)

* Enable passing backLink through location state. Explicitly handle cases for BACK

* Allow pages to override default backLink. Fix manga page back link

* Cleanup
This commit is contained in:
Valter Martinek
2022-11-21 01:33:45 +01:00
committed by GitHub
parent 68f67273aa
commit 3972d7757f
11 changed files with 94 additions and 31 deletions

View File

@@ -5,9 +5,13 @@
* 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 React from 'react';
import React, { useContext, useEffect } from 'react';
type ContextType = {
// Default back button url
defaultBackTo: string | undefined
setDefaultBackTo: React.Dispatch<React.SetStateAction<string | undefined>>
// AppBar title
title: string
setTitle: React.Dispatch<React.SetStateAction<string>>
@@ -22,6 +26,8 @@ type ContextType = {
};
const NavBarContext = React.createContext<ContextType>({
defaultBackTo: undefined,
setDefaultBackTo: ():void => {},
title: 'Tachidesk',
setTitle: ():void => {},
action: <div />,
@@ -31,3 +37,14 @@ const NavBarContext = React.createContext<ContextType>({
});
export default NavBarContext;
export const useNavBarContext = () => useContext(NavBarContext);
export const useSetDefaultBackTo = (value: string) => {
const { setDefaultBackTo } = useNavBarContext();
useEffect(() => {
setDefaultBackTo(value);
return () => setDefaultBackTo(undefined);
}, [value]);
};