Initial commit
This commit is contained in:
34
src/stores/dragStore.ts
Normal file
34
src/stores/dragStore.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { create } from 'zustand'
|
||||
|
||||
export interface DragState {
|
||||
draggedPath: string | null
|
||||
draggedType: 'file' | 'dir' | null
|
||||
dropTargetPath: string | null
|
||||
}
|
||||
|
||||
interface DragStore {
|
||||
state: DragState
|
||||
setState: (state: DragState) => void
|
||||
isDraggedInsidePath: (checkPath: string) => boolean
|
||||
}
|
||||
|
||||
const initialState: DragState = {
|
||||
draggedPath: null,
|
||||
draggedType: null,
|
||||
dropTargetPath: null
|
||||
}
|
||||
|
||||
export const useDragStore = create<DragStore>((set, get) => ({
|
||||
state: initialState,
|
||||
|
||||
setState: (state) => set({ state }),
|
||||
|
||||
isDraggedInsidePath: (checkPath) => {
|
||||
const { state } = get()
|
||||
if (!state.draggedPath) return false
|
||||
if (state.draggedType === 'dir') {
|
||||
return checkPath.startsWith(`${state.draggedPath}/`)
|
||||
}
|
||||
return false
|
||||
}
|
||||
}))
|
||||
Reference in New Issue
Block a user