-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathindex.jsx
More file actions
91 lines (80 loc) · 2.66 KB
/
index.jsx
File metadata and controls
91 lines (80 loc) · 2.66 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import React from "react";
import PropTypes from "prop-types";
export const MaterialTailwind = React.createContext(null);
MaterialTailwind.displayName = "MaterialTailwindContext";
export function reducer(state, action) {
switch (action.type) {
case "OPEN_SIDENAV": {
return { ...state, openSidenav: action.value };
}
case "SIDENAV_TYPE": {
return { ...state, sidenavType: action.value };
}
case "SIDENAV_COLOR": {
return { ...state, sidenavColor: action.value };
}
case "TRANSPARENT_NAVBAR": {
return { ...state, transparentNavbar: action.value };
}
case "FIXED_NAVBAR": {
return { ...state, fixedNavbar: action.value };
}
case "OPEN_CONFIGURATOR": {
return { ...state, openConfigurator: action.value };
}
case "AUTH_STATUS": {
return { ...state, isAuthenticated: action.value}
}
default: {
throw new Error(`Unhandled action type: ${action.type}`);
}
}
}
export function MaterialTailwindControllerProvider({ children }) {
const initialState = {
openSidenav: false,
sidenavColor: "blue-gray",
sidenavType: "white",
transparentNavbar: true,
fixedNavbar: false,
openConfigurator: false,
isAuthenticated: Boolean(localStorage.getItem("token")),
};
const [controller, dispatch] = React.useReducer(reducer, initialState);
const value = React.useMemo(
() => [controller, dispatch],
[controller, dispatch]
);
return (
<MaterialTailwind.Provider value={value}>
{children}
</MaterialTailwind.Provider>
);
}
export function useMaterialTailwindController() {
const context = React.useContext(MaterialTailwind);
if (!context) {
throw new Error(
"useMaterialTailwindController should be used inside the MaterialTailwindControllerProvider."
);
}
return context;
}
MaterialTailwindControllerProvider.displayName = "/src/context/index.jsx";
MaterialTailwindControllerProvider.propTypes = {
children: PropTypes.node.isRequired,
};
export const setOpenSidenav = (dispatch, value) =>
dispatch({ type: "OPEN_SIDENAV", value });
export const setSidenavType = (dispatch, value) =>
dispatch({ type: "SIDENAV_TYPE", value });
export const setSidenavColor = (dispatch, value) =>
dispatch({ type: "SIDENAV_COLOR", value });
export const setTransparentNavbar = (dispatch, value) =>
dispatch({ type: "TRANSPARENT_NAVBAR", value });
export const setFixedNavbar = (dispatch, value) =>
dispatch({ type: "FIXED_NAVBAR", value });
export const setOpenConfigurator = (dispatch, value) =>
dispatch({ type: "OPEN_CONFIGURATOR", value });
export const setAuthStatus = (dispatch, value) =>
dispatch({type: "AUTH_STATUS", value})