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
|
2023-05-18 13:17:41 +02:00
|
|
|
* 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';
|
2023-10-28 00:32:02 +02:00
|
|
|
import { NavBarContext } from '@/components/context/NavbarContext';
|
2024-06-14 13:32:54 +02:00
|
|
|
import { useHistory } from '@/util/useHistory.ts';
|
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-10-28 00:32:02 +02:00
|
|
|
export function NavBarContextProvider({ children }: IProps) {
|
2024-01-05 20:11:29 +01:00
|
|
|
const [title, setTitle] = useState<string | React.ReactNode>('Suwayomi');
|
2022-03-03 15:09:18 +05:30
|
|
|
const [action, setAction] = useState<any>(<div />);
|
|
|
|
|
const [override, setOverride] = useState<INavbarOverride>({
|
|
|
|
|
status: false,
|
|
|
|
|
value: <div />,
|
|
|
|
|
});
|
|
|
|
|
|
2024-06-14 13:32:54 +02:00
|
|
|
const history = useHistory();
|
|
|
|
|
|
2023-03-11 18:05:58 +01:00
|
|
|
const updateTitle = useCallback(
|
2023-04-22 11:39:59 +02:00
|
|
|
(newTitle: string | React.ReactNode, browserTitle: string = typeof newTitle === 'string' ? newTitle : '') => {
|
2024-01-05 20:11:29 +01:00
|
|
|
document.title = `${browserTitle} - Suwayomi`;
|
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(
|
|
|
|
|
() => ({
|
2024-06-14 13:32:54 +02:00
|
|
|
history,
|
2023-03-11 18:05:58 +01:00
|
|
|
title,
|
|
|
|
|
setTitle: updateTitle,
|
|
|
|
|
action,
|
|
|
|
|
setAction,
|
|
|
|
|
override,
|
|
|
|
|
setOverride,
|
|
|
|
|
}),
|
2024-06-14 13:43:15 +02:00
|
|
|
[history, title, updateTitle, action, setAction, override, setOverride],
|
2023-03-11 18:05:58 +01:00
|
|
|
);
|
2023-02-06 10:06:33 +01:00
|
|
|
return <NavBarContext.Provider value={value}>{children}</NavBarContext.Provider>;
|
2022-03-03 15:09:18 +05:30
|
|
|
}
|