veza/apps/web/src/components/upload/FilePreviewCard.tsx

107 lines
3.1 KiB
TypeScript
Raw Normal View History

import React from 'react';
import { Card } from '../ui/card';
import { UploadProgressBar } from './UploadProgressBar';
import {
FileAudio,
FileImage,
FolderArchive,
File,
CheckCircle,
AlertCircle,
} from 'lucide-react';
export interface UploadFile {
id: string;
file: File;
progress: number;
status: 'uploading' | 'paused' | 'completed' | 'error' | 'processing';
previewUrl?: string;
}
interface FilePreviewCardProps {
fileData: UploadFile;
onPause: () => void;
onResume: () => void;
onCancel: () => void;
}
export const FilePreviewCard: React.FC<FilePreviewCardProps> = ({
fileData,
onPause,
onResume,
onCancel,
}) => {
const { file, progress, status, previewUrl } = fileData;
const formatSize = (bytes: number) => {
if (bytes === 0) return '0 B';
const k = 1024;
const sizes = ['B', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(2))} ${sizes[i]}`;
};
const getIcon = () => {
if (file.type.startsWith('image/'))
return <FileImage className="w-6 h-6 text-kodo-magenta" />;
if (file.type.startsWith('audio/'))
aesthetic-improvements: reduce decorative cyan across multiple component categories (80/20 rule, batch 11) - Social: FeedView, ConnectionsView, GroupsView, ExploreView, GroupDetailView loading spinners and decorative text, CreatePostModal decorative select text and hashtag links, PostCard decorative tag links and waveform bars and view comments link, CreateGroupModal decorative icon (9 instances) - Settings: DataExportModal decorative icon, LoginHistory decorative IP text, AppearanceSettingsView decorative icon and selected theme checkmark, BackupsView decorative icon, CloudIntegrationView decorative icon, AccessibilitySettingsView decorative icon, SecuritySettings decorative icon, PasskeyModal decorative icon and loading spinner (8 instances) - Studio: ProjectsManager loading spinner and progress percentage text, CloudFileBrowser decorative music icons, AIToolsView decorative music icon, ConnectivityView decorative icon, CreateProjectModal decorative icon, CloudSettingsView decorative icon (6 instances) - Admin: AdminDashboardView loading spinner and decorative chart bars and icon, AdminSettingsView decorative icon, AdminModerationView loading spinner, AdminUsersView loading spinner (5 instances) - Inventory: InventoryView loading spinner, EquipmentCard decorative price icon, EquipmentDetailView loading spinner and decorative icons and price text, AddEquipmentView decorative icon (5 instances) - Seller: CreateProductView decorative icon, SellerDashboardView loading spinner and decorative icon and sales text (3 instances) - Live: LiveStreamDetailView decorative streamer name text (1 instance) - Developer: DeveloperDashboardView loading spinner, WebhooksView decorative icon (2 instances) - Upload: BulkUploadModal decorative icon, FilePreviewCard decorative audio file icon, MetadataForm decorative button text, CoverArtUploadModal decorative icon, LyricsEditorModal decorative icon (5 instances) - Notifications: NotificationItem decorative follow icon and mark as read button, NotificationBell decorative mark all read link (3 instances) - Total: ~46 files, ~46 instances replaced - Preserved: Active/selected states (CloudFileBrowser selected files checkmarks, CreatePostModal post type active state, GroupCard/GroupDetailView public/private badges - semantic indicators, DataExportModal checkbox accents - focus/interaction, AppearanceSettingsView selected theme - active state, PasskeyModal checkbox accent - focus/interaction, LyricsEditorModal checkbox accent - focus/interaction, FileUploadZone drag active state - active state, EquipmentDetailView support link - functional link, FlashSaleModal link - functional link, EquipmentDetailView image indicator dots - active state), primary actions, design system variants - Action 11.3.1.3 in progress (eleventh batch: social, settings, studio, admin, inventory, seller, live, developer, upload, notifications components)
2026-01-16 10:26:33 +00:00
return <FileAudio className="w-6 h-6 text-kodo-steel" />;
if (file.type.includes('zip') || file.type.includes('compressed'))
return <FolderArchive className="w-6 h-6 text-kodo-gold" />;
return <File className="w-6 h-6 text-kodo-content-dim" />;
};
return (
<Card
variant="glass"
className="p-4 flex items-center gap-4 border-l-4 border-l-kodo-slate hover:border-l-kodo-cyan transition-all"
>
{/* Thumbnail / Icon */}
<div className="w-12 h-12 rounded-lg bg-black/40 flex items-center justify-center overflow-hidden flex-shrink-0 border border-white/5">
{previewUrl && file.type.startsWith('image/') ? (
<img
src={previewUrl}
alt="Preview"
className="w-full h-full object-cover"
/>
) : (
getIcon()
)}
</div>
{/* Info & Progress */}
<div className="flex-1 min-w-0">
<div className="flex justify-between items-start mb-1">
<h4
className="font-bold text-white text-sm truncate pr-2"
title={file.name}
>
{file.name}
</h4>
<span className="text-[10px] text-kodo-content-dim font-mono flex-shrink-0">
{formatSize(file.size)}
</span>
</div>
{status === 'completed' ? (
<div className="flex items-center gap-2 text-xs text-kodo-lime font-bold">
<CheckCircle className="w-3 h-3" /> Ready
</div>
) : status === 'error' ? (
<div className="flex items-center gap-2 text-xs text-kodo-red font-bold">
<AlertCircle className="w-3 h-3" /> Failed
</div>
) : (
<UploadProgressBar
progress={progress}
status={status}
onPause={onPause}
onResume={onResume}
onCancel={onCancel}
/>
)}
</div>
</Card>
);
};