-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
35 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,50 @@ | ||
'use client' | ||
|
||
import { createContext, useContext, useReducer, useState } from 'react' | ||
import { ThemeAction, ThemeActionType, ThemeContextProps, ThemeState, ToastState } from '../types' | ||
import { createContext, useContext, useState } from 'react' | ||
import { | ||
ThemeAction, | ||
ThemeActionType, | ||
ThemeContextProps, | ||
ThemeState, | ||
} from '../types' | ||
import { PropsWithChildren } from 'react' | ||
import ToastProvider from './ToastContext' | ||
import Layout from '../views/Layout' | ||
import AuthProvider from '@/pkg/auth/context/AuthContext' | ||
import ReactQueryProvider from './ReactQueryContext' | ||
import LoadingOverlay from '../views/LoadingOverlay' | ||
|
||
function themeReducer(state: ThemeState, action: ThemeAction){ | ||
const {type, payload} = action | ||
function themeReducer(state: ThemeState, action: ThemeAction) { | ||
const { type, payload } = action | ||
|
||
switch(type){ | ||
switch (type) { | ||
case ThemeActionType.Loading: | ||
return { | ||
...state, | ||
...payload | ||
...payload, | ||
} | ||
default: | ||
throw new Error('Unknown theme action type: '+type) | ||
throw new Error('Unknown theme action type: ' + type) | ||
} | ||
} | ||
|
||
const ThemeContext = createContext<ThemeContextProps|undefined>(undefined) | ||
export default function ThemeProvider({children}: PropsWithChildren) { | ||
const ThemeContext = createContext<ThemeContextProps | undefined>(undefined) | ||
export default function ThemeProvider({ children }: PropsWithChildren) { | ||
const [loading, setLoading] = useState(false) | ||
return ( | ||
<ThemeContext.Provider value={{ | ||
loading, | ||
setLoading | ||
}}> | ||
<ThemeContext.Provider | ||
value={{ | ||
loading, | ||
setLoading, | ||
}}> | ||
{children} | ||
<LoadingOverlay loading={loading}/> | ||
<LoadingOverlay loading={loading} /> | ||
</ThemeContext.Provider> | ||
) | ||
} | ||
|
||
export function useThemeContext(): ThemeContextProps { | ||
const context = useContext(ThemeContext) as ThemeContextProps | undefined | ||
|
||
if(!context){ | ||
throw Error( | ||
'useThemeContext should be used within ThemeProvider' | ||
) | ||
if (!context) { | ||
throw Error('useThemeContext should be used within ThemeProvider') | ||
} | ||
|
||
return context | ||
} | ||
|