mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-02 05:54:44 +00:00
fix(webui): clear external drag state synchronously on folder drops
This commit is contained in:
@@ -2,46 +2,49 @@
|
|||||||
import { client } from '@/ui/api/client'
|
import { client } from '@/ui/api/client'
|
||||||
import type { InferRequestType, InferResponseType } from 'hono/client'
|
import type { InferRequestType, InferResponseType } from 'hono/client'
|
||||||
|
|
||||||
import type { AssetInfo } from '@shumai/dtos'
|
|
||||||
import type { CollectionInfo } from '@shumai/dtos'
|
|
||||||
import type { SearchCondition, SearchSort } from '@shumai/dtos'
|
|
||||||
import type { ShareLinkInfo } from '@shumai/dtos'
|
|
||||||
import type { CreateUploadTaskRequest } from '@shumai/dtos'
|
|
||||||
import { formatSize } from '@/ui/lib/format'
|
|
||||||
import { ulid } from 'ulid'
|
|
||||||
import { usePermissions } from '@/ui/hooks/use-permissions'
|
import { usePermissions } from '@/ui/hooks/use-permissions'
|
||||||
|
import { getAllFilesFromEntries } from '@/ui/lib/dnd-utils'
|
||||||
|
import { formatSize } from '@/ui/lib/format'
|
||||||
import { useFieldStore } from '@/ui/stores/fields'
|
import { useFieldStore } from '@/ui/stores/fields'
|
||||||
import { useUploadStore } from '@/ui/stores/upload'
|
import { useUploadStore } from '@/ui/stores/upload'
|
||||||
|
import type {
|
||||||
|
AssetInfo,
|
||||||
|
CollectionInfo,
|
||||||
|
CreateUploadTaskRequest,
|
||||||
|
SearchCondition,
|
||||||
|
SearchSort,
|
||||||
|
ShareLinkInfo,
|
||||||
|
} from '@shumai/dtos'
|
||||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||||
import { useNavigate } from '@tanstack/react-router'
|
import { useNavigate } from '@tanstack/react-router'
|
||||||
import { Download, AlertTriangle, Loader2, UploadCloud } from 'lucide-react'
|
import { AlertTriangle, Download, Loader2 } from 'lucide-react'
|
||||||
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||||
import { getAllFilesFromEntries } from '@/ui/lib/dnd-utils'
|
|
||||||
import { toast } from 'sonner'
|
import { toast } from 'sonner'
|
||||||
|
import { ulid } from 'ulid'
|
||||||
import type { DragState } from '../dnd-types'
|
import type { DragState } from '../dnd-types'
|
||||||
import { MoveCopyDialog } from '../move-copy-dialog'
|
import { MoveCopyDialog } from '../move-copy-dialog'
|
||||||
import { FileBrowserContextMenu } from './context-menu'
|
import { FileBrowserContextMenu } from './context-menu'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
AlertDialog,
|
AlertDialog,
|
||||||
AlertDialogAction,
|
AlertDialogAction,
|
||||||
AlertDialogCancel,
|
AlertDialogCancel,
|
||||||
AlertDialogContent,
|
AlertDialogContent,
|
||||||
AlertDialogDescription,
|
AlertDialogDescription,
|
||||||
AlertDialogFooter,
|
AlertDialogFooter,
|
||||||
AlertDialogHeader,
|
AlertDialogHeader,
|
||||||
AlertDialogTitle,
|
AlertDialogTitle,
|
||||||
} from '../ui/alert-dialog'
|
} from '../ui/alert-dialog'
|
||||||
import {
|
|
||||||
Dialog,
|
|
||||||
DialogContent,
|
|
||||||
DialogDescription,
|
|
||||||
DialogFooter,
|
|
||||||
DialogHeader,
|
|
||||||
DialogTitle,
|
|
||||||
} from '../ui/dialog'
|
|
||||||
import { Button } from '../ui/button'
|
import { Button } from '../ui/button'
|
||||||
import { ContextMenu, ContextMenuTrigger } from '../ui/context-menu'
|
import { ContextMenu, ContextMenuTrigger } from '../ui/context-menu'
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from '../ui/dialog'
|
||||||
import { FileCard } from './file-card'
|
import { FileCard } from './file-card'
|
||||||
import { FileListItem } from './file-list-item'
|
import { FileListItem } from './file-list-item'
|
||||||
import { FolderCard } from './folder-card'
|
import { FolderCard } from './folder-card'
|
||||||
@@ -143,6 +146,12 @@ export function FileBrowser({
|
|||||||
const [externalOverFolderId, setExternalOverFolderId] = useState<string | null>(null)
|
const [externalOverFolderId, setExternalOverFolderId] = useState<string | null>(null)
|
||||||
const dragCounter = useRef(0)
|
const dragCounter = useRef(0)
|
||||||
|
|
||||||
|
const resetExternalDragState = useCallback(() => {
|
||||||
|
setIsExternalDragging(false)
|
||||||
|
setExternalOverFolderId(null)
|
||||||
|
dragCounter.current = 0
|
||||||
|
}, [])
|
||||||
|
|
||||||
// Prevent default window behavior to avoid browser replacing page on accidental drops
|
// Prevent default window behavior to avoid browser replacing page on accidental drops
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const preventDefault = (e: DragEvent) => {
|
const preventDefault = (e: DragEvent) => {
|
||||||
@@ -190,9 +199,7 @@ export function FileBrowser({
|
|||||||
|
|
||||||
const files = await getAllFilesFromEntries(e.dataTransfer)
|
const files = await getAllFilesFromEntries(e.dataTransfer)
|
||||||
|
|
||||||
setIsExternalDragging(false)
|
resetExternalDragState()
|
||||||
setExternalOverFolderId(null)
|
|
||||||
dragCounter.current = 0
|
|
||||||
|
|
||||||
if (files.length > 0) {
|
if (files.length > 0) {
|
||||||
processAndUploadFiles(files)
|
processAndUploadFiles(files)
|
||||||
@@ -614,6 +621,7 @@ export function FileBrowser({
|
|||||||
isExternalDragging,
|
isExternalDragging,
|
||||||
externalOverFolderId,
|
externalOverFolderId,
|
||||||
setExternalOverFolderId,
|
setExternalOverFolderId,
|
||||||
|
resetExternalDragState,
|
||||||
onExternalDrop: (files: File[], folderId: string) => {
|
onExternalDrop: (files: File[], folderId: string) => {
|
||||||
processAndUploadFiles(files, folderId)
|
processAndUploadFiles(files, folderId)
|
||||||
},
|
},
|
||||||
@@ -960,6 +968,7 @@ export function FileBrowser({
|
|||||||
isExternalDragging={isExternalDragging}
|
isExternalDragging={isExternalDragging}
|
||||||
externalOverFolderId={externalOverFolderId}
|
externalOverFolderId={externalOverFolderId}
|
||||||
setExternalOverFolderId={setExternalOverFolderId}
|
setExternalOverFolderId={setExternalOverFolderId}
|
||||||
|
resetExternalDragState={resetExternalDragState}
|
||||||
onExternalDrop={(files, folderId) => processAndUploadFiles(files, folderId)}
|
onExternalDrop={(files, folderId) => processAndUploadFiles(files, folderId)}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
@@ -1047,11 +1056,8 @@ export function FileBrowser({
|
|||||||
)}
|
)}
|
||||||
{isExternalDragging && !externalOverFolderId && (
|
{isExternalDragging && !externalOverFolderId && (
|
||||||
<div className="absolute bottom-6 left-1/2 -translate-x-1/2 z-50 pointer-events-none animate-in fade-in slide-in-from-bottom-4 duration-300">
|
<div className="absolute bottom-6 left-1/2 -translate-x-1/2 z-50 pointer-events-none animate-in fade-in slide-in-from-bottom-4 duration-300">
|
||||||
<div className="flex items-center gap-3 px-6 py-3 rounded-full bg-primary text-primary-foreground shadow-lg shadow-primary/20 border border-primary/20 backdrop-blur-md">
|
<div className="flex items-center gap-3 px-6 py-3 rounded-full bg-primary/80 text-primary-foreground shadow-lg shadow-primary/20 border border-primary/20 backdrop-blur-md">
|
||||||
<UploadCloud className="h-5 w-5 animate-bounce" />
|
<span className="font-medium text-sm">Drop files here to upload</span>
|
||||||
<span className="font-medium text-sm">
|
|
||||||
Drop here to upload files to the current folder
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ interface FolderCardProps {
|
|||||||
isExternalDragging?: boolean
|
isExternalDragging?: boolean
|
||||||
externalOverFolderId?: string | null
|
externalOverFolderId?: string | null
|
||||||
setExternalOverFolderId?: (id: string | null) => void
|
setExternalOverFolderId?: (id: string | null) => void
|
||||||
|
resetExternalDragState?: () => void
|
||||||
onExternalDrop?: (files: File[], folderId: string) => void
|
onExternalDrop?: (files: File[], folderId: string) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,6 +123,7 @@ export function FolderCard({
|
|||||||
isExternalDragging,
|
isExternalDragging,
|
||||||
externalOverFolderId,
|
externalOverFolderId,
|
||||||
setExternalOverFolderId,
|
setExternalOverFolderId,
|
||||||
|
resetExternalDragState,
|
||||||
onExternalDrop,
|
onExternalDrop,
|
||||||
}: FolderCardProps) {
|
}: FolderCardProps) {
|
||||||
const [name, setName] = useState(item.name || '')
|
const [name, setName] = useState(item.name || '')
|
||||||
@@ -262,7 +264,7 @@ export function FolderCard({
|
|||||||
? async (e) => {
|
? async (e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
setExternalOverFolderId?.(null)
|
resetExternalDragState?.()
|
||||||
const files = await getAllFilesFromEntries(e.dataTransfer)
|
const files = await getAllFilesFromEntries(e.dataTransfer)
|
||||||
onExternalDrop?.(files, item.id!)
|
onExternalDrop?.(files, item.id!)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ interface ListRowProps {
|
|||||||
isExternalDragging?: boolean
|
isExternalDragging?: boolean
|
||||||
externalOverFolderId?: string | null
|
externalOverFolderId?: string | null
|
||||||
setExternalOverFolderId?: (id: string | null) => void
|
setExternalOverFolderId?: (id: string | null) => void
|
||||||
|
resetExternalDragState?: () => void
|
||||||
onExternalDrop?: (files: File[], folderId: string) => void
|
onExternalDrop?: (files: File[], folderId: string) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,6 +43,7 @@ function ListRow({
|
|||||||
isExternalDragging,
|
isExternalDragging,
|
||||||
externalOverFolderId,
|
externalOverFolderId,
|
||||||
setExternalOverFolderId,
|
setExternalOverFolderId,
|
||||||
|
resetExternalDragState,
|
||||||
onExternalDrop,
|
onExternalDrop,
|
||||||
}: ListRowProps) {
|
}: ListRowProps) {
|
||||||
const isDraggingItem = dragState?.draggedIds.has(item.id!)
|
const isDraggingItem = dragState?.draggedIds.has(item.id!)
|
||||||
@@ -130,7 +132,7 @@ function ListRow({
|
|||||||
? async (e) => {
|
? async (e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
setExternalOverFolderId?.(null)
|
resetExternalDragState?.()
|
||||||
const files = await getAllFilesFromEntries(e.dataTransfer)
|
const files = await getAllFilesFromEntries(e.dataTransfer)
|
||||||
onExternalDrop?.(files, item.id!)
|
onExternalDrop?.(files, item.id!)
|
||||||
}
|
}
|
||||||
@@ -193,6 +195,7 @@ interface FileBrowserListViewProps {
|
|||||||
isExternalDragging?: boolean
|
isExternalDragging?: boolean
|
||||||
externalOverFolderId?: string | null
|
externalOverFolderId?: string | null
|
||||||
setExternalOverFolderId?: (id: string | null) => void
|
setExternalOverFolderId?: (id: string | null) => void
|
||||||
|
resetExternalDragState?: () => void
|
||||||
onExternalDrop?: (files: File[], folderId: string) => void
|
onExternalDrop?: (files: File[], folderId: string) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,6 +228,7 @@ export function FileBrowserListView({
|
|||||||
isExternalDragging,
|
isExternalDragging,
|
||||||
externalOverFolderId,
|
externalOverFolderId,
|
||||||
setExternalOverFolderId,
|
setExternalOverFolderId,
|
||||||
|
resetExternalDragState,
|
||||||
onExternalDrop,
|
onExternalDrop,
|
||||||
}: FileBrowserListViewProps) {
|
}: FileBrowserListViewProps) {
|
||||||
const [columnSizing, setColumnSizing] = useState<Record<string, number>>({})
|
const [columnSizing, setColumnSizing] = useState<Record<string, number>>({})
|
||||||
@@ -514,6 +518,7 @@ export function FileBrowserListView({
|
|||||||
isExternalDragging={isExternalDragging}
|
isExternalDragging={isExternalDragging}
|
||||||
externalOverFolderId={externalOverFolderId}
|
externalOverFolderId={externalOverFolderId}
|
||||||
setExternalOverFolderId={setExternalOverFolderId}
|
setExternalOverFolderId={setExternalOverFolderId}
|
||||||
|
resetExternalDragState={resetExternalDragState}
|
||||||
onExternalDrop={onExternalDrop}
|
onExternalDrop={onExternalDrop}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user