Add drag-and-drop from carousel support to alt-text page

This commit is contained in:
DJP 2025-12-10 22:28:34 -05:00
parent 9f8aa022cd
commit e1405d4b6a

View file

@ -7,6 +7,7 @@ import { FileText, Copy, Check, Sparkles, Download, Trash2, RefreshCw } from 'lu
import FileUpload from '@/components/FileUpload';
import { modulesApi, assetsApi, jobsApi } from '@/lib/api';
import { useStore } from '@/lib/store';
import { useDragFromCarousel } from '@/hooks/useDragFromCarousel';
interface QueueItem {
id: string;
@ -69,6 +70,38 @@ export default function AltTextPage() {
}
}, [searchParams, router]);
// Handle drag-and-drop from carousel
useDragFromCarousel({
onAssetDrop: async (assetIds) => {
try {
const responses = await Promise.all(assetIds.map(id => assetsApi.get(id)));
const newItems = responses
.map((r: any) => r.data)
.filter((asset: any) => asset.file_type === 'image')
.map((asset: any) => ({
id: Math.random().toString(36).substring(7),
assetId: asset.id,
filename: asset.original_filename,
status: 'pending' as const
}));
if (newItems.length > 0) {
setQueue(prev => {
const existing = new Set(prev.map(p => p.assetId));
return [...prev, ...newItems.filter(i => !existing.has(i.assetId))];
});
toast.success(`${newItems.length} images added from carousel`);
} else {
toast.error('No valid images in selection');
}
} catch (err) {
console.error('Failed to load dragged assets', err);
toast.error('Failed to add assets');
}
},
enabled: true
});
const handleFileUpload = (files: File[]) => {
const newItems: QueueItem[] = files.map(file => ({
id: Math.random().toString(36).substring(7),