feat: scaffold complete danable frontend architecture with all pages, layouts, stores, and 3 annotator modes

This commit is contained in:
quanganh2k4 2026-10-30 00:33:07 +07:00
commit 78848dd7d1
173 changed files with 18649 additions and 0 deletions

View file

@ -0,0 +1,216 @@
import React, { useState, useRef } from 'react'
import { ImageItem, Project } from '@/types'
import { ImageTable } from './ImageTable'
interface DataTabProps {
project: Project
images: ImageItem[]
onUploadImages: (fileNames: string[]) => void
}
interface DatasetBatch {
id: string
batchName: string
uploadedBy: string
uploadedAt: string
imageCount: number
status: 'Đã phân công' | 'Đang gán nhãn' | 'Hoàn thành'
}
export const DataTab: React.FC<DataTabProps> = ({
project,
images,
onUploadImages,
}) => {
const fileInputRef = useRef<HTMLInputElement | null>(null)
const [isDragging, setIsDragging] = useState(false)
const [batches, setBatches] = useState<DatasetBatch[]>([
{
id: 'batch-03',
batchName: 'batch_2026_10_morning_cam04',
uploadedBy: 'Minh Anh',
uploadedAt: 'Hôm nay, 08:30',
imageCount: 320,
status: 'Đang gán nhãn',
},
{
id: 'batch-02',
batchName: 'batch_2026_10_intersection_02',
uploadedBy: 'Minh Anh',
uploadedAt: 'Hôm qua, 16:15',
imageCount: 480,
status: 'Đang gán nhãn',
},
{
id: 'batch-01',
batchName: 'batch_2026_09_initial_seed',
uploadedBy: 'Thu Hà',
uploadedAt: '5 ngày trước',
imageCount: 480,
status: 'Hoàn thành',
},
])
const handleFilesSelected = (files: FileList | null) => {
if (!files || files.length === 0) return
const names = Array.from(files).map((f) => f.name)
onUploadImages(names)
setBatches((prev) => [
{
id: `batch-${Date.now()}`,
batchName: `upload_batch_${new Date().toISOString().slice(0, 10).replace(/-/g, '_')}`,
uploadedBy: 'Minh Anh',
uploadedAt: 'Vừa tải lên',
imageCount: names.length,
status: 'Đã phân công',
},
...prev,
])
}
const handleSimulatedSampleUpload = () => {
const sampleNames = [
`traffic_${String(327 + images.length).padStart(5, '0')}.jpg`,
`traffic_${String(328 + images.length).padStart(5, '0')}.jpg`,
`traffic_${String(329 + images.length).padStart(5, '0')}.jpg`,
]
onUploadImages(sampleNames)
setBatches((prev) => [
{
id: `batch-${Date.now()}`,
batchName: `camera_import_${batches.length + 1}`,
uploadedBy: 'Minh Anh',
uploadedAt: 'Vừa tải lên',
imageCount: sampleNames.length,
status: 'Đã phân công',
},
...prev,
])
}
return (
<div className="space-y-5">
{/* Upload Dropzone */}
<div
onDragOver={(e) => {
e.preventDefault()
setIsDragging(true)
}}
onDragLeave={() => setIsDragging(false)}
onDrop={(e) => {
e.preventDefault()
setIsDragging(false)
handleFilesSelected(e.dataTransfer.files)
}}
className={`flex flex-col items-center justify-center rounded-2xl border-2 border-dashed p-8 text-center transition ${
isDragging
? 'border-[#C95C3C] bg-[#FDF4F1]'
: 'border-slate-300 bg-white hover:border-slate-400'
}`}
>
<input
ref={fileInputRef}
type="file"
accept="image/*"
multiple
className="hidden"
onChange={(e) => handleFilesSelected(e.target.files)}
/>
<div className="flex h-12 w-12 items-center justify-center rounded-2xl bg-[#FDF4F1] text-[#C95C3C]">
<svg
className="h-6 w-6"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={2}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M4 16v2a2 2 0 002 2h12a2 2 0 002-2v-2M16 8l-4-4m0 0L8 8m4-4v12"
/>
</svg>
</div>
<h3 className="mt-3 text-sm font-bold text-slate-900">
Kéo thả ảnh hoặc thư mục dữ liệu vào đây
</h3>
<p className="mt-1 text-xs text-slate-500">
Hỗ trợ định dạng JPG, PNG, WEBP tối đa 25MB/ảnh cho dự án{' '}
<span className="font-mono font-semibold text-slate-700">{project.slug}</span>
</p>
<div className="mt-4 flex flex-wrap items-center gap-3">
<button
type="button"
onClick={() => fileInputRef.current?.click()}
className="rounded-xl bg-[#C95C3C] px-4 py-2 text-xs font-semibold text-white shadow-sm transition hover:bg-[#B5492B]"
>
Chọn tệp từ máy tính
</button>
<button
type="button"
onClick={handleSimulatedSampleUpload}
className="rounded-xl border border-slate-200 bg-white px-4 py-2 text-xs font-semibold text-slate-700 transition hover:bg-slate-50"
>
+ Nhập nhanh 3 ảnh mẫu
</button>
</div>
</div>
{/* Dataset Batches Table */}
<div className="rounded-2xl border border-slate-200/80 bg-white p-5 shadow-[0_1px_2px_rgba(15,23,42,0.03)]">
<div className="flex items-center justify-between">
<div>
<h3 className="text-base font-bold text-slate-900">Lô dữ liệu đã tải lên</h3>
<p className="mt-0.5 text-xs text-slate-500">
Quản lý các đợt nhập ảnh vào dự án và trạng thái phân công
</p>
</div>
<span className="rounded-lg bg-slate-100 px-2.5 py-1 text-xs font-semibold text-slate-700">
{batches.length} lô dữ liệu
</span>
</div>
<div className="mt-4 divide-y divide-slate-100">
{batches.map((batch) => (
<div
key={batch.id}
className="flex flex-wrap items-center justify-between gap-3 py-3 text-xs"
>
<div>
<p className="font-mono font-semibold text-slate-900">{batch.batchName}</p>
<p className="mt-0.5 text-slate-400">
Tải lên bởi {batch.uploadedBy} · {batch.uploadedAt}
</p>
</div>
<div className="flex items-center gap-4">
<span className="font-semibold text-slate-700">
{batch.imageCount.toLocaleString('vi-VN')} ảnh
</span>
<span
className={`rounded-full px-2.5 py-0.5 font-semibold ${
batch.status === 'Hoàn thành'
? 'bg-emerald-50 text-emerald-700'
: batch.status === 'Đang gán nhãn'
? 'bg-amber-50 text-amber-700'
: 'bg-indigo-50 text-indigo-700'
}`}
>
{batch.status}
</span>
</div>
</div>
))}
</div>
</div>
{/* Full Image Table */}
<ImageTable
projectId={project.id}
projectSlug={project.slug}
images={images}
stats={project.stats}
classes={project.classes}
/>
</div>
)
}