forked from Suwayomi/Suwayomi-WebUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNavbarContext.tsx
50 lines (40 loc) · 1.45 KB
/
NavbarContext.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* 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, { 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>>
// AppBar action buttons
action: any
setAction: React.Dispatch<React.SetStateAction<any>>
// Allow default navbar to be overrided
override: INavbarOverride
setOverride: React.Dispatch<React.SetStateAction<INavbarOverride>>
};
const NavBarContext = React.createContext<ContextType>({
defaultBackTo: undefined,
setDefaultBackTo: ():void => {},
title: 'Tachidesk',
setTitle: ():void => {},
action: <div />,
setAction: ():void => {},
override: { status: false, value: <div /> },
setOverride: ():void => {},
});
export default NavBarContext;
export const useNavBarContext = () => useContext(NavBarContext);
export const useSetDefaultBackTo = (value: string) => {
const { setDefaultBackTo } = useNavBarContext();
useEffect(() => {
setDefaultBackTo(value);
return () => setDefaultBackTo(undefined);
}, [value]);
};