Files
suwayomi-material-you-webui/src/components/navbar/NavBarContextProvider.tsx
T

49 lines
1.6 KiB
TypeScript
Raw Normal View History

2022-03-03 15:09:18 +05:30
/*
* 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/.
*/
2022-03-03 15:09:18 +05:30
2023-03-11 18:05:58 +01:00
import React, { useCallback, useMemo, useState } from 'react';
2023-06-05 01:42:39 +02:00
import { INavbarOverride } from '@/typings';
import NavBarContext from '@/components/context/NavbarContext';
2022-03-03 15:09:18 +05:30
2023-02-06 10:06:33 +01:00
interface IProps {
children: React.ReactNode;
2022-03-03 15:09:18 +05:30
}
2023-02-06 10:06:33 +01:00
export default function NavBarProvider({ children }: IProps) {
2022-11-21 01:33:45 +01:00
const [defaultBackTo, setDefaultBackTo] = useState<string | undefined>();
const [title, setTitle] = useState<string | React.ReactNode>('Tachidesk');
2022-03-03 15:09:18 +05:30
const [action, setAction] = useState<any>(<div />);
const [override, setOverride] = useState<INavbarOverride>({
status: false,
value: <div />,
});
2023-03-11 18:05:58 +01:00
const updateTitle = useCallback(
(newTitle: string | React.ReactNode, browserTitle: string = typeof newTitle === 'string' ? newTitle : '') => {
document.title = `${browserTitle} - Tachidesk`;
2023-03-11 18:05:58 +01:00
setTitle(newTitle);
},
[setTitle],
);
2023-01-07 16:44:00 +01:00
2023-03-11 18:05:58 +01:00
const value = useMemo(
() => ({
defaultBackTo,
setDefaultBackTo,
title,
setTitle: updateTitle,
action,
setAction,
override,
setOverride,
}),
[defaultBackTo, setDefaultBackTo, title, updateTitle, action, setAction, override, setOverride],
);
2023-02-06 10:06:33 +01:00
return <NavBarContext.Provider value={value}>{children}</NavBarContext.Provider>;
2022-03-03 15:09:18 +05:30
}