Files
XCDesktop/src/stores/dragStore.ts
2026-03-08 01:34:54 +08:00

35 lines
772 B
TypeScript

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
}
}))