fix(ui): resolve upload error mapping and completeness race condition

This commit is contained in:
yiling
2026-06-03 15:23:10 +08:00
parent 5a19986c92
commit eba4801dc7
3 changed files with 30 additions and 7 deletions
@@ -361,13 +361,14 @@ export function FileBrowser({
const urlInfo = (
data.presignedUrls as { id?: string; url?: string; fileId?: string }[] | undefined
)?.find((p) => p.id === f.id)
const hasUrl = !!urlInfo && !!urlInfo.url
return {
id: urlInfo?.fileId || f.id,
name: f.file.name,
sizeByte: f.file.size,
fileCount: 0,
type: 'file',
status: 'uploading',
status: hasUrl ? 'uploading' : 'error',
mediaType: f.file.type || null,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
@@ -606,10 +607,12 @@ export function FileBrowser({
}
} finally {
decrementUploading()
setLocalUploadingFiles((prev) => prev.filter((f) => f.id !== uploadInfo.fileId))
queryClient.invalidateQueries({
await queryClient.invalidateQueries({
queryKey: ['search', teamId, assetId],
})
setLocalUploadingFiles((prev) =>
prev.filter((f) => f.id !== uploadInfo.fileId && f.id !== file.id),
)
}
}
}
@@ -238,11 +238,25 @@ export function FileCard({
<div className="relative aspect-square overflow-hidden bg-muted/30">
{displayItem.status === 'uploading' ||
displayItem.status === 'processing' ||
displayItem.status === 'uploaded' ? (
displayItem.status === 'uploaded' ||
displayItem.status === 'error' ? (
<div className="flex h-full w-full items-center justify-center bg-background/50">
<Skeleton className="absolute inset-0 h-full w-full" />
<span className="z-10 font-medium capitalize text-muted-foreground">
{displayItem.status === 'uploaded' ? 'Processing' : displayItem.status}
{displayItem.status !== 'error' && (
<Skeleton className="absolute inset-0 h-full w-full" />
)}
<span
className={cn(
'z-10 font-medium px-2 text-center text-sm',
displayItem.status === 'error'
? 'text-destructive font-semibold'
: 'text-muted-foreground capitalize',
)}
>
{displayItem.status === 'uploaded'
? 'Processing'
: displayItem.status === 'error'
? 'Failed to upload'
: displayItem.status}
</span>
</div>
) : (
@@ -216,6 +216,12 @@ export function FileListItem({
disabled={!isEditing}
className="h-auto p-0 text-sm font-medium text-foreground truncate"
/>
{displayItem.status === 'error' && (
<span className="text-xs text-destructive font-semibold shrink-0">
(Failed to upload)
</span>
)}
{displayItem.versionStack && (
<Badge variant="outline" className="px-1 py-0 text-xs shrink-0">
v