-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContextProvider.tsx
64 lines (55 loc) · 1.97 KB
/
ContextProvider.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { SetStateAction, createContext, useState, Dispatch, ReactNode } from 'react'
import IUser from './interfaces/IUser'
interface IPages {
general: {
all: number,
favorites: number,
search: number,
filter: string
},
top_sellers: number
}
interface ISelectedBtn { all: boolean, favorites: boolean }
type authContextType = {
selectedBtn: ISelectedBtn, setSelectedBtn: Dispatch<SetStateAction<ISelectedBtn>>,
visibleModal: boolean, setVisibleModal: Dispatch<SetStateAction<boolean>>,
pages: IPages, setPages: Dispatch<SetStateAction<IPages>>,
title: string, setTitle: Dispatch<SetStateAction<string>>,
searchValue: string, setSearchValue: Dispatch<SetStateAction<string>>,
}
const placeholder_pages: IPages = {
general: {
all: 1,
favorites: 1,
search: 1,
filter: "all"
},
top_sellers: 1
}
const authContextDefaultValues: authContextType = {
selectedBtn: { all: true, favorites: false }, setSelectedBtn: () => { },
visibleModal: false, setVisibleModal: () => { },
pages: placeholder_pages, setPages: () => { },
title: "", setTitle: () => { },
searchValue: "", setSearchValue: () => { }
}
export const AppContext = createContext<authContextType>(authContextDefaultValues)
export const ContextProvider = ({ children }: { children: ReactNode }) => {
const [selectedBtn, setSelectedBtn] = useState({ all: true, favorites: false })
const [pages, setPages] = useState(placeholder_pages)
const [visibleModal, setVisibleModal] = useState(false)
const [title, setTitle] = useState("Todos os produtos")
const [searchValue, setSearchValue] = useState("")
const globalStates = {
pages, setPages,
selectedBtn, setSelectedBtn,
visibleModal, setVisibleModal,
title, setTitle,
searchValue, setSearchValue
}
return (
<AppContext.Provider value={globalStates}>
{children}
</AppContext.Provider>
)
}