Files
suwayomi-material-you-webui/src/components/context/NavbarContext.tsx
T

51 lines
1.4 KiB
TypeScript
Raw Normal View History

/*
* Copyright (C) Contributors to the Suwayomi project
*
* This Source Code Form is subject to the terms of the Mozilla Public
2021-01-26 23:32:12 +03:30
* 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/. */
2022-11-21 01:33:45 +01:00
import React, { useContext, useEffect } from 'react';
2021-01-22 17:00:33 +03:30
type ContextType = {
2022-11-21 01:33:45 +01:00
// Default back button url
2023-02-06 10:06:33 +01:00
defaultBackTo: string | undefined;
setDefaultBackTo: React.Dispatch<React.SetStateAction<string | undefined>>;
2022-11-21 01:33:45 +01:00
2021-10-30 16:10:34 +03:30
// AppBar title
2023-02-06 10:06:33 +01:00
title: string;
setTitle: (title: string) => void;
2021-10-30 16:10:34 +03:30
// AppBar action buttons
2023-02-06 10:06:33 +01:00
action: any;
setAction: React.Dispatch<React.SetStateAction<any>>;
2021-10-30 16:10:34 +03:30
// Allow default navbar to be overrided
2023-02-06 10:06:33 +01:00
override: INavbarOverride;
setOverride: React.Dispatch<React.SetStateAction<INavbarOverride>>;
2021-01-22 17:00:33 +03:30
};
2021-03-08 21:04:42 +03:30
const NavBarContext = React.createContext<ContextType>({
2022-11-21 01:33:45 +01:00
defaultBackTo: undefined,
2023-02-06 10:06:33 +01:00
setDefaultBackTo: (): void => {},
2021-01-22 17:00:33 +03:30
title: 'Tachidesk',
2023-02-06 10:06:33 +01:00
setTitle: (): void => {},
2021-03-08 21:04:42 +03:30
action: <div />,
2023-02-06 10:06:33 +01:00
setAction: (): void => {},
2021-03-18 21:46:24 +03:30
override: { status: false, value: <div /> },
2023-02-06 10:06:33 +01:00
setOverride: (): void => {},
2021-01-22 17:00:33 +03:30
});
2021-03-08 21:04:42 +03:30
export default NavBarContext;
2022-11-21 01:33:45 +01:00
export const useNavBarContext = () => useContext(NavBarContext);
export const useSetDefaultBackTo = (value: string) => {
const { setDefaultBackTo } = useNavBarContext();
useEffect(() => {
setDefaultBackTo(value);
return () => setDefaultBackTo(undefined);
}, [value]);
};