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

64 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-01-12 09:10:59 +01:00
import {
BubbleStep,
BubbleStepType,
ChoiceItem,
InputStep,
InputStepType,
LogicStepType,
LogicStep,
2022-01-12 09:10:59 +01:00
} from 'models'
2021-12-16 10:43:49 +01:00
import {
createContext,
Dispatch,
ReactNode,
SetStateAction,
useContext,
useState,
} from 'react'
export type DraggableStep = BubbleStep | InputStep | LogicStep
export type DraggableStepType = BubbleStepType | InputStepType | LogicStepType
2022-01-08 07:40:55 +01:00
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>>
2022-01-12 09:10:59 +01:00
draggedChoiceItem?: ChoiceItem
setDraggedChoiceItem: Dispatch<SetStateAction<ChoiceItem | undefined>>
mouseOverBlockId?: string
setMouseOverBlockId: Dispatch<SetStateAction<string | undefined>>
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
}>({})
2021-12-16 10:43:49 +01:00
export const DndContext = ({ children }: { children: ReactNode }) => {
2022-01-12 09:10:59 +01:00
const [draggedStep, setDraggedStep] = useState<DraggableStep>()
2022-01-08 07:40:55 +01:00
const [draggedStepType, setDraggedStepType] = useState<
DraggableStepType | undefined
>()
2022-01-12 09:10:59 +01:00
const [draggedChoiceItem, setDraggedChoiceItem] = useState<
ChoiceItem | undefined
>()
const [mouseOverBlockId, setMouseOverBlockId] = useState<string>()
2021-12-16 10:43:49 +01:00
return (
<dndContext.Provider
value={{
draggedStep,
setDraggedStep,
draggedStepType,
setDraggedStepType,
2022-01-12 09:10:59 +01:00
draggedChoiceItem,
setDraggedChoiceItem,
mouseOverBlockId,
setMouseOverBlockId,
2021-12-16 10:43:49 +01:00
}}
>
{children}
</dndContext.Provider>
)
}
export const useDnd = () => useContext(dndContext)