first
This commit is contained in:
55
src/providers/KanbanProvider.tsx
Normal file
55
src/providers/KanbanProvider.tsx
Normal file
@@ -0,0 +1,55 @@
|
||||
import { KanbanBoardItem, kanbanItems } from 'data/kanban';
|
||||
import React, {
|
||||
Dispatch,
|
||||
PropsWithChildren,
|
||||
createContext,
|
||||
useContext,
|
||||
useReducer
|
||||
} from 'react';
|
||||
import { ACTIONTYPE, kanbanReducer } from 'reducers/KanbanReducer';
|
||||
|
||||
export type ConversationFilterType = 'all' | 'read' | 'unread';
|
||||
interface KanbanProviderInterface {}
|
||||
|
||||
export interface KanbanState {
|
||||
openBoardDetailsOffcanvas: boolean;
|
||||
openAddListModal: boolean;
|
||||
boardLists: KanbanBoardItem[];
|
||||
}
|
||||
|
||||
interface KanbanContextInterface extends KanbanState {
|
||||
kanbanDispatch: Dispatch<ACTIONTYPE>;
|
||||
}
|
||||
|
||||
export const KanbanContext = createContext({} as KanbanContextInterface);
|
||||
|
||||
const useKanbanReducer = () => {
|
||||
const initState: KanbanState = {
|
||||
openBoardDetailsOffcanvas: false,
|
||||
openAddListModal: false,
|
||||
boardLists: kanbanItems
|
||||
};
|
||||
|
||||
return useReducer(kanbanReducer, initState);
|
||||
};
|
||||
|
||||
const KanbanProvider = ({
|
||||
children
|
||||
}: PropsWithChildren<KanbanProviderInterface>) => {
|
||||
const [kanbanState, kanbanDispatch] = useKanbanReducer();
|
||||
|
||||
return (
|
||||
<KanbanContext.Provider
|
||||
value={{
|
||||
...kanbanState,
|
||||
kanbanDispatch
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</KanbanContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useKanbanContext = () => useContext(KanbanContext);
|
||||
|
||||
export default KanbanProvider;
|
||||
Reference in New Issue
Block a user