2
0
Files
bot/apps/builder/contexts/DndContext.tsx

45 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-01-08 07:40:55 +01:00
import { BubbleStep, BubbleStepType, InputStep, InputStepType } from 'models'
2021-12-16 10:43:49 +01:00
import {
createContext,
Dispatch,
ReactNode,
SetStateAction,
useContext,
useState,
} from 'react'
2022-01-08 07:40:55 +01:00
export type DraggableStep = BubbleStep | InputStep
export type DraggableStepType = BubbleStepType | InputStepType
2021-12-16 10:43:49 +01:00
const dndContext = createContext<{
2022-01-08 07:40:55 +01:00
draggedStepType?: DraggableStepType
setDraggedStepType: Dispatch<SetStateAction<DraggableStepType | undefined>>
draggedStep?: DraggableStep
setDraggedStep: Dispatch<SetStateAction<DraggableStep | undefined>>
2021-12-16 10:43:49 +01:00
}>({
setDraggedStep: () => console.log("I'm not implemented"),
setDraggedStepType: () => console.log("I'm not implemented"),
})
export const DndContext = ({ children }: { children: ReactNode }) => {
2022-01-08 07:40:55 +01:00
const [draggedStep, setDraggedStep] = useState<DraggableStep | undefined>()
const [draggedStepType, setDraggedStepType] = useState<
DraggableStepType | undefined
>()
2021-12-16 10:43:49 +01:00
return (
<dndContext.Provider
value={{
draggedStep,
setDraggedStep,
draggedStepType,
setDraggedStepType,
}}
>
{children}
</dndContext.Provider>
)
}
export const useDnd = () => useContext(dndContext)