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

53 lines
1.5 KiB
TypeScript
Raw Normal View History

import { ChoiceItem, DraggableStep, DraggableStepType } from 'models'
2021-12-16 10:43:49 +01:00
import {
createContext,
Dispatch,
ReactNode,
SetStateAction,
useContext,
useState,
} from 'react'
const stepDndContext = 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 StepDndContext = ({ 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 (
<stepDndContext.Provider
2021-12-16 10:43:49 +01:00
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}
</stepDndContext.Provider>
2021-12-16 10:43:49 +01:00
)
}
export const useStepDnd = () => useContext(stepDndContext)