Files
suwayomi-material-you-webui/src/components/navbar/NavBarContextProvider.tsx
schroda 4b83ccc889 Feature/use alias for imports (#352)
* Use alias "@" for imports

* Use alias "@" for imports - Fix imports

* Use alias "@" for imports - Prevent faulty "import/extensions" linting issue

For some reason the rule throws an error for alias imports

* Use alias "@" for imports - Update "no-relative-imports" eslint rule
2023-06-05 01:42:39 +02:00

49 lines
1.6 KiB
TypeScript

/*
* 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 React, { useCallback, useMemo, useState } from 'react';
import { INavbarOverride } from '@/typings';
import NavBarContext from '@/components/context/NavbarContext';
interface IProps {
children: React.ReactNode;
}
export default function NavBarProvider({ children }: IProps) {
const [defaultBackTo, setDefaultBackTo] = useState<string | undefined>();
const [title, setTitle] = useState<string | React.ReactNode>('Tachidesk');
const [action, setAction] = useState<any>(<div />);
const [override, setOverride] = useState<INavbarOverride>({
status: false,
value: <div />,
});
const updateTitle = useCallback(
(newTitle: string | React.ReactNode, browserTitle: string = typeof newTitle === 'string' ? newTitle : '') => {
document.title = `${browserTitle} - Tachidesk`;
setTitle(newTitle);
},
[setTitle],
);
const value = useMemo(
() => ({
defaultBackTo,
setDefaultBackTo,
title,
setTitle: updateTitle,
action,
setAction,
override,
setOverride,
}),
[defaultBackTo, setDefaultBackTo, title, updateTitle, action, setAction, override, setOverride],
);
return <NavBarContext.Provider value={value}>{children}</NavBarContext.Provider>;
}