feat: scaffold complete danable frontend architecture with all pages, layouts, stores, and 3 annotator modes
This commit is contained in:
commit
78848dd7d1
173 changed files with 18649 additions and 0 deletions
14
src/App.tsx
Normal file
14
src/App.tsx
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import React from 'react'
|
||||
import { AppProviders } from '@/app/providers'
|
||||
import { AppRouter } from '@/app/router'
|
||||
|
||||
export const App: React.FC = () => {
|
||||
return (
|
||||
<AppProviders>
|
||||
<AppRouter />
|
||||
</AppProviders>
|
||||
)
|
||||
}
|
||||
|
||||
export default App
|
||||
|
||||
61
src/app/constants.ts
Normal file
61
src/app/constants.ts
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
import { ImageAnnotationStatus, ProjectStatus, TaskType, UserRole, UserStatus } from '@/types'
|
||||
|
||||
export const APP_NAME = 'danable'
|
||||
export const APP_TAGLINE = 'Nền tảng gán nhãn dữ liệu thị giác máy tính'
|
||||
|
||||
export const API_BASE_URL = import.meta.env.VITE_API_URL || 'http://localhost:8000/api/v1'
|
||||
export const USE_MOCK_DATA = import.meta.env.VITE_USE_MOCK_DATA !== 'false'
|
||||
|
||||
export const STORAGE_KEYS = {
|
||||
ACCESS_TOKEN: 'danable_access_token',
|
||||
REFRESH_TOKEN: 'danable_refresh_token',
|
||||
CURRENT_USER: 'danable_current_user',
|
||||
MOCK_DB: 'danable_mock_db_v1',
|
||||
THEME: 'danable_theme',
|
||||
} as const
|
||||
|
||||
export const ROLE_LABELS: Record<UserRole, string> = {
|
||||
admin: 'Admin',
|
||||
manager: 'Manager',
|
||||
annotator: 'Annotator',
|
||||
reviewer: 'Reviewer',
|
||||
}
|
||||
|
||||
export const ROLE_VI_LABELS: Record<UserRole, string> = {
|
||||
admin: 'Quản trị viên (Admin)',
|
||||
manager: 'Quản lý dự án (Manager)',
|
||||
annotator: 'Người gán nhãn (Annotator)',
|
||||
reviewer: 'Người kiểm duyệt (Reviewer)',
|
||||
}
|
||||
|
||||
export const USER_STATUS_LABELS: Record<UserStatus, string> = {
|
||||
active: 'Đang hoạt động',
|
||||
invited: 'Đã gửi lời mời',
|
||||
suspended: 'Tạm khóa',
|
||||
}
|
||||
|
||||
export const TASK_TYPE_LABELS: Record<TaskType, string> = {
|
||||
classification: 'Classification',
|
||||
object_detection: 'Object Detection',
|
||||
segmentation: 'Segmentation',
|
||||
}
|
||||
|
||||
export const TASK_TYPE_VI_LABELS: Record<TaskType, string> = {
|
||||
classification: 'Phân loại ảnh (Classification)',
|
||||
object_detection: 'Phát hiện vật thể (Object Detection)',
|
||||
segmentation: 'Phân vùng ảnh (Segmentation)',
|
||||
}
|
||||
|
||||
export const PROJECT_STATUS_LABELS: Record<ProjectStatus, string> = {
|
||||
annotating: 'Đang gán nhãn',
|
||||
pending_review: 'Chờ duyệt',
|
||||
completed: 'Hoàn thành',
|
||||
draft: 'Bản nháp',
|
||||
}
|
||||
|
||||
export const IMAGE_STATUS_LABELS: Record<ImageAnnotationStatus, string> = {
|
||||
unassigned: 'Chưa gán',
|
||||
in_progress: 'Đang làm',
|
||||
pending_review: 'Chờ duyệt',
|
||||
completed: 'Hoàn thành',
|
||||
}
|
||||
39
src/app/providers.tsx
Normal file
39
src/app/providers.tsx
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import React from 'react'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { Toaster } from 'react-hot-toast'
|
||||
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
staleTime: 1000 * 60 * 5,
|
||||
refetchOnWindowFocus: false,
|
||||
retry: 1,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
interface AppProvidersProps {
|
||||
children: React.ReactNode
|
||||
}
|
||||
|
||||
export const AppProviders: React.FC<AppProvidersProps> = ({ children }) => {
|
||||
return (
|
||||
<QueryClientProvider client={queryClient}>
|
||||
{children}
|
||||
<Toaster
|
||||
position="bottom-right"
|
||||
toastOptions={{
|
||||
duration: 2800,
|
||||
style: {
|
||||
background: '#1e293b',
|
||||
color: '#f8fafc',
|
||||
fontSize: '13px',
|
||||
borderRadius: '10px',
|
||||
padding: '10px 14px',
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</QueryClientProvider>
|
||||
)
|
||||
}
|
||||
|
||||
112
src/app/router.tsx
Normal file
112
src/app/router.tsx
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
import React, { Suspense, lazy } from 'react'
|
||||
import { createBrowserRouter, Navigate, RouterProvider } from 'react-router-dom'
|
||||
import { AuthLayout } from '@/layouts/AuthLayout'
|
||||
import { DashboardLayout } from '@/layouts/DashboardLayout'
|
||||
import { AnnotatorLayout } from '@/layouts/AnnotatorLayout'
|
||||
|
||||
const LoginPage = lazy(() =>
|
||||
import('@/pages/auth/LoginPage').then((m) => ({ default: m.LoginPage }))
|
||||
)
|
||||
const ForgotPasswordPage = lazy(() =>
|
||||
import('@/pages/auth/ForgotPasswordPage').then((m) => ({ default: m.ForgotPasswordPage }))
|
||||
)
|
||||
const ProjectListPage = lazy(() =>
|
||||
import('@/pages/projects/ProjectListPage').then((m) => ({ default: m.ProjectListPage }))
|
||||
)
|
||||
const ProjectDetailPage = lazy(() =>
|
||||
import('@/pages/projects/ProjectDetailPage').then((m) => ({ default: m.ProjectDetailPage }))
|
||||
)
|
||||
const UserManagementPage = lazy(() =>
|
||||
import('@/pages/users/UserManagementPage').then((m) => ({ default: m.UserManagementPage }))
|
||||
)
|
||||
const AnnotatorPage = lazy(() =>
|
||||
import('@/pages/annotator/AnnotatorPage').then((m) => ({ default: m.AnnotatorPage }))
|
||||
)
|
||||
|
||||
const PageLoader: React.FC = () => (
|
||||
<div className="flex h-full min-h-[360px] w-full items-center justify-center">
|
||||
<div className="flex flex-col items-center gap-3">
|
||||
<div className="h-8 w-8 animate-spin rounded-full border-2 border-slate-200 border-t-[#C95C3C]" />
|
||||
<span className="text-xs font-medium text-slate-500">Đang tải giao diện...</span>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
export const router = createBrowserRouter([
|
||||
{
|
||||
path: '/',
|
||||
element: <Navigate to="/projects" replace />,
|
||||
},
|
||||
{
|
||||
element: <AuthLayout />,
|
||||
children: [
|
||||
{
|
||||
path: '/login',
|
||||
element: (
|
||||
<Suspense fallback={<PageLoader />}>
|
||||
<LoginPage />
|
||||
</Suspense>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: '/forgot-password',
|
||||
element: (
|
||||
<Suspense fallback={<PageLoader />}>
|
||||
<ForgotPasswordPage />
|
||||
</Suspense>
|
||||
),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
element: <DashboardLayout />,
|
||||
children: [
|
||||
{
|
||||
path: '/projects',
|
||||
element: (
|
||||
<Suspense fallback={<PageLoader />}>
|
||||
<ProjectListPage />
|
||||
</Suspense>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: '/projects/:id',
|
||||
element: (
|
||||
<Suspense fallback={<PageLoader />}>
|
||||
<ProjectDetailPage />
|
||||
</Suspense>
|
||||
),
|
||||
},
|
||||
{
|
||||
path: '/users',
|
||||
element: (
|
||||
<Suspense fallback={<PageLoader />}>
|
||||
<UserManagementPage />
|
||||
</Suspense>
|
||||
),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
element: <AnnotatorLayout />,
|
||||
children: [
|
||||
{
|
||||
path: '/projects/:id/annotate',
|
||||
element: (
|
||||
<Suspense fallback={<PageLoader />}>
|
||||
<AnnotatorPage />
|
||||
</Suspense>
|
||||
),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: '*',
|
||||
element: <Navigate to="/projects" replace />,
|
||||
},
|
||||
])
|
||||
|
||||
export const AppRouter: React.FC = () => {
|
||||
return <RouterProvider router={router} />
|
||||
}
|
||||
|
||||
72
src/components/data-display/DataTable.tsx
Normal file
72
src/components/data-display/DataTable.tsx
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
import React from 'react'
|
||||
import {
|
||||
TableContainer,
|
||||
TableHead,
|
||||
TableBody,
|
||||
TableRow,
|
||||
TableHeaderCell,
|
||||
TableCell,
|
||||
} from '../ui/Table'
|
||||
import { EmptyState } from '../feedback/EmptyState'
|
||||
|
||||
export interface DataTableColumn<T> {
|
||||
key: string
|
||||
header: string
|
||||
className?: string
|
||||
render: (item: T, index: number) => React.ReactNode
|
||||
}
|
||||
|
||||
export interface DataTableProps<T> {
|
||||
columns: DataTableColumn<T>[]
|
||||
data: T[]
|
||||
keyExtractor: (item: T, index: number) => string
|
||||
emptyTitle?: string
|
||||
emptyDescription?: string
|
||||
onRowClick?: (item: T) => void
|
||||
}
|
||||
|
||||
export function DataTable<T>({
|
||||
columns,
|
||||
data,
|
||||
keyExtractor,
|
||||
emptyTitle = 'Không có dữ liệu',
|
||||
emptyDescription = 'Chưa có bản ghi nào phù hợp với bộ lọc hiện tại.',
|
||||
onRowClick,
|
||||
}: DataTableProps<T>) {
|
||||
if (data.length === 0) {
|
||||
return (
|
||||
<div className="p-6">
|
||||
<EmptyState title={emptyTitle} description={emptyDescription} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<TableContainer>
|
||||
<TableHead>
|
||||
<tr>
|
||||
{columns.map((col) => (
|
||||
<TableHeaderCell key={col.key} className={col.className}>
|
||||
{col.header}
|
||||
</TableHeaderCell>
|
||||
))}
|
||||
</tr>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{data.map((item, idx) => (
|
||||
<TableRow
|
||||
key={keyExtractor(item, idx)}
|
||||
onClick={onRowClick ? () => onRowClick(item) : undefined}
|
||||
className={onRowClick ? 'cursor-pointer' : undefined}
|
||||
>
|
||||
{columns.map((col) => (
|
||||
<TableCell key={col.key} className={col.className}>
|
||||
{col.render(item, idx)}
|
||||
</TableCell>
|
||||
))}
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</TableContainer>
|
||||
)
|
||||
}
|
||||
87
src/components/data-display/Pagination.tsx
Normal file
87
src/components/data-display/Pagination.tsx
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
|
||||
export interface PaginationProps {
|
||||
currentPage: number
|
||||
totalPages: number
|
||||
totalItems?: number
|
||||
pageSize?: number
|
||||
onPageChange: (page: number) => void
|
||||
className?: string
|
||||
}
|
||||
|
||||
export const Pagination: React.FC<PaginationProps> = ({
|
||||
currentPage,
|
||||
totalPages,
|
||||
totalItems,
|
||||
pageSize = 10,
|
||||
onPageChange,
|
||||
className,
|
||||
}) => {
|
||||
if (totalPages <= 1 && !totalItems) return null
|
||||
|
||||
const startItem = totalItems ? (currentPage - 1) * pageSize + 1 : 0
|
||||
const endItem = totalItems ? Math.min(currentPage * pageSize, totalItems) : 0
|
||||
|
||||
return (
|
||||
<div
|
||||
className={clsx(
|
||||
'flex flex-col sm:flex-row items-center justify-between gap-3 px-5 py-3.5 border-t border-slate-100 text-xs text-slate-500',
|
||||
className
|
||||
)}
|
||||
>
|
||||
<div>
|
||||
{totalItems !== undefined ? (
|
||||
<span>
|
||||
Hiển thị <strong className="font-semibold text-slate-700">{startItem}</strong> -{' '}
|
||||
<strong className="font-semibold text-slate-700">{endItem}</strong> trong tổng số{' '}
|
||||
<strong className="font-semibold text-slate-700">{totalItems}</strong> mục
|
||||
</span>
|
||||
) : (
|
||||
<span>
|
||||
Trang <strong className="font-semibold text-slate-700">{currentPage}</strong> /{' '}
|
||||
{totalPages}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-1.5">
|
||||
<button
|
||||
type="button"
|
||||
disabled={currentPage <= 1}
|
||||
onClick={() => onPageChange(currentPage - 1)}
|
||||
className="px-3 py-1.5 rounded-lg border border-slate-200 bg-white text-slate-700 font-medium hover:bg-slate-50 disabled:opacity-40 disabled:cursor-not-allowed transition-colors"
|
||||
>
|
||||
Trước
|
||||
</button>
|
||||
{Array.from({ length: totalPages }).map((_, i) => {
|
||||
const page = i + 1
|
||||
const active = page === currentPage
|
||||
return (
|
||||
<button
|
||||
key={page}
|
||||
type="button"
|
||||
onClick={() => onPageChange(page)}
|
||||
className={clsx(
|
||||
'h-7 w-7 rounded-lg text-xs font-semibold transition-colors',
|
||||
active
|
||||
? 'bg-[#C95C3C] text-white'
|
||||
: 'text-slate-600 hover:bg-slate-100'
|
||||
)}
|
||||
>
|
||||
{page}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
<button
|
||||
type="button"
|
||||
disabled={currentPage >= totalPages}
|
||||
onClick={() => onPageChange(currentPage + 1)}
|
||||
className="px-3 py-1.5 rounded-lg border border-slate-200 bg-white text-slate-700 font-medium hover:bg-slate-50 disabled:opacity-40 disabled:cursor-not-allowed transition-colors"
|
||||
>
|
||||
Sau
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
55
src/components/data-display/StatCard.tsx
Normal file
55
src/components/data-display/StatCard.tsx
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
|
||||
export interface StatCardProps {
|
||||
label: string
|
||||
value: string | number
|
||||
subtitle?: string
|
||||
icon?: React.ReactNode
|
||||
trend?: {
|
||||
value: string
|
||||
positive?: boolean
|
||||
}
|
||||
className?: string
|
||||
}
|
||||
|
||||
export const StatCard: React.FC<StatCardProps> = ({
|
||||
label,
|
||||
value,
|
||||
subtitle,
|
||||
icon,
|
||||
trend,
|
||||
className,
|
||||
}) => {
|
||||
return (
|
||||
<div
|
||||
className={clsx(
|
||||
'rounded-2xl bg-white border border-slate-200/80 p-5 shadow-sm flex flex-col justify-between',
|
||||
className
|
||||
)}
|
||||
>
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-xs font-medium text-slate-500">{label}</span>
|
||||
{icon && <div className="text-slate-400">{icon}</div>}
|
||||
</div>
|
||||
<div className="mt-2.5 text-3xl font-bold tracking-tight text-slate-900">
|
||||
{value}
|
||||
</div>
|
||||
{(subtitle || trend) && (
|
||||
<div className="mt-2.5 flex items-center gap-1.5 text-xs text-slate-500">
|
||||
{trend && (
|
||||
<span
|
||||
className={clsx(
|
||||
'font-semibold',
|
||||
trend.positive ? 'text-emerald-600' : 'text-amber-600'
|
||||
)}
|
||||
>
|
||||
{trend.value}
|
||||
</span>
|
||||
)}
|
||||
{subtitle && <span>{subtitle}</span>}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
59
src/components/feedback/EmptyState.tsx
Normal file
59
src/components/feedback/EmptyState.tsx
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
import { Button } from '../ui/Button'
|
||||
|
||||
export interface EmptyStateProps {
|
||||
title: string
|
||||
description?: string
|
||||
actionLabel?: string
|
||||
onAction?: () => void
|
||||
icon?: React.ReactNode
|
||||
className?: string
|
||||
}
|
||||
|
||||
export const EmptyState: React.FC<EmptyStateProps> = ({
|
||||
title,
|
||||
description,
|
||||
actionLabel,
|
||||
onAction,
|
||||
icon,
|
||||
className,
|
||||
}) => {
|
||||
return (
|
||||
<div
|
||||
className={clsx(
|
||||
'flex flex-col items-center justify-center rounded-2xl border border-dashed border-slate-200 bg-slate-50/40 px-6 py-12 text-center',
|
||||
className
|
||||
)}
|
||||
>
|
||||
<div className="mb-3 flex h-12 w-12 items-center justify-center rounded-full bg-orange-50 text-[#C95C3C]">
|
||||
{icon || (
|
||||
<svg
|
||||
className="h-6 w-6"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
strokeWidth={1.8}
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"
|
||||
/>
|
||||
</svg>
|
||||
)}
|
||||
</div>
|
||||
<h4 className="text-base font-semibold text-slate-900">{title}</h4>
|
||||
{description && (
|
||||
<p className="mt-1 max-w-sm text-sm text-slate-500">{description}</p>
|
||||
)}
|
||||
{actionLabel && onAction && (
|
||||
<div className="mt-4">
|
||||
<Button variant="primary" size="sm" onClick={onAction}>
|
||||
{actionLabel}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
70
src/components/feedback/ErrorBoundary.tsx
Normal file
70
src/components/feedback/ErrorBoundary.tsx
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
import React, { Component, ErrorInfo, ReactNode } from 'react'
|
||||
import { Button } from '../ui/Button'
|
||||
|
||||
export interface ErrorBoundaryProps {
|
||||
children: ReactNode
|
||||
fallback?: ReactNode
|
||||
}
|
||||
|
||||
interface ErrorBoundaryState {
|
||||
hasError: boolean
|
||||
error: Error | null
|
||||
}
|
||||
|
||||
export class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
||||
public state: ErrorBoundaryState = {
|
||||
hasError: false,
|
||||
error: null,
|
||||
}
|
||||
|
||||
public static getDerivedStateFromError(error: Error): ErrorBoundaryState {
|
||||
return { hasError: true, error }
|
||||
}
|
||||
|
||||
public componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
||||
console.error('ErrorBoundary caught error:', error, errorInfo)
|
||||
}
|
||||
|
||||
private handleReset = () => {
|
||||
this.setState({ hasError: false, error: null })
|
||||
}
|
||||
|
||||
public render() {
|
||||
if (this.state.hasError) {
|
||||
if (this.props.fallback) {
|
||||
return this.props.fallback
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex min-h-[320px] flex-col items-center justify-center rounded-2xl border border-rose-200 bg-rose-50/40 p-8 text-center">
|
||||
<div className="mb-3 flex h-12 w-12 items-center justify-center rounded-full bg-rose-100 text-rose-600">
|
||||
<svg
|
||||
className="h-6 w-6"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
strokeWidth={2}
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
d="M12 9v2m0 4h.01M5.07 19h13.86c1.54 0 2.5-1.67 1.73-3L13.73 4c-.77-1.33-2.69-1.33-3.46 0L3.34 16c-.77 1.33.19 3 1.73 3z"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
<h3 className="text-lg font-semibold text-slate-900">Đã xảy ra lỗi hiển thị</h3>
|
||||
<p className="mt-1 max-w-md text-sm text-slate-600">
|
||||
{this.state.error?.message || 'Một lỗi không mong muốn đã xảy ra. Vui lòng thử tải lại.'}
|
||||
</p>
|
||||
<div className="mt-4">
|
||||
<Button variant="primary" size="sm" onClick={this.handleReset}>
|
||||
Thử lại
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return this.props.children
|
||||
}
|
||||
}
|
||||
39
src/components/feedback/LoadingSkeleton.tsx
Normal file
39
src/components/feedback/LoadingSkeleton.tsx
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
|
||||
export interface LoadingSkeletonProps {
|
||||
rows?: number
|
||||
className?: string
|
||||
cardCount?: number
|
||||
}
|
||||
|
||||
export const LoadingSkeleton: React.FC<LoadingSkeletonProps> = ({
|
||||
rows = 3,
|
||||
cardCount,
|
||||
className,
|
||||
}) => {
|
||||
if (cardCount && cardCount > 0) {
|
||||
return (
|
||||
<div className={clsx('grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4', className)}>
|
||||
{Array.from({ length: cardCount }).map((_, idx) => (
|
||||
<div
|
||||
key={idx}
|
||||
className="animate-pulse rounded-2xl border border-slate-200 bg-white p-5 space-y-3"
|
||||
>
|
||||
<div className="h-3.5 w-24 rounded bg-slate-200" />
|
||||
<div className="h-8 w-20 rounded bg-slate-200" />
|
||||
<div className="h-3 w-32 rounded bg-slate-100" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={clsx('animate-pulse space-y-3', className)}>
|
||||
{Array.from({ length: rows }).map((_, idx) => (
|
||||
<div key={idx} className="h-12 w-full rounded-xl bg-slate-200/70" />
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
37
src/components/feedback/Toast.tsx
Normal file
37
src/components/feedback/Toast.tsx
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import React from 'react'
|
||||
import toast, { Toaster } from 'react-hot-toast'
|
||||
|
||||
export const showToast = {
|
||||
success: (message: string) =>
|
||||
toast.success(message, {
|
||||
style: {
|
||||
borderRadius: '12px',
|
||||
background: '#1E293B',
|
||||
color: '#fff',
|
||||
fontSize: '14px',
|
||||
},
|
||||
}),
|
||||
error: (message: string) =>
|
||||
toast.error(message, {
|
||||
style: {
|
||||
borderRadius: '12px',
|
||||
background: '#1E293B',
|
||||
color: '#fff',
|
||||
fontSize: '14px',
|
||||
},
|
||||
}),
|
||||
info: (message: string) =>
|
||||
toast(message, {
|
||||
icon: 'ℹ️',
|
||||
style: {
|
||||
borderRadius: '12px',
|
||||
background: '#1E293B',
|
||||
color: '#fff',
|
||||
fontSize: '14px',
|
||||
},
|
||||
}),
|
||||
}
|
||||
|
||||
export const ToasterProvider: React.FC = () => {
|
||||
return <Toaster position="top-right" toastOptions={{ duration: 3000 }} />
|
||||
}
|
||||
43
src/components/ui/Avatar.tsx
Normal file
43
src/components/ui/Avatar.tsx
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
|
||||
export interface AvatarProps {
|
||||
initials: string
|
||||
color?: string
|
||||
size?: 'xs' | 'sm' | 'md' | 'lg'
|
||||
className?: string
|
||||
}
|
||||
|
||||
export const Avatar: React.FC<AvatarProps> = ({
|
||||
initials,
|
||||
color = 'bg-orange-100 text-[#C95C3C]',
|
||||
size = 'md',
|
||||
className,
|
||||
}) => {
|
||||
const sizeClasses: Record<NonNullable<AvatarProps['size']>, string> = {
|
||||
xs: 'h-6 w-6 text-[10px]',
|
||||
sm: 'h-7 w-7 text-xs',
|
||||
md: 'h-8 w-8 text-xs',
|
||||
lg: 'h-10 w-10 text-sm',
|
||||
}
|
||||
|
||||
const isHexOrRgb = color.startsWith('#') || color.startsWith('rgb')
|
||||
|
||||
return (
|
||||
<div
|
||||
style={
|
||||
isHexOrRgb
|
||||
? { backgroundColor: `${color}22`, color: color }
|
||||
: undefined
|
||||
}
|
||||
className={clsx(
|
||||
'inline-flex items-center justify-center rounded-full font-semibold select-none shrink-0',
|
||||
sizeClasses[size],
|
||||
!isHexOrRgb && color,
|
||||
className
|
||||
)}
|
||||
>
|
||||
{initials.slice(0, 2).toUpperCase()}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
60
src/components/ui/Badge.tsx
Normal file
60
src/components/ui/Badge.tsx
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
|
||||
export type BadgeVariant = 'success' | 'warning' | 'danger' | 'info' | 'neutral' | 'purple'
|
||||
|
||||
export interface BadgeProps {
|
||||
children: React.ReactNode
|
||||
variant?: BadgeVariant
|
||||
dot?: boolean
|
||||
className?: string
|
||||
}
|
||||
|
||||
export const Badge: React.FC<BadgeProps> = ({
|
||||
children,
|
||||
variant = 'neutral',
|
||||
dot = false,
|
||||
className,
|
||||
}) => {
|
||||
const variantStyles: Record<BadgeVariant, { container: string; dot: string }> = {
|
||||
success: {
|
||||
container: 'bg-emerald-50 text-emerald-700 border-emerald-200/60',
|
||||
dot: 'bg-emerald-500',
|
||||
},
|
||||
warning: {
|
||||
container: 'bg-amber-50 text-amber-700 border-amber-200/60',
|
||||
dot: 'bg-amber-500',
|
||||
},
|
||||
danger: {
|
||||
container: 'bg-rose-50 text-rose-700 border-rose-200/60',
|
||||
dot: 'bg-rose-500',
|
||||
},
|
||||
info: {
|
||||
container: 'bg-blue-50 text-blue-700 border-blue-200/60',
|
||||
dot: 'bg-blue-500',
|
||||
},
|
||||
neutral: {
|
||||
container: 'bg-slate-100 text-slate-700 border-slate-200/60',
|
||||
dot: 'bg-slate-400',
|
||||
},
|
||||
purple: {
|
||||
container: 'bg-violet-50 text-violet-700 border-violet-200/60',
|
||||
dot: 'bg-violet-500',
|
||||
},
|
||||
}
|
||||
|
||||
const style = variantStyles[variant]
|
||||
|
||||
return (
|
||||
<span
|
||||
className={clsx(
|
||||
'inline-flex items-center gap-1.5 rounded-full border px-2.5 py-0.5 text-xs font-medium',
|
||||
style.container,
|
||||
className
|
||||
)}
|
||||
>
|
||||
{dot && <span className={clsx('h-1.5 w-1.5 rounded-full shrink-0', style.dot)} />}
|
||||
{children}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
78
src/components/ui/Button.tsx
Normal file
78
src/components/ui/Button.tsx
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
|
||||
export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
||||
variant?: 'primary' | 'secondary' | 'outline' | 'ghost' | 'danger'
|
||||
size?: 'sm' | 'md' | 'lg'
|
||||
leftIcon?: React.ReactNode
|
||||
rightIcon?: React.ReactNode
|
||||
isLoading?: boolean
|
||||
}
|
||||
|
||||
export const Button: React.FC<ButtonProps> = ({
|
||||
children,
|
||||
variant = 'primary',
|
||||
size = 'md',
|
||||
leftIcon,
|
||||
rightIcon,
|
||||
isLoading = false,
|
||||
className,
|
||||
disabled,
|
||||
type = 'button',
|
||||
...props
|
||||
}) => {
|
||||
const variantClasses: Record<NonNullable<ButtonProps['variant']>, string> = {
|
||||
primary: 'bg-[#C95C3C] hover:bg-[#B5492B] text-white border border-transparent shadow-sm',
|
||||
secondary: 'bg-slate-100 hover:bg-slate-200 text-slate-800 border border-transparent',
|
||||
outline: 'bg-white hover:bg-slate-50 text-slate-700 border border-slate-200 shadow-sm',
|
||||
ghost: 'bg-transparent hover:bg-slate-100 text-slate-600 hover:text-slate-900 border border-transparent',
|
||||
danger: 'bg-red-600 hover:bg-red-700 text-white border border-transparent shadow-sm',
|
||||
}
|
||||
|
||||
const sizeClasses: Record<NonNullable<ButtonProps['size']>, string> = {
|
||||
sm: 'px-3 py-1.5 text-xs rounded-lg gap-1.5',
|
||||
md: 'px-4 py-2 text-sm rounded-xl gap-2',
|
||||
lg: 'px-5 py-2.5 text-base rounded-xl gap-2.5',
|
||||
}
|
||||
|
||||
return (
|
||||
<button
|
||||
type={type}
|
||||
disabled={disabled || isLoading}
|
||||
className={clsx(
|
||||
'inline-flex items-center justify-center font-medium transition-colors duration-150 focus:outline-none focus:ring-2 focus:ring-[#C95C3C]/30 disabled:opacity-50 disabled:cursor-not-allowed',
|
||||
variantClasses[variant],
|
||||
sizeClasses[size],
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{isLoading ? (
|
||||
<svg
|
||||
className="animate-spin h-4 w-4 text-current"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<circle
|
||||
className="opacity-25"
|
||||
cx="12"
|
||||
cy="12"
|
||||
r="10"
|
||||
stroke="currentColor"
|
||||
strokeWidth="4"
|
||||
/>
|
||||
<path
|
||||
className="opacity-75"
|
||||
fill="currentColor"
|
||||
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
||||
/>
|
||||
</svg>
|
||||
) : (
|
||||
leftIcon && <span className="shrink-0">{leftIcon}</span>
|
||||
)}
|
||||
<span>{children}</span>
|
||||
{!isLoading && rightIcon && <span className="shrink-0">{rightIcon}</span>}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
34
src/components/ui/Card.tsx
Normal file
34
src/components/ui/Card.tsx
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
|
||||
export interface CardProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||
children: React.ReactNode
|
||||
padding?: 'none' | 'sm' | 'md' | 'lg'
|
||||
}
|
||||
|
||||
export const Card: React.FC<CardProps> = ({
|
||||
children,
|
||||
padding = 'md',
|
||||
className,
|
||||
...props
|
||||
}) => {
|
||||
const paddingClasses: Record<NonNullable<CardProps['padding']>, string> = {
|
||||
none: '',
|
||||
sm: 'p-4',
|
||||
md: 'p-5',
|
||||
lg: 'p-6',
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className={clsx(
|
||||
'rounded-2xl bg-white border border-slate-200/80 shadow-sm',
|
||||
paddingClasses[padding],
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
43
src/components/ui/Checkbox.tsx
Normal file
43
src/components/ui/Checkbox.tsx
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
|
||||
export interface CheckboxProps
|
||||
extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'type'> {
|
||||
label?: string
|
||||
description?: string
|
||||
}
|
||||
|
||||
export const Checkbox: React.FC<CheckboxProps> = ({
|
||||
label,
|
||||
description,
|
||||
className,
|
||||
id,
|
||||
...props
|
||||
}) => {
|
||||
const checkboxId =
|
||||
id || (label ? `checkbox-${label.replace(/\s+/g, '-').toLowerCase()}` : undefined)
|
||||
|
||||
return (
|
||||
<label
|
||||
htmlFor={checkboxId}
|
||||
className={clsx(
|
||||
'inline-flex items-start gap-2.5 cursor-pointer select-none',
|
||||
props.disabled && 'opacity-60 cursor-not-allowed',
|
||||
className
|
||||
)}
|
||||
>
|
||||
<input
|
||||
id={checkboxId}
|
||||
type="checkbox"
|
||||
className="mt-0.5 h-4 w-4 rounded border-slate-300 text-[#C95C3C] focus:ring-[#C95C3C]/30 accent-[#C95C3C] cursor-pointer"
|
||||
{...props}
|
||||
/>
|
||||
{(label || description) && (
|
||||
<div className="text-sm">
|
||||
{label && <span className="font-medium text-slate-700">{label}</span>}
|
||||
{description && <p className="text-xs text-slate-500 mt-0.5">{description}</p>}
|
||||
</div>
|
||||
)}
|
||||
</label>
|
||||
)
|
||||
}
|
||||
75
src/components/ui/Dropdown.tsx
Normal file
75
src/components/ui/Dropdown.tsx
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
import React, { useState, useRef, useEffect } from 'react'
|
||||
import clsx from 'clsx'
|
||||
|
||||
export interface DropdownItem {
|
||||
label: string
|
||||
onClick: () => void
|
||||
danger?: boolean
|
||||
icon?: React.ReactNode
|
||||
}
|
||||
|
||||
export interface DropdownProps {
|
||||
trigger: React.ReactNode
|
||||
items: DropdownItem[]
|
||||
align?: 'left' | 'right'
|
||||
className?: string
|
||||
}
|
||||
|
||||
export const Dropdown: React.FC<DropdownProps> = ({
|
||||
trigger,
|
||||
items,
|
||||
align = 'right',
|
||||
className,
|
||||
}) => {
|
||||
const [open, setOpen] = useState(false)
|
||||
const ref = useRef<HTMLDivElement>(null)
|
||||
|
||||
useEffect(() => {
|
||||
const handleClickOutside = (event: MouseEvent) => {
|
||||
if (ref.current && !ref.current.contains(event.target as Node)) {
|
||||
setOpen(false)
|
||||
}
|
||||
}
|
||||
document.addEventListener('mousedown', handleClickOutside)
|
||||
return () => document.removeEventListener('mousedown', handleClickOutside)
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<div ref={ref} className={clsx('relative inline-block text-left', className)}>
|
||||
<div
|
||||
onClick={() => setOpen((prev) => !prev)}
|
||||
className="cursor-pointer inline-flex items-center"
|
||||
>
|
||||
{trigger}
|
||||
</div>
|
||||
{open && (
|
||||
<div
|
||||
className={clsx(
|
||||
'absolute z-40 mt-2 w-48 rounded-xl bg-white border border-slate-200 shadow-lg py-1.5 focus:outline-none',
|
||||
align === 'right' ? 'right-0' : 'left-0'
|
||||
)}
|
||||
>
|
||||
{items.map((item, idx) => (
|
||||
<button
|
||||
key={idx}
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setOpen(false)
|
||||
item.onClick()
|
||||
}}
|
||||
className={clsx(
|
||||
'flex w-full items-center gap-2 px-4 py-2 text-left text-sm transition-colors',
|
||||
item.danger
|
||||
? 'text-red-600 hover:bg-red-50'
|
||||
: 'text-slate-700 hover:bg-slate-50'
|
||||
)}
|
||||
>
|
||||
{item.icon && <span className="shrink-0">{item.icon}</span>}
|
||||
<span>{item.label}</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
58
src/components/ui/Input.tsx
Normal file
58
src/components/ui/Input.tsx
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
|
||||
export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
|
||||
label?: string
|
||||
error?: string
|
||||
leftIcon?: React.ReactNode
|
||||
rightElement?: React.ReactNode
|
||||
helperText?: string
|
||||
}
|
||||
|
||||
export const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
||||
({ label, error, leftIcon, rightElement, helperText, className, id, ...props }, ref) => {
|
||||
const inputId = id || (label ? `input-${label.replace(/\s+/g, '-').toLowerCase()}` : undefined)
|
||||
|
||||
return (
|
||||
<div className="w-full">
|
||||
{label && (
|
||||
<label
|
||||
htmlFor={inputId}
|
||||
className="block text-sm font-medium text-slate-700 mb-1.5"
|
||||
>
|
||||
{label}
|
||||
</label>
|
||||
)}
|
||||
<div className="relative flex items-center">
|
||||
{leftIcon && (
|
||||
<div className="absolute left-3.5 text-slate-400 pointer-events-none flex items-center">
|
||||
{leftIcon}
|
||||
</div>
|
||||
)}
|
||||
<input
|
||||
ref={ref}
|
||||
id={inputId}
|
||||
className={clsx(
|
||||
'w-full rounded-lg border bg-white px-3.5 py-2 text-sm text-slate-900 placeholder:text-slate-400 transition-colors focus:outline-none focus:ring-2',
|
||||
leftIcon && 'pl-10',
|
||||
rightElement && 'pr-10',
|
||||
error
|
||||
? 'border-red-400 focus:border-red-500 focus:ring-red-500/20'
|
||||
: 'border-slate-200 focus:border-[#C95C3C] focus:ring-[#C95C3C]/20',
|
||||
props.disabled && 'bg-slate-50 text-slate-500 cursor-not-allowed',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
{rightElement && (
|
||||
<div className="absolute right-3 flex items-center">{rightElement}</div>
|
||||
)}
|
||||
</div>
|
||||
{error && <p className="mt-1.5 text-xs text-red-600">{error}</p>}
|
||||
{!error && helperText && <p className="mt-1.5 text-xs text-slate-500">{helperText}</p>}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
Input.displayName = 'Input'
|
||||
80
src/components/ui/Modal.tsx
Normal file
80
src/components/ui/Modal.tsx
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
import React, { useEffect } from 'react'
|
||||
import clsx from 'clsx'
|
||||
|
||||
export interface ModalProps {
|
||||
isOpen: boolean
|
||||
onClose: () => void
|
||||
title: string
|
||||
subtitle?: string
|
||||
children: React.ReactNode
|
||||
footer?: React.ReactNode
|
||||
size?: 'sm' | 'md' | 'lg' | 'xl'
|
||||
}
|
||||
|
||||
export const Modal: React.FC<ModalProps> = ({
|
||||
isOpen,
|
||||
onClose,
|
||||
title,
|
||||
subtitle,
|
||||
children,
|
||||
footer,
|
||||
size = 'md',
|
||||
}) => {
|
||||
useEffect(() => {
|
||||
if (!isOpen) return
|
||||
const handleKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape') {
|
||||
onClose()
|
||||
}
|
||||
}
|
||||
window.addEventListener('keydown', handleKeyDown)
|
||||
return () => window.removeEventListener('keydown', handleKeyDown)
|
||||
}, [isOpen, onClose])
|
||||
|
||||
if (!isOpen) return null
|
||||
|
||||
const sizeClasses: Record<NonNullable<ModalProps['size']>, string> = {
|
||||
sm: 'max-w-md',
|
||||
md: 'max-w-lg',
|
||||
lg: 'max-w-2xl',
|
||||
xl: 'max-w-4xl',
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center p-4">
|
||||
<div
|
||||
className="fixed inset-0 bg-slate-900/40 backdrop-blur-[1px] transition-opacity"
|
||||
onClick={onClose}
|
||||
/>
|
||||
<div
|
||||
className={clsx(
|
||||
'relative z-10 w-full rounded-2xl bg-white border border-slate-200 shadow-xl overflow-hidden',
|
||||
sizeClasses[size]
|
||||
)}
|
||||
>
|
||||
<div className="flex items-start justify-between px-6 pt-5 pb-4 border-b border-slate-100">
|
||||
<div>
|
||||
<h3 className="text-lg font-semibold text-slate-900">{title}</h3>
|
||||
{subtitle && <p className="mt-0.5 text-sm text-slate-500">{subtitle}</p>}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
className="rounded-lg p-1.5 text-slate-400 hover:bg-slate-100 hover:text-slate-600 transition-colors"
|
||||
aria-label="Đóng"
|
||||
>
|
||||
<svg className="w-5 h-5" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
|
||||
<path strokeLinecap="round" strokeLinejoin="round" d="M6 18L18 6M6 6l12 12" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
<div className="px-6 py-5 max-h-[75vh] overflow-y-auto">{children}</div>
|
||||
{footer && (
|
||||
<div className="flex items-center justify-end gap-2.5 px-6 py-4 bg-slate-50/70 border-t border-slate-100">
|
||||
{footer}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
46
src/components/ui/ProgressBar.tsx
Normal file
46
src/components/ui/ProgressBar.tsx
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
|
||||
export interface ProgressBarProps {
|
||||
value: number
|
||||
max?: number
|
||||
color?: string
|
||||
height?: 'xs' | 'sm' | 'md'
|
||||
className?: string
|
||||
}
|
||||
|
||||
export const ProgressBar: React.FC<ProgressBarProps> = ({
|
||||
value,
|
||||
max = 100,
|
||||
color = 'bg-[#C95C3C]',
|
||||
height = 'sm',
|
||||
className,
|
||||
}) => {
|
||||
const percentage = Math.min(100, Math.max(0, (value / max) * 100))
|
||||
|
||||
const heightClasses: Record<NonNullable<ProgressBarProps['height']>, string> = {
|
||||
xs: 'h-1',
|
||||
sm: 'h-1.5',
|
||||
md: 'h-2.5',
|
||||
}
|
||||
|
||||
const isHex = color.startsWith('#')
|
||||
|
||||
return (
|
||||
<div
|
||||
className={clsx(
|
||||
'w-full overflow-hidden rounded-full bg-slate-100',
|
||||
heightClasses[height],
|
||||
className
|
||||
)}
|
||||
>
|
||||
<div
|
||||
className={clsx('h-full rounded-full transition-all duration-300', !isHex && color)}
|
||||
style={{
|
||||
width: `${percentage}%`,
|
||||
...(isHex ? { backgroundColor: color } : {}),
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
63
src/components/ui/RadioGroup.tsx
Normal file
63
src/components/ui/RadioGroup.tsx
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
|
||||
export interface RadioOption {
|
||||
value: string
|
||||
label: string
|
||||
description?: string
|
||||
}
|
||||
|
||||
export interface RadioGroupProps {
|
||||
name: string
|
||||
label?: string
|
||||
options: RadioOption[]
|
||||
value: string
|
||||
onChange: (value: string) => void
|
||||
className?: string
|
||||
}
|
||||
|
||||
export const RadioGroup: React.FC<RadioGroupProps> = ({
|
||||
name,
|
||||
label,
|
||||
options,
|
||||
value,
|
||||
onChange,
|
||||
className,
|
||||
}) => {
|
||||
return (
|
||||
<div className={className}>
|
||||
{label && <div className="text-sm font-medium text-slate-700 mb-2">{label}</div>}
|
||||
<div className="space-y-2">
|
||||
{options.map((option) => {
|
||||
const checked = value === option.value
|
||||
return (
|
||||
<label
|
||||
key={option.value}
|
||||
className={clsx(
|
||||
'flex items-start gap-3 rounded-xl border p-3 cursor-pointer transition-colors',
|
||||
checked
|
||||
? 'border-[#C95C3C] bg-orange-50/40'
|
||||
: 'border-slate-200 hover:bg-slate-50'
|
||||
)}
|
||||
>
|
||||
<input
|
||||
type="radio"
|
||||
name={name}
|
||||
value={option.value}
|
||||
checked={checked}
|
||||
onChange={() => onChange(option.value)}
|
||||
className="mt-0.5 h-4 w-4 border-slate-300 text-[#C95C3C] focus:ring-[#C95C3C]/30 accent-[#C95C3C]"
|
||||
/>
|
||||
<div className="text-sm">
|
||||
<div className="font-medium text-slate-800">{option.label}</div>
|
||||
{option.description && (
|
||||
<div className="text-xs text-slate-500 mt-0.5">{option.description}</div>
|
||||
)}
|
||||
</div>
|
||||
</label>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
61
src/components/ui/SearchInput.tsx
Normal file
61
src/components/ui/SearchInput.tsx
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
|
||||
export interface SearchInputProps
|
||||
extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onChange'> {
|
||||
value: string
|
||||
onChange: (value: string) => void
|
||||
onClear?: () => void
|
||||
}
|
||||
|
||||
export const SearchInput: React.FC<SearchInputProps> = ({
|
||||
value,
|
||||
onChange,
|
||||
onClear,
|
||||
placeholder = 'Tìm kiếm...',
|
||||
className,
|
||||
...props
|
||||
}) => {
|
||||
const handleClear = () => {
|
||||
onChange('')
|
||||
onClear?.()
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={clsx('relative flex items-center', className)}>
|
||||
<svg
|
||||
className="w-4 h-4 text-slate-400 absolute left-3.5 pointer-events-none"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
strokeWidth={2}
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
d="M21 21l-4.35-4.35m0 0A7.5 7.5 0 103.5 10.5a7.5 7.5 0 0013.15 6.15z"
|
||||
/>
|
||||
</svg>
|
||||
<input
|
||||
type="text"
|
||||
value={value}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
placeholder={placeholder}
|
||||
className="w-full rounded-xl border border-slate-200 bg-white pl-10 pr-8 py-2 text-sm text-slate-900 placeholder:text-slate-400 focus:outline-none focus:border-[#C95C3C] focus:ring-2 focus:ring-[#C95C3C]/15 transition-colors"
|
||||
{...props}
|
||||
/>
|
||||
{value && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleClear}
|
||||
aria-label="Xóa tìm kiếm"
|
||||
className="absolute right-2.5 p-0.5 text-slate-400 hover:text-slate-600 rounded-md"
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
|
||||
<path strokeLinecap="round" strokeLinejoin="round" d="M6 18L18 6M6 6l12 12" />
|
||||
</svg>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
65
src/components/ui/Select.tsx
Normal file
65
src/components/ui/Select.tsx
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
|
||||
export interface SelectOption {
|
||||
value: string
|
||||
label: string
|
||||
}
|
||||
|
||||
export interface SelectProps
|
||||
extends Omit<React.SelectHTMLAttributes<HTMLSelectElement>, 'onChange'> {
|
||||
label?: string
|
||||
options: SelectOption[]
|
||||
value: string
|
||||
onChange: (value: string) => void
|
||||
error?: string
|
||||
}
|
||||
|
||||
export const Select: React.FC<SelectProps> = ({
|
||||
label,
|
||||
options,
|
||||
value,
|
||||
onChange,
|
||||
error,
|
||||
className,
|
||||
id,
|
||||
...props
|
||||
}) => {
|
||||
const selectId = id || (label ? `select-${label.replace(/\s+/g, '-').toLowerCase()}` : undefined)
|
||||
|
||||
return (
|
||||
<div className={clsx(' inline-block', className)}>
|
||||
{label && (
|
||||
<label htmlFor={selectId} className="block text-sm font-medium text-slate-700 mb-1.5">
|
||||
{label}
|
||||
</label>
|
||||
)}
|
||||
<div className="relative">
|
||||
<select
|
||||
id={selectId}
|
||||
value={value}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
className={clsx(
|
||||
'w-full appearance-none rounded-xl border bg-white pl-3.5 pr-9 py-2 text-sm text-slate-700 font-medium focus:outline-none focus:ring-2 transition-colors cursor-pointer',
|
||||
error
|
||||
? 'border-red-400 focus:border-red-500 focus:ring-red-500/20'
|
||||
: 'border-slate-200 hover:border-slate-300 focus:border-[#C95C3C] focus:ring-[#C95C3C]/15'
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{options.map((opt) => (
|
||||
<option key={opt.value} value={opt.value}>
|
||||
{opt.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<div className="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3 text-slate-500">
|
||||
<svg className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
|
||||
<path strokeLinecap="round" strokeLinejoin="round" d="M19 9l-7 7-7-7" />
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
{error && <p className="mt-1 text-xs text-red-600">{error}</p>}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
39
src/components/ui/Spinner.tsx
Normal file
39
src/components/ui/Spinner.tsx
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
|
||||
export interface SpinnerProps {
|
||||
size?: 'sm' | 'md' | 'lg'
|
||||
className?: string
|
||||
}
|
||||
|
||||
export const Spinner: React.FC<SpinnerProps> = ({ size = 'md', className }) => {
|
||||
const sizeClasses: Record<NonNullable<SpinnerProps['size']>, string> = {
|
||||
sm: 'h-4 w-4',
|
||||
md: 'h-6 w-6',
|
||||
lg: 'h-8 w-8',
|
||||
}
|
||||
|
||||
return (
|
||||
<svg
|
||||
className={clsx('animate-spin text-[#C95C3C]', sizeClasses[size], className)}
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
aria-label="Đang tải..."
|
||||
>
|
||||
<circle
|
||||
className="opacity-25"
|
||||
cx="12"
|
||||
cy="12"
|
||||
r="10"
|
||||
stroke="currentColor"
|
||||
strokeWidth="4"
|
||||
/>
|
||||
<path
|
||||
className="opacity-75"
|
||||
fill="currentColor"
|
||||
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
||||
/>
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
65
src/components/ui/Table.tsx
Normal file
65
src/components/ui/Table.tsx
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
|
||||
export const TableContainer: React.FC<React.HTMLAttributes<HTMLDivElement>> = ({
|
||||
children,
|
||||
className,
|
||||
...props
|
||||
}) => (
|
||||
<div className={clsx('w-full overflow-x-auto', className)} {...props}>
|
||||
<table className="w-full border-collapse text-left">{children}</table>
|
||||
</div>
|
||||
)
|
||||
|
||||
export const TableHead: React.FC<React.HTMLAttributes<HTMLTableSectionElement>> = ({
|
||||
children,
|
||||
className,
|
||||
...props
|
||||
}) => (
|
||||
<thead
|
||||
className={clsx('bg-slate-50/70 border-y border-slate-200/80 text-[11px] font-semibold uppercase tracking-wider text-slate-400', className)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</thead>
|
||||
)
|
||||
|
||||
export const TableBody: React.FC<React.HTMLAttributes<HTMLTableSectionElement>> = ({
|
||||
children,
|
||||
className,
|
||||
...props
|
||||
}) => (
|
||||
<tbody className={clsx('divide-y divide-slate-100 bg-white text-sm text-slate-700', className)} {...props}>
|
||||
{children}
|
||||
</tbody>
|
||||
)
|
||||
|
||||
export const TableRow: React.FC<React.HTMLAttributes<HTMLTableRowElement>> = ({
|
||||
children,
|
||||
className,
|
||||
...props
|
||||
}) => (
|
||||
<tr className={clsx('hover:bg-slate-50/70 transition-colors', className)} {...props}>
|
||||
{children}
|
||||
</tr>
|
||||
)
|
||||
|
||||
export const TableHeaderCell: React.FC<React.ThHTMLAttributes<HTMLTableCellElement>> = ({
|
||||
children,
|
||||
className,
|
||||
...props
|
||||
}) => (
|
||||
<th className={clsx('px-5 py-3 font-semibold', className)} {...props}>
|
||||
{children}
|
||||
</th>
|
||||
)
|
||||
|
||||
export const TableCell: React.FC<React.TdHTMLAttributes<HTMLTableCellElement>> = ({
|
||||
children,
|
||||
className,
|
||||
...props
|
||||
}) => (
|
||||
<td className={clsx('px-5 py-3.5 align-middle', className)} {...props}>
|
||||
{children}
|
||||
</td>
|
||||
)
|
||||
59
src/components/ui/Tabs.tsx
Normal file
59
src/components/ui/Tabs.tsx
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
|
||||
export interface TabItem {
|
||||
id: string
|
||||
label: string
|
||||
count?: number
|
||||
}
|
||||
|
||||
export interface TabsProps {
|
||||
tabs: TabItem[]
|
||||
activeTab: string
|
||||
onChange: (id: string) => void
|
||||
className?: string
|
||||
}
|
||||
|
||||
export const Tabs: React.FC<TabsProps> = ({
|
||||
tabs,
|
||||
activeTab,
|
||||
onChange,
|
||||
className,
|
||||
}) => {
|
||||
return (
|
||||
<div className={clsx('border-b border-slate-200', className)}>
|
||||
<nav className="-mb-px flex space-x-6 overflow-x-auto" aria-label="Tabs">
|
||||
{tabs.map((tab) => {
|
||||
const isActive = tab.id === activeTab
|
||||
return (
|
||||
<button
|
||||
key={tab.id}
|
||||
type="button"
|
||||
onClick={() => onChange(tab.id)}
|
||||
className={clsx(
|
||||
'whitespace-nowrap py-3 px-1 border-b-2 text-sm font-medium transition-colors flex items-center gap-2',
|
||||
isActive
|
||||
? 'border-[#3B5BDB] text-[#3B5BDB] font-semibold'
|
||||
: 'border-transparent text-slate-500 hover:text-slate-800 hover:border-slate-300'
|
||||
)}
|
||||
>
|
||||
<span>{tab.label}</span>
|
||||
{typeof tab.count === 'number' && (
|
||||
<span
|
||||
className={clsx(
|
||||
'rounded-full px-2 py-0.5 text-xs font-medium',
|
||||
isActive
|
||||
? 'bg-blue-50 text-[#3B5BDB]'
|
||||
: 'bg-slate-100 text-slate-600'
|
||||
)}
|
||||
>
|
||||
{tab.count}
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</nav>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
46
src/components/ui/Textarea.tsx
Normal file
46
src/components/ui/Textarea.tsx
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
|
||||
export interface TextareaProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {
|
||||
label?: string
|
||||
error?: string
|
||||
helperText?: string
|
||||
}
|
||||
|
||||
export const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
|
||||
({ label, error, helperText, className, id, rows = 3, ...props }, ref) => {
|
||||
const textareaId =
|
||||
id || (label ? `textarea-${label.replace(/\s+/g, '-').toLowerCase()}` : undefined)
|
||||
|
||||
return (
|
||||
<div className="w-full">
|
||||
{label && (
|
||||
<label
|
||||
htmlFor={textareaId}
|
||||
className="block text-sm font-medium text-slate-700 mb-1.5"
|
||||
>
|
||||
{label}
|
||||
</label>
|
||||
)}
|
||||
<textarea
|
||||
ref={ref}
|
||||
id={textareaId}
|
||||
rows={rows}
|
||||
className={clsx(
|
||||
'w-full rounded-xl border bg-white px-3.5 py-2.5 text-sm text-slate-900 placeholder:text-slate-400 transition-colors focus:outline-none focus:ring-2',
|
||||
error
|
||||
? 'border-red-400 focus:border-red-500 focus:ring-red-500/20'
|
||||
: 'border-slate-200 focus:border-[#C95C3C] focus:ring-[#C95C3C]/20',
|
||||
props.disabled && 'bg-slate-50 text-slate-500 cursor-not-allowed',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
{error && <p className="mt-1.5 text-xs text-red-600">{error}</p>}
|
||||
{!error && helperText && <p className="mt-1.5 text-xs text-slate-500">{helperText}</p>}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
Textarea.displayName = 'Textarea'
|
||||
38
src/components/ui/Tooltip.tsx
Normal file
38
src/components/ui/Tooltip.tsx
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
|
||||
export interface TooltipProps {
|
||||
content: string
|
||||
children: React.ReactNode
|
||||
position?: 'top' | 'bottom' | 'left' | 'right'
|
||||
className?: string
|
||||
}
|
||||
|
||||
export const Tooltip: React.FC<TooltipProps> = ({
|
||||
content,
|
||||
children,
|
||||
position = 'top',
|
||||
className,
|
||||
}) => {
|
||||
const positionClasses: Record<NonNullable<TooltipProps['position']>, string> = {
|
||||
top: 'bottom-full left-1/2 -translate-x-1/2 mb-2',
|
||||
bottom: 'top-full left-1/2 -translate-x-1/2 mt-2',
|
||||
left: 'right-full top-1/2 -translate-y-1/2 mr-2',
|
||||
right: 'left-full top-1/2 -translate-y-1/2 ml-2',
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={clsx('relative inline-flex group', className)}>
|
||||
{children}
|
||||
<div
|
||||
role="tooltip"
|
||||
className={clsx(
|
||||
'pointer-events-none absolute z-50 whitespace-nowrap rounded-lg bg-slate-900 px-2.5 py-1 text-xs font-medium text-white opacity-0 shadow-md transition-opacity duration-150 group-hover:opacity-100',
|
||||
positionClasses[position]
|
||||
)}
|
||||
>
|
||||
{content}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
17
src/components/ui/index.ts
Normal file
17
src/components/ui/index.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
export * from './Button'
|
||||
export * from './Input'
|
||||
export * from './SearchInput'
|
||||
export * from './Select'
|
||||
export * from './Modal'
|
||||
export * from './Badge'
|
||||
export * from './Avatar'
|
||||
export * from './Card'
|
||||
export * from './Table'
|
||||
export * from './Tabs'
|
||||
export * from './ProgressBar'
|
||||
export * from './Tooltip'
|
||||
export * from './Dropdown'
|
||||
export * from './Checkbox'
|
||||
export * from './RadioGroup'
|
||||
export * from './Textarea'
|
||||
export * from './Spinner'
|
||||
128
src/hooks/useAnnotation.ts
Normal file
128
src/hooks/useAnnotation.ts
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
import { useEffect } from 'react'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import * as annotationService from '@/services/annotationService'
|
||||
import * as exportService from '@/services/exportService'
|
||||
import * as imageService from '@/services/imageService'
|
||||
import { useAnnotationStore } from '@/stores/annotationStore'
|
||||
|
||||
export function useAnnotation(projectId?: string, imageId?: string) {
|
||||
const queryClient = useQueryClient()
|
||||
const resolvedProjectId = projectId || 'proj-traffic-det'
|
||||
const resolvedImageId = imageId || `${resolvedProjectId}-img-42`
|
||||
|
||||
const store = useAnnotationStore()
|
||||
|
||||
const imageQuery = useQuery({
|
||||
queryKey: ['image', resolvedProjectId, resolvedImageId],
|
||||
queryFn: () => imageService.getImageById(resolvedProjectId, resolvedImageId),
|
||||
enabled: Boolean(resolvedProjectId && resolvedImageId),
|
||||
})
|
||||
|
||||
const annotationQuery = useQuery({
|
||||
queryKey: ['annotation', resolvedProjectId, resolvedImageId],
|
||||
queryFn: () => annotationService.getAnnotation(resolvedProjectId, resolvedImageId),
|
||||
enabled: Boolean(resolvedProjectId && resolvedImageId),
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (annotationQuery.data && annotationQuery.data.imageId !== store.currentImageId) {
|
||||
store.setAnnotationData(annotationQuery.data)
|
||||
}
|
||||
}, [annotationQuery.data, store])
|
||||
|
||||
const saveMutation = useMutation({
|
||||
mutationFn: () =>
|
||||
annotationService.saveAnnotation(resolvedProjectId, resolvedImageId, {
|
||||
classificationLabelId: store.classificationLabelId,
|
||||
flags: store.flags,
|
||||
shapes: store.shapes,
|
||||
}),
|
||||
onSuccess: (saved) => {
|
||||
store.markSaved(saved.updatedAt)
|
||||
queryClient.invalidateQueries({ queryKey: ['project-images', resolvedProjectId] })
|
||||
},
|
||||
})
|
||||
|
||||
const submitMutation = useMutation({
|
||||
mutationFn: async () => {
|
||||
await annotationService.saveAnnotation(resolvedProjectId, resolvedImageId, {
|
||||
classificationLabelId: store.classificationLabelId,
|
||||
flags: store.flags,
|
||||
shapes: store.shapes,
|
||||
})
|
||||
return annotationService.submitForReview(resolvedProjectId, resolvedImageId)
|
||||
},
|
||||
onSuccess: () => {
|
||||
store.markSaved('Đã gửi duyệt')
|
||||
queryClient.invalidateQueries({ queryKey: ['image', resolvedProjectId, resolvedImageId] })
|
||||
queryClient.invalidateQueries({ queryKey: ['project-images', resolvedProjectId] })
|
||||
queryClient.invalidateQueries({ queryKey: ['project', resolvedProjectId] })
|
||||
},
|
||||
})
|
||||
|
||||
const approveMutation = useMutation({
|
||||
mutationFn: () => annotationService.approveAnnotation(resolvedProjectId, resolvedImageId),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['image', resolvedProjectId, resolvedImageId] })
|
||||
queryClient.invalidateQueries({ queryKey: ['project-images', resolvedProjectId] })
|
||||
queryClient.invalidateQueries({ queryKey: ['project', resolvedProjectId] })
|
||||
},
|
||||
})
|
||||
|
||||
const rejectMutation = useMutation({
|
||||
mutationFn: (reason?: string) =>
|
||||
annotationService.rejectAnnotation(resolvedProjectId, resolvedImageId, reason),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['image', resolvedProjectId, resolvedImageId] })
|
||||
queryClient.invalidateQueries({ queryKey: ['project-images', resolvedProjectId] })
|
||||
queryClient.invalidateQueries({ queryKey: ['project', resolvedProjectId] })
|
||||
},
|
||||
})
|
||||
|
||||
const exportLabelMe = () => {
|
||||
if (!imageQuery.data) return
|
||||
exportService.downloadImageLabelMeJSON(imageQuery.data, store.shapes)
|
||||
}
|
||||
|
||||
const exportMask = () => {
|
||||
if (!imageQuery.data) return
|
||||
exportService.downloadImageMaskPNG(imageQuery.data, store.shapes)
|
||||
}
|
||||
|
||||
const selectedShape = store.shapes.find((s) => s.id === store.selectedShapeId) ?? null
|
||||
|
||||
return {
|
||||
image: imageQuery.data,
|
||||
isLoading: imageQuery.isLoading || annotationQuery.isLoading,
|
||||
shapes: store.shapes,
|
||||
selectedShapeId: store.selectedShapeId,
|
||||
selectedShape,
|
||||
classificationLabelId: store.classificationLabelId,
|
||||
flags: store.flags,
|
||||
activeLabelId: store.activeLabelId,
|
||||
activeGroupId: store.activeGroupId,
|
||||
lastSavedAt: store.lastSavedAt,
|
||||
isDirty: store.isDirty,
|
||||
canUndo: store.history.past.length > 0,
|
||||
canRedo: store.history.future.length > 0,
|
||||
addShape: store.addShape,
|
||||
updateShape: store.updateShape,
|
||||
deleteShape: store.deleteShape,
|
||||
toggleShapeVisibility: store.toggleShapeVisibility,
|
||||
selectShape: store.selectShape,
|
||||
setClassificationLabel: store.setClassificationLabel,
|
||||
toggleFlag: store.toggleFlag,
|
||||
setActiveLabelId: store.setActiveLabelId,
|
||||
setActiveGroupId: store.setActiveGroupId,
|
||||
undo: store.undo,
|
||||
redo: store.redo,
|
||||
saveAnnotation: saveMutation.mutateAsync,
|
||||
isSaving: saveMutation.isPending,
|
||||
submitForReview: submitMutation.mutateAsync,
|
||||
isSubmitting: submitMutation.isPending,
|
||||
approveAnnotation: approveMutation.mutateAsync,
|
||||
rejectAnnotation: rejectMutation.mutateAsync,
|
||||
exportLabelMe,
|
||||
exportMask,
|
||||
}
|
||||
}
|
||||
67
src/hooks/useAuth.ts
Normal file
67
src/hooks/useAuth.ts
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
import { useState } from 'react'
|
||||
import * as authService from '@/services/authService'
|
||||
import { useAuthStore } from '@/stores/authStore'
|
||||
import { LoginRequest, UserRole } from '@/types'
|
||||
import { canApproveLabels, canCreateProject, canManageUsers } from '@/utils/permissions'
|
||||
|
||||
export function useAuth() {
|
||||
const { user, isAuthenticated, login: storeLogin, logout: storeLogout, setUser, setRole } = useAuthStore()
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
|
||||
const login = async (payload: LoginRequest) => {
|
||||
setIsLoading(true)
|
||||
setError(null)
|
||||
try {
|
||||
const response = await authService.login(payload)
|
||||
storeLogin(response.user, response.accessToken)
|
||||
return response
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : 'Đăng nhập thất bại'
|
||||
setError(message)
|
||||
throw err
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
const loginWithSSO = async (provider: 'google' | 'microsoft' | 'sso' = 'sso') => {
|
||||
setIsLoading(true)
|
||||
setError(null)
|
||||
try {
|
||||
const response = await authService.loginWithSSO(provider)
|
||||
storeLogin(response.user, response.accessToken)
|
||||
return response
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
const logout = async () => {
|
||||
await authService.logout()
|
||||
storeLogout()
|
||||
}
|
||||
|
||||
const switchRole = async (role: UserRole) => {
|
||||
const updated = await authService.switchUserRole(role)
|
||||
setRole(role)
|
||||
setUser(updated)
|
||||
}
|
||||
|
||||
const role: UserRole = user?.role ?? 'admin'
|
||||
|
||||
return {
|
||||
user,
|
||||
role,
|
||||
isAuthenticated,
|
||||
isLoading,
|
||||
error,
|
||||
login,
|
||||
loginWithSSO,
|
||||
logout,
|
||||
switchRole,
|
||||
canManageUsers: canManageUsers(role),
|
||||
canApproveLabels: canApproveLabels(role),
|
||||
canCreateProject: canCreateProject(role),
|
||||
}
|
||||
}
|
||||
36
src/hooks/useAutoSave.ts
Normal file
36
src/hooks/useAutoSave.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import { useEffect } from 'react'
|
||||
import * as annotationService from '@/services/annotationService'
|
||||
import { useAnnotationStore } from '@/stores/annotationStore'
|
||||
|
||||
export function useAutoSave(projectId?: string, imageId?: string, intervalMs = 2500) {
|
||||
const isDirty = useAnnotationStore((s) => s.isDirty)
|
||||
const shapes = useAnnotationStore((s) => s.shapes)
|
||||
const classificationLabelId = useAnnotationStore((s) => s.classificationLabelId)
|
||||
const flags = useAnnotationStore((s) => s.flags)
|
||||
const markSaved = useAnnotationStore((s) => s.markSaved)
|
||||
const lastSavedAt = useAnnotationStore((s) => s.lastSavedAt)
|
||||
|
||||
useEffect(() => {
|
||||
if (!projectId || !imageId || !isDirty) return
|
||||
|
||||
const timer = window.setTimeout(async () => {
|
||||
try {
|
||||
await annotationService.saveAnnotation(projectId, imageId, {
|
||||
classificationLabelId,
|
||||
flags,
|
||||
shapes,
|
||||
})
|
||||
markSaved('Vừa lưu 1 giây trước')
|
||||
} catch {
|
||||
// Bỏ qua lỗi tự động lưu tạm thời
|
||||
}
|
||||
}, intervalMs)
|
||||
|
||||
return () => window.clearTimeout(timer)
|
||||
}, [projectId, imageId, isDirty, shapes, classificationLabelId, flags, intervalMs, markSaved])
|
||||
|
||||
return {
|
||||
isDirty,
|
||||
lastSavedAt,
|
||||
}
|
||||
}
|
||||
29
src/hooks/useCanvas.ts
Normal file
29
src/hooks/useCanvas.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import { useCanvasStore } from '@/stores/canvasStore'
|
||||
|
||||
export function useCanvas() {
|
||||
const store = useCanvasStore()
|
||||
|
||||
return {
|
||||
activeTool: store.activeTool,
|
||||
zoom: store.zoom,
|
||||
zoomPercent: Math.round(store.zoom * 100),
|
||||
pan: store.pan,
|
||||
showBoxes: store.showBoxes,
|
||||
showMask: store.showMask,
|
||||
maskOpacity: store.maskOpacity,
|
||||
vertexEditMode: store.vertexEditMode,
|
||||
setActiveTool: store.setActiveTool,
|
||||
setZoom: store.setZoom,
|
||||
setPan: store.setPan,
|
||||
setShowBoxes: store.setShowBoxes,
|
||||
toggleShowBoxes: store.toggleShowBoxes,
|
||||
setShowMask: store.setShowMask,
|
||||
toggleShowMask: store.toggleShowMask,
|
||||
setMaskOpacity: store.setMaskOpacity,
|
||||
setVertexEditMode: store.setVertexEditMode,
|
||||
toggleVertexEditMode: store.toggleVertexEditMode,
|
||||
zoomIn: store.zoomIn,
|
||||
zoomOut: store.zoomOut,
|
||||
resetZoom: store.resetZoom,
|
||||
}
|
||||
}
|
||||
17
src/hooks/useDebounce.ts
Normal file
17
src/hooks/useDebounce.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import { useEffect, useState } from 'react'
|
||||
|
||||
export function useDebounce<T>(value: T, delayMs = 250): T {
|
||||
const [debouncedValue, setDebouncedValue] = useState<T>(value)
|
||||
|
||||
useEffect(() => {
|
||||
const timer = window.setTimeout(() => {
|
||||
setDebouncedValue(value)
|
||||
}, delayMs)
|
||||
|
||||
return () => {
|
||||
window.clearTimeout(timer)
|
||||
}
|
||||
}, [value, delayMs])
|
||||
|
||||
return debouncedValue
|
||||
}
|
||||
47
src/hooks/useImageNavigation.ts
Normal file
47
src/hooks/useImageNavigation.ts
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import { useNavigate } from 'react-router-dom'
|
||||
import { ImageItem } from '@/types'
|
||||
|
||||
export function useImageNavigation(
|
||||
projectId: string,
|
||||
images: ImageItem[],
|
||||
currentImageId?: string
|
||||
) {
|
||||
const navigate = useNavigate()
|
||||
|
||||
const currentIndex = images.findIndex((img) => img.id === currentImageId)
|
||||
const resolvedIndex = currentIndex >= 0 ? currentIndex : 0
|
||||
|
||||
const currentImage = images[resolvedIndex] ?? null
|
||||
const prevImage = resolvedIndex > 0 ? (images[resolvedIndex - 1] ?? null) : null
|
||||
const nextImage =
|
||||
resolvedIndex < images.length - 1 ? (images[resolvedIndex + 1] ?? null) : null
|
||||
|
||||
const goToImage = (imageId: string) => {
|
||||
navigate(`/projects/${projectId}/annotate/${imageId}`)
|
||||
}
|
||||
|
||||
const goToPrev = () => {
|
||||
if (prevImage) {
|
||||
goToImage(prevImage.id)
|
||||
}
|
||||
}
|
||||
|
||||
const goToNext = () => {
|
||||
if (nextImage) {
|
||||
goToImage(nextImage.id)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
currentImage,
|
||||
currentIndex: resolvedIndex,
|
||||
totalCount: images.length,
|
||||
hasPrev: Boolean(prevImage),
|
||||
hasNext: Boolean(nextImage),
|
||||
prevImage,
|
||||
nextImage,
|
||||
goToImage,
|
||||
goToPrev,
|
||||
goToNext,
|
||||
}
|
||||
}
|
||||
62
src/hooks/useImages.ts
Normal file
62
src/hooks/useImages.ts
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
import { useState } from 'react'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import * as imageService from '@/services/imageService'
|
||||
import { ImageAnnotationStatus } from '@/types'
|
||||
|
||||
export function useImages(projectId?: string) {
|
||||
const queryClient = useQueryClient()
|
||||
const resolvedProjectId = projectId || 'proj-traffic-det'
|
||||
|
||||
const [statusFilter, setStatusFilter] = useState<ImageAnnotationStatus | 'all'>('all')
|
||||
const [assigneeFilter, setAssigneeFilter] = useState<string>('all')
|
||||
const [search, setSearch] = useState<string>('')
|
||||
|
||||
const imagesQuery = useQuery({
|
||||
queryKey: [
|
||||
'project-images',
|
||||
resolvedProjectId,
|
||||
{ status: statusFilter, assigneeId: assigneeFilter, search },
|
||||
],
|
||||
queryFn: () =>
|
||||
imageService.getProjectImages(resolvedProjectId, {
|
||||
status: statusFilter,
|
||||
assigneeId: assigneeFilter,
|
||||
search,
|
||||
}),
|
||||
enabled: Boolean(resolvedProjectId),
|
||||
})
|
||||
|
||||
const uploadMutation = useMutation({
|
||||
mutationFn: (files: { fileName: string; url?: string; width?: number; height?: number }[]) =>
|
||||
imageService.uploadImages(resolvedProjectId, files),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['project-images', resolvedProjectId] })
|
||||
queryClient.invalidateQueries({ queryKey: ['project', resolvedProjectId] })
|
||||
queryClient.invalidateQueries({ queryKey: ['projects'] })
|
||||
},
|
||||
})
|
||||
|
||||
const updateStatusMutation = useMutation({
|
||||
mutationFn: ({ imageId, status }: { imageId: string; status: ImageAnnotationStatus }) =>
|
||||
imageService.updateImageStatus(resolvedProjectId, imageId, status),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['project-images', resolvedProjectId] })
|
||||
queryClient.invalidateQueries({ queryKey: ['project', resolvedProjectId] })
|
||||
queryClient.invalidateQueries({ queryKey: ['projects'] })
|
||||
},
|
||||
})
|
||||
|
||||
return {
|
||||
images: imagesQuery.data ?? [],
|
||||
isLoading: imagesQuery.isLoading,
|
||||
statusFilter,
|
||||
assigneeFilter,
|
||||
search,
|
||||
setStatusFilter,
|
||||
setAssigneeFilter,
|
||||
setSearch,
|
||||
uploadImages: uploadMutation.mutateAsync,
|
||||
isUploading: uploadMutation.isPending,
|
||||
updateImageStatus: updateStatusMutation.mutateAsync,
|
||||
}
|
||||
}
|
||||
147
src/hooks/useKeyboardShortcuts.ts
Normal file
147
src/hooks/useKeyboardShortcuts.ts
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
import { useEffect } from 'react'
|
||||
import { useAnnotationStore } from '@/stores/annotationStore'
|
||||
import { useCanvasStore } from '@/stores/canvasStore'
|
||||
import { LabelClass } from '@/types'
|
||||
|
||||
export interface KeyboardShortcutsOptions {
|
||||
classes?: LabelClass[]
|
||||
onSave?: () => void
|
||||
onSubmit?: () => void
|
||||
onPrevImage?: () => void
|
||||
onNextImage?: () => void
|
||||
isClassification?: boolean
|
||||
enabled?: boolean
|
||||
}
|
||||
|
||||
export function useKeyboardShortcuts({
|
||||
classes = [],
|
||||
onSave,
|
||||
onSubmit,
|
||||
onPrevImage,
|
||||
onNextImage,
|
||||
isClassification = false,
|
||||
enabled = true,
|
||||
}: KeyboardShortcutsOptions = {}) {
|
||||
const setActiveTool = useCanvasStore((s) => s.setActiveTool)
|
||||
const selectedShapeId = useAnnotationStore((s) => s.selectedShapeId)
|
||||
const deleteShape = useAnnotationStore((s) => s.deleteShape)
|
||||
const updateShape = useAnnotationStore((s) => s.updateShape)
|
||||
const setActiveLabelId = useAnnotationStore((s) => s.setActiveLabelId)
|
||||
const setClassificationLabel = useAnnotationStore((s) => s.setClassificationLabel)
|
||||
const undo = useAnnotationStore((s) => s.undo)
|
||||
const redo = useAnnotationStore((s) => s.redo)
|
||||
|
||||
useEffect(() => {
|
||||
if (!enabled) return
|
||||
|
||||
const handleKeyDown = (event: KeyboardEvent) => {
|
||||
const target = event.target as HTMLElement | null
|
||||
if (
|
||||
target &&
|
||||
(target.tagName === 'INPUT' ||
|
||||
target.tagName === 'TEXTAREA' ||
|
||||
target.tagName === 'SELECT' ||
|
||||
target.isContentEditable)
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
const key = event.key.toLowerCase()
|
||||
|
||||
// Ctrl+S / Cmd+S: Lưu
|
||||
if ((event.ctrlKey || event.metaKey) && key === 's') {
|
||||
event.preventDefault()
|
||||
onSave?.()
|
||||
return
|
||||
}
|
||||
|
||||
// Ctrl+Z / Cmd+Z: Undo / Redo
|
||||
if ((event.ctrlKey || event.metaKey) && key === 'z') {
|
||||
event.preventDefault()
|
||||
if (event.shiftKey) {
|
||||
redo()
|
||||
} else {
|
||||
undo()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Phím tắt công cụ: V (Select), R/W (BBox), P (Polygon)
|
||||
if (!event.ctrlKey && !event.metaKey && !event.altKey) {
|
||||
if (key === 'v') {
|
||||
setActiveTool('select')
|
||||
return
|
||||
}
|
||||
if (key === 'r' || key === 'w') {
|
||||
setActiveTool('bbox')
|
||||
return
|
||||
}
|
||||
if (key === 'p') {
|
||||
setActiveTool('polygon')
|
||||
return
|
||||
}
|
||||
|
||||
// A / ArrowLeft: Ảnh trước, D / ArrowRight: Ảnh tiếp
|
||||
if (key === 'a' || event.key === 'ArrowLeft') {
|
||||
onPrevImage?.()
|
||||
return
|
||||
}
|
||||
if (key === 'd' || event.key === 'ArrowRight') {
|
||||
onNextImage?.()
|
||||
return
|
||||
}
|
||||
|
||||
// Enter: Nộp duyệt hoặc xác nhận
|
||||
if (event.key === 'Enter' && onSubmit) {
|
||||
event.preventDefault()
|
||||
onSubmit()
|
||||
return
|
||||
}
|
||||
|
||||
// Delete / Backspace: Xóa shape đang chọn
|
||||
if ((event.key === 'Delete' || event.key === 'Backspace') && selectedShapeId) {
|
||||
event.preventDefault()
|
||||
deleteShape(selectedShapeId)
|
||||
return
|
||||
}
|
||||
|
||||
// Phím số 1-9: Chọn lớp nhãn
|
||||
if (/^[1-9]$/.test(key)) {
|
||||
const idx = parseInt(key, 10) - 1
|
||||
const targetClass = classes[idx]
|
||||
if (targetClass) {
|
||||
setActiveLabelId(targetClass.id)
|
||||
if (isClassification) {
|
||||
setClassificationLabel(targetClass.id)
|
||||
} else if (selectedShapeId) {
|
||||
updateShape(selectedShapeId, {
|
||||
labelId: targetClass.id,
|
||||
labelName: targetClass.name,
|
||||
color: targetClass.color,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('keydown', handleKeyDown)
|
||||
return () => window.removeEventListener('keydown', handleKeyDown)
|
||||
}, [
|
||||
enabled,
|
||||
classes,
|
||||
isClassification,
|
||||
selectedShapeId,
|
||||
setActiveTool,
|
||||
deleteShape,
|
||||
updateShape,
|
||||
setActiveLabelId,
|
||||
setClassificationLabel,
|
||||
undo,
|
||||
redo,
|
||||
onSave,
|
||||
onSubmit,
|
||||
onPrevImage,
|
||||
onNextImage,
|
||||
])
|
||||
}
|
||||
48
src/hooks/useProjectDetail.ts
Normal file
48
src/hooks/useProjectDetail.ts
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import * as exportService from '@/services/exportService'
|
||||
import * as labelService from '@/services/labelService'
|
||||
import * as projectService from '@/services/projectService'
|
||||
|
||||
export function useProjectDetail(projectId?: string) {
|
||||
const queryClient = useQueryClient()
|
||||
const resolvedId = projectId || 'proj-traffic-det'
|
||||
|
||||
const projectQuery = useQuery({
|
||||
queryKey: ['project', resolvedId],
|
||||
queryFn: () => projectService.getProjectById(resolvedId),
|
||||
enabled: Boolean(resolvedId),
|
||||
})
|
||||
|
||||
const createLabelMutation = useMutation({
|
||||
mutationFn: (input: { name: string; color?: string }) =>
|
||||
labelService.createLabel(resolvedId, input),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['project', resolvedId] })
|
||||
queryClient.invalidateQueries({ queryKey: ['projects'] })
|
||||
},
|
||||
})
|
||||
|
||||
const deleteLabelMutation = useMutation({
|
||||
mutationFn: (labelId: string) => labelService.deleteLabel(resolvedId, labelId),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['project', resolvedId] })
|
||||
queryClient.invalidateQueries({ queryKey: ['projects'] })
|
||||
},
|
||||
})
|
||||
|
||||
const exportMutation = useMutation({
|
||||
mutationFn: (format: exportService.ExportFormat = 'coco_json') =>
|
||||
exportService.exportProjectLabels(resolvedId, format),
|
||||
})
|
||||
|
||||
return {
|
||||
project: projectQuery.data,
|
||||
isLoading: projectQuery.isLoading,
|
||||
isError: projectQuery.isError,
|
||||
refetch: projectQuery.refetch,
|
||||
createLabel: createLabelMutation.mutateAsync,
|
||||
deleteLabel: deleteLabelMutation.mutateAsync,
|
||||
exportDataset: exportMutation.mutateAsync,
|
||||
isExporting: exportMutation.isPending,
|
||||
}
|
||||
}
|
||||
97
src/hooks/useProjects.ts
Normal file
97
src/hooks/useProjects.ts
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import * as projectService from '@/services/projectService'
|
||||
import { useProjectStore } from '@/stores/projectStore'
|
||||
import { CreateProjectInput, Project } from '@/types'
|
||||
|
||||
export function useProjects() {
|
||||
const queryClient = useQueryClient()
|
||||
const {
|
||||
searchQuery,
|
||||
taskTypeFilter,
|
||||
statusFilter,
|
||||
selectedProjectId,
|
||||
setSearchQuery,
|
||||
setTaskTypeFilter,
|
||||
setStatusFilter,
|
||||
setSelectedProjectId,
|
||||
resetFilters,
|
||||
} = useProjectStore()
|
||||
|
||||
const projectsQuery = useQuery({
|
||||
queryKey: ['projects', { search: searchQuery, taskType: taskTypeFilter, status: statusFilter }],
|
||||
queryFn: () =>
|
||||
projectService.getProjects({
|
||||
search: searchQuery,
|
||||
taskType: taskTypeFilter,
|
||||
status: statusFilter,
|
||||
}),
|
||||
})
|
||||
|
||||
const allProjectsQuery = useQuery({
|
||||
queryKey: ['projects', 'all'],
|
||||
queryFn: () => projectService.getProjects(),
|
||||
})
|
||||
|
||||
const activitiesQuery = useQuery({
|
||||
queryKey: ['activities'],
|
||||
queryFn: () => projectService.getRecentActivities(),
|
||||
})
|
||||
|
||||
const createProjectMutation = useMutation({
|
||||
mutationFn: (input: CreateProjectInput) => projectService.createProject(input),
|
||||
onSuccess: (created) => {
|
||||
setSelectedProjectId(created.id)
|
||||
queryClient.invalidateQueries({ queryKey: ['projects'] })
|
||||
queryClient.invalidateQueries({ queryKey: ['activities'] })
|
||||
},
|
||||
})
|
||||
|
||||
const updateProjectMutation = useMutation({
|
||||
mutationFn: ({ projectId, updates }: { projectId: string; updates: Partial<Project> }) =>
|
||||
projectService.updateProject(projectId, updates),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['projects'] })
|
||||
},
|
||||
})
|
||||
|
||||
const deleteProjectMutation = useMutation({
|
||||
mutationFn: (projectId: string) => projectService.deleteProject(projectId),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['projects'] })
|
||||
},
|
||||
})
|
||||
|
||||
const projects = projectsQuery.data ?? []
|
||||
const allProjects = allProjectsQuery.data ?? projects
|
||||
|
||||
const totalImages = allProjects.reduce((acc, p) => acc + p.stats.totalImages, 0)
|
||||
const completedImages = allProjects.reduce((acc, p) => acc + p.stats.completed, 0)
|
||||
const pendingReviewImages = allProjects.reduce((acc, p) => acc + p.stats.pendingReview, 0)
|
||||
|
||||
return {
|
||||
projects,
|
||||
allProjects,
|
||||
activities: activitiesQuery.data ?? [],
|
||||
isLoading: projectsQuery.isLoading,
|
||||
isError: projectsQuery.isError,
|
||||
searchQuery,
|
||||
taskTypeFilter,
|
||||
statusFilter,
|
||||
selectedProjectId,
|
||||
setSearchQuery,
|
||||
setTaskTypeFilter,
|
||||
setStatusFilter,
|
||||
setSelectedProjectId,
|
||||
resetFilters,
|
||||
createProject: createProjectMutation.mutateAsync,
|
||||
isCreating: createProjectMutation.isPending,
|
||||
updateProject: updateProjectMutation.mutateAsync,
|
||||
deleteProject: deleteProjectMutation.mutateAsync,
|
||||
summaryStats: {
|
||||
totalProjects: allProjects.length,
|
||||
totalImages,
|
||||
completedImages,
|
||||
pendingReviewImages,
|
||||
},
|
||||
}
|
||||
}
|
||||
79
src/hooks/useUsers.ts
Normal file
79
src/hooks/useUsers.ts
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
import { useState } from 'react'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import * as userService from '@/services/userService'
|
||||
import { InviteMemberInput, UserRole, UserStatus } from '@/types'
|
||||
|
||||
export function useUsers() {
|
||||
const queryClient = useQueryClient()
|
||||
const [search, setSearch] = useState('')
|
||||
const [roleFilter, setRoleFilter] = useState<UserRole | 'all'>('all')
|
||||
const [statusFilter, setStatusFilter] = useState<UserStatus | 'all'>('all')
|
||||
|
||||
const membersQuery = useQuery({
|
||||
queryKey: ['members', { search, role: roleFilter, status: statusFilter }],
|
||||
queryFn: () =>
|
||||
userService.getMembers({
|
||||
search,
|
||||
role: roleFilter,
|
||||
status: statusFilter,
|
||||
}),
|
||||
})
|
||||
|
||||
const allMembersQuery = useQuery({
|
||||
queryKey: ['members', 'all'],
|
||||
queryFn: () => userService.getMembers(),
|
||||
})
|
||||
|
||||
const permissionsQuery = useQuery({
|
||||
queryKey: ['role-permissions'],
|
||||
queryFn: () => userService.getRolePermissions(),
|
||||
})
|
||||
|
||||
const inviteMutation = useMutation({
|
||||
mutationFn: (input: InviteMemberInput) => userService.inviteMember(input),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['members'] })
|
||||
},
|
||||
})
|
||||
|
||||
const updateRoleMutation = useMutation({
|
||||
mutationFn: ({ memberId, role }: { memberId: string; role: UserRole }) =>
|
||||
userService.updateMemberRole(memberId, role),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['members'] })
|
||||
},
|
||||
})
|
||||
|
||||
const toggleStatusMutation = useMutation({
|
||||
mutationFn: (memberId: string) => userService.toggleMemberStatus(memberId),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['members'] })
|
||||
},
|
||||
})
|
||||
|
||||
const allMembers = allMembersQuery.data ?? []
|
||||
|
||||
return {
|
||||
members: membersQuery.data ?? [],
|
||||
allMembers,
|
||||
rolePermissions: permissionsQuery.data ?? [],
|
||||
isLoading: membersQuery.isLoading,
|
||||
search,
|
||||
roleFilter,
|
||||
statusFilter,
|
||||
setSearch,
|
||||
setRoleFilter,
|
||||
setStatusFilter,
|
||||
inviteMember: inviteMutation.mutateAsync,
|
||||
isInviting: inviteMutation.isPending,
|
||||
updateMemberRole: updateRoleMutation.mutateAsync,
|
||||
toggleMemberStatus: toggleStatusMutation.mutateAsync,
|
||||
counts: {
|
||||
total: allMembers.length,
|
||||
admins: allMembers.filter((m) => m.role === 'admin').length,
|
||||
managers: allMembers.filter((m) => m.role === 'manager').length,
|
||||
annotators: allMembers.filter((m) => m.role === 'annotator').length,
|
||||
reviewers: allMembers.filter((m) => m.role === 'reviewer').length,
|
||||
},
|
||||
}
|
||||
}
|
||||
18
src/layouts/AnnotatorLayout.tsx
Normal file
18
src/layouts/AnnotatorLayout.tsx
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import React from 'react'
|
||||
import { Outlet } from 'react-router-dom'
|
||||
import { Sidebar } from './components/Sidebar/Sidebar'
|
||||
import { Header } from './components/Header/Header'
|
||||
|
||||
export const AnnotatorLayout: React.FC<{ children?: React.ReactNode }> = ({
|
||||
children,
|
||||
}) => {
|
||||
return (
|
||||
<div className="flex h-screen w-screen overflow-hidden bg-[#F8FAFC] text-slate-900">
|
||||
<Sidebar />
|
||||
<div className="flex-1 flex flex-col min-w-0 h-full overflow-hidden">
|
||||
<Header />
|
||||
<main className="flex-1 overflow-hidden">{children || <Outlet />}</main>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
67
src/layouts/AuthLayout.tsx
Normal file
67
src/layouts/AuthLayout.tsx
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
import React from 'react'
|
||||
import { Outlet, Link } from 'react-router-dom'
|
||||
import { showToast } from '../components/feedback/Toast'
|
||||
|
||||
export const AuthLayout: React.FC<{ children?: React.ReactNode }> = ({ children }) => {
|
||||
return (
|
||||
<div className="min-h-screen bg-[#FAF9F6] flex flex-col justify-between text-slate-900">
|
||||
{/* Top Bar */}
|
||||
<header className="w-full px-6 sm:px-10 py-5 flex items-center justify-between border-b border-slate-200/60 bg-white/80 backdrop-blur-sm">
|
||||
<Link to="/login" className="flex items-center gap-3">
|
||||
<div className="flex h-8 w-8 items-center justify-center rounded-lg bg-[#C95C3C] text-white shadow-sm">
|
||||
<svg
|
||||
className="h-4 w-4"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
strokeWidth={2.2}
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
d="M4 8V6a2 2 0 012-2h2M4 16v2a2 2 0 002 2h2m8-16h2a2 2 0 012 2v2m-4 12h2a2 2 0 002-2v-2"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
<span className="text-xl font-bold tracking-tight text-slate-900">
|
||||
danable
|
||||
</span>
|
||||
<span className="hidden sm:inline-block rounded-full border border-slate-200 bg-slate-50 px-2.5 py-0.5 text-[10px] font-semibold uppercase tracking-wider text-slate-500">
|
||||
NỀN TẢNG DỮ LIỆU CHO AI
|
||||
</span>
|
||||
</Link>
|
||||
|
||||
<div className="text-xs text-slate-500">
|
||||
Chưa có tài khoản?{' '}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() =>
|
||||
showToast.info('Vui lòng liên hệ admin@danable.vn để được cấp tài khoản')
|
||||
}
|
||||
className="font-semibold text-[#C95C3C] hover:underline"
|
||||
>
|
||||
Liên hệ quản trị viên ↗
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{/* Main Content */}
|
||||
<main className="flex-1 flex items-center justify-center p-4 sm:p-8">
|
||||
{children || <Outlet />}
|
||||
</main>
|
||||
|
||||
{/* Footer */}
|
||||
<footer className="w-full px-6 sm:px-10 py-4 border-t border-slate-200/60 bg-white/60 flex flex-col sm:flex-row items-center justify-between gap-2 text-xs text-slate-400">
|
||||
<div>© 2026 danable · Hệ thống gán nhãn dữ liệu thị giác máy tính</div>
|
||||
<div className="flex items-center gap-4">
|
||||
<span className="inline-flex items-center gap-1.5 text-slate-500">
|
||||
<span className="h-1.5 w-1.5 rounded-full bg-emerald-500" />
|
||||
Máy chủ ổn định (v2.4.0)
|
||||
</span>
|
||||
<span>Bảo mật</span>
|
||||
<span>Điều khoản</span>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
20
src/layouts/DashboardLayout.tsx
Normal file
20
src/layouts/DashboardLayout.tsx
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import React from 'react'
|
||||
import { Outlet } from 'react-router-dom'
|
||||
import { Sidebar } from './components/Sidebar/Sidebar'
|
||||
import { Header } from './components/Header/Header'
|
||||
|
||||
export const DashboardLayout: React.FC<{ children?: React.ReactNode }> = ({
|
||||
children,
|
||||
}) => {
|
||||
return (
|
||||
<div className="flex min-h-screen bg-[#F8FAFC] text-slate-900">
|
||||
<Sidebar />
|
||||
<div className="flex-1 flex flex-col min-w-0">
|
||||
<Header />
|
||||
<main className="flex-1 overflow-y-auto p-6 lg:p-8">
|
||||
<div className="mx-auto max-w-7xl">{children || <Outlet />}</div>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
90
src/layouts/components/Header/Breadcrumb.tsx
Normal file
90
src/layouts/components/Header/Breadcrumb.tsx
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
import React from 'react'
|
||||
import { Link, useLocation } from 'react-router-dom'
|
||||
|
||||
export interface BreadcrumbItem {
|
||||
label: string
|
||||
to?: string
|
||||
}
|
||||
|
||||
export interface BreadcrumbProps {
|
||||
items?: BreadcrumbItem[]
|
||||
}
|
||||
|
||||
const PROJECT_NAMES: Record<string, string> = {
|
||||
'proj-1': 'Phương tiện đô thị',
|
||||
'proj-2': 'Giao thông đô thị',
|
||||
'proj-3': 'Phân vùng đường phố',
|
||||
}
|
||||
|
||||
export const Breadcrumb: React.FC<BreadcrumbProps> = ({ items }) => {
|
||||
const location = useLocation()
|
||||
|
||||
const resolvedItems: BreadcrumbItem[] = React.useMemo(() => {
|
||||
if (items && items.length > 0) return items
|
||||
|
||||
const path = location.pathname
|
||||
if (path.startsWith('/users')) {
|
||||
return [
|
||||
{ label: 'Không gian làm việc', to: '/projects' },
|
||||
{ label: 'Quản lý người dùng' },
|
||||
]
|
||||
}
|
||||
|
||||
const parts = path.split('/').filter(Boolean)
|
||||
if (parts[0] === 'projects') {
|
||||
const list: BreadcrumbItem[] = [{ label: 'Dự án', to: '/projects' }]
|
||||
if (parts[1]) {
|
||||
const projName = PROJECT_NAMES[parts[1]] || 'Giao thông đô thị'
|
||||
list.push({ label: projName, to: `/projects/${parts[1]}` })
|
||||
if (parts[2] === 'annotate') {
|
||||
list.push({ label: 'Gán nhãn' })
|
||||
} else {
|
||||
list.push({ label: 'Tổng quan' })
|
||||
}
|
||||
} else {
|
||||
list.push({ label: 'Danh sách dự án' })
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
return [{ label: 'Dự án', to: '/projects' }, { label: 'Tổng quan' }]
|
||||
}, [items, location.pathname])
|
||||
|
||||
return (
|
||||
<nav className="flex items-center gap-2 text-xs text-slate-500">
|
||||
<svg
|
||||
className="h-4 w-4 text-slate-400 shrink-0"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
strokeWidth={1.8}
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"
|
||||
/>
|
||||
</svg>
|
||||
{resolvedItems.map((item, idx) => {
|
||||
const isLast = idx === resolvedItems.length - 1
|
||||
return (
|
||||
<React.Fragment key={idx}>
|
||||
{idx > 0 && <span className="text-slate-300">/</span>}
|
||||
{item.to && !isLast ? (
|
||||
<Link
|
||||
to={item.to}
|
||||
className="hover:text-slate-800 transition-colors font-medium"
|
||||
>
|
||||
{item.label}
|
||||
</Link>
|
||||
) : (
|
||||
<span className={isLast ? 'font-medium text-slate-700' : ''}>
|
||||
{item.label}
|
||||
</span>
|
||||
)}
|
||||
</React.Fragment>
|
||||
)
|
||||
})}
|
||||
</nav>
|
||||
)
|
||||
}
|
||||
22
src/layouts/components/Header/Header.tsx
Normal file
22
src/layouts/components/Header/Header.tsx
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import React from 'react'
|
||||
import { Breadcrumb, BreadcrumbItem } from './Breadcrumb'
|
||||
import { SystemStatus } from './SystemStatus'
|
||||
import { NotificationBell } from './NotificationBell'
|
||||
import { UserMenu } from './UserMenu'
|
||||
|
||||
export interface HeaderProps {
|
||||
breadcrumbItems?: BreadcrumbItem[]
|
||||
}
|
||||
|
||||
export const Header: React.FC<HeaderProps> = ({ breadcrumbItems }) => {
|
||||
return (
|
||||
<header className="h-14 shrink-0 bg-white border-b border-slate-200/80 px-6 flex items-center justify-between sticky top-0 z-20">
|
||||
<Breadcrumb items={breadcrumbItems} />
|
||||
<div className="flex items-center gap-4">
|
||||
<SystemStatus />
|
||||
<NotificationBell />
|
||||
<UserMenu />
|
||||
</div>
|
||||
</header>
|
||||
)
|
||||
}
|
||||
120
src/layouts/components/Header/NotificationBell.tsx
Normal file
120
src/layouts/components/Header/NotificationBell.tsx
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
import React, { useState, useRef, useEffect } from 'react'
|
||||
|
||||
interface NotificationItem {
|
||||
id: string
|
||||
title: string
|
||||
time: string
|
||||
unread?: boolean
|
||||
}
|
||||
|
||||
const MOCK_NOTIFICATIONS: NotificationItem[] = [
|
||||
{
|
||||
id: 'n1',
|
||||
title: 'Hà Linh đã gửi 18 ảnh chờ duyệt trong dự án Giao thông đô thị',
|
||||
time: '5 phút trước',
|
||||
unread: true,
|
||||
},
|
||||
{
|
||||
id: 'n2',
|
||||
title: 'Tuấn Nam hoàn thành gán nhãn lô #04 (120 ảnh)',
|
||||
time: '1 giờ trước',
|
||||
unread: true,
|
||||
},
|
||||
{
|
||||
id: 'n3',
|
||||
title: 'Xuất bộ nhãn YOLOv8 thành công',
|
||||
time: 'Hôm qua',
|
||||
unread: false,
|
||||
},
|
||||
]
|
||||
|
||||
export const NotificationBell: React.FC = () => {
|
||||
const [open, setOpen] = useState(false)
|
||||
const [notifications, setNotifications] = useState(MOCK_NOTIFICATIONS)
|
||||
const ref = useRef<HTMLDivElement>(null)
|
||||
|
||||
useEffect(() => {
|
||||
const handleClickOutside = (event: MouseEvent) => {
|
||||
if (ref.current && !ref.current.contains(event.target as Node)) {
|
||||
setOpen(false)
|
||||
}
|
||||
}
|
||||
document.addEventListener('mousedown', handleClickOutside)
|
||||
return () => document.removeEventListener('mousedown', handleClickOutside)
|
||||
}, [])
|
||||
|
||||
const unreadCount = notifications.filter((n) => n.unread).length
|
||||
|
||||
const markAllRead = () => {
|
||||
setNotifications((prev) => prev.map((n) => ({ ...n, unread: false })))
|
||||
}
|
||||
|
||||
return (
|
||||
<div ref={ref} className="relative">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setOpen((prev) => !prev)}
|
||||
className="relative rounded-full p-2 text-slate-500 hover:bg-slate-100 hover:text-slate-800 transition-colors"
|
||||
aria-label="Thông báo"
|
||||
>
|
||||
<svg
|
||||
className="h-4 w-4"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
strokeWidth={1.9}
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
d="M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9"
|
||||
/>
|
||||
</svg>
|
||||
{unreadCount > 0 && (
|
||||
<span className="absolute top-1.5 right-1.5 h-2 w-2 rounded-full bg-[#C95C3C] ring-2 ring-white" />
|
||||
)}
|
||||
</button>
|
||||
|
||||
{open && (
|
||||
<div className="absolute right-0 z-50 mt-2 w-80 rounded-2xl border border-slate-200 bg-white shadow-xl overflow-hidden">
|
||||
<div className="flex items-center justify-between border-b border-slate-100 px-4 py-3">
|
||||
<span className="text-xs font-semibold text-slate-900">
|
||||
Thông báo ({unreadCount})
|
||||
</span>
|
||||
{unreadCount > 0 && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={markAllRead}
|
||||
className="text-[11px] font-medium text-[#C95C3C] hover:underline"
|
||||
>
|
||||
Đánh dấu đã đọc
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<div className="divide-y divide-slate-100 max-h-72 overflow-y-auto">
|
||||
{notifications.map((item) => (
|
||||
<div
|
||||
key={item.id}
|
||||
className="px-4 py-3 hover:bg-slate-50 transition-colors"
|
||||
>
|
||||
<div className="flex items-start gap-2">
|
||||
{item.unread && (
|
||||
<span className="mt-1.5 h-1.5 w-1.5 rounded-full bg-[#C95C3C] shrink-0" />
|
||||
)}
|
||||
<div>
|
||||
<p className="text-xs text-slate-700 leading-relaxed">
|
||||
{item.title}
|
||||
</p>
|
||||
<span className="mt-1 block text-[11px] text-slate-400">
|
||||
{item.time}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
10
src/layouts/components/Header/SystemStatus.tsx
Normal file
10
src/layouts/components/Header/SystemStatus.tsx
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import React from 'react'
|
||||
|
||||
export const SystemStatus: React.FC = () => {
|
||||
return (
|
||||
<div className="hidden sm:flex items-center gap-2 text-xs text-slate-600">
|
||||
<span className="h-2 w-2 rounded-full bg-emerald-600" />
|
||||
<span>Hệ thống ổn định</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
37
src/layouts/components/Header/UserMenu.tsx
Normal file
37
src/layouts/components/Header/UserMenu.tsx
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import React from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { Dropdown } from '../../../components/ui/Dropdown'
|
||||
import { showToast } from '../../../components/feedback/Toast'
|
||||
|
||||
export const UserMenu: React.FC = () => {
|
||||
const navigate = useNavigate()
|
||||
|
||||
return (
|
||||
<Dropdown
|
||||
align="right"
|
||||
trigger={
|
||||
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-orange-100 text-xs font-bold text-slate-800 hover:ring-2 hover:ring-orange-200 transition-all">
|
||||
MA
|
||||
</div>
|
||||
}
|
||||
items={[
|
||||
{
|
||||
label: 'Hồ sơ cá nhân (Minh Anh)',
|
||||
onClick: () => showToast.info('Đang mở hồ sơ Quản trị viên Minh Anh'),
|
||||
},
|
||||
{
|
||||
label: 'Quản lý người dùng',
|
||||
onClick: () => navigate('/users'),
|
||||
},
|
||||
{
|
||||
label: 'Đăng xuất',
|
||||
danger: true,
|
||||
onClick: () => {
|
||||
showToast.success('Đã đăng xuất thành công')
|
||||
navigate('/login')
|
||||
},
|
||||
},
|
||||
]}
|
||||
/>
|
||||
)
|
||||
}
|
||||
63
src/layouts/components/Sidebar/RecentProjects.tsx
Normal file
63
src/layouts/components/Sidebar/RecentProjects.tsx
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
import React from 'react'
|
||||
import { Link, useLocation } from 'react-router-dom'
|
||||
import clsx from 'clsx'
|
||||
|
||||
interface RecentProjectItem {
|
||||
id: string
|
||||
name: string
|
||||
path: string
|
||||
dotColor: string
|
||||
}
|
||||
|
||||
const RECENT_PROJECTS: RecentProjectItem[] = [
|
||||
{
|
||||
id: 'proj-1',
|
||||
name: 'Phương tiện đô thị',
|
||||
path: '/projects/proj-1',
|
||||
dotColor: 'bg-indigo-500',
|
||||
},
|
||||
{
|
||||
id: 'proj-2',
|
||||
name: 'Giao thông đô thị',
|
||||
path: '/projects/proj-2',
|
||||
dotColor: 'bg-blue-600',
|
||||
},
|
||||
{
|
||||
id: 'proj-3',
|
||||
name: 'Phân vùng đường phố',
|
||||
path: '/projects/proj-3',
|
||||
dotColor: 'bg-violet-500',
|
||||
},
|
||||
]
|
||||
|
||||
export const RecentProjects: React.FC = () => {
|
||||
const location = useLocation()
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="px-2 mb-2 text-[10px] font-bold uppercase tracking-wider text-slate-500">
|
||||
DỰ ÁN GẦN ĐÂY
|
||||
</div>
|
||||
<div className="space-y-0.5">
|
||||
{RECENT_PROJECTS.map((project) => {
|
||||
const isCurrent = location.pathname.startsWith(project.path)
|
||||
return (
|
||||
<Link
|
||||
key={project.id}
|
||||
to={project.path}
|
||||
className={clsx(
|
||||
'flex items-center gap-2.5 rounded-lg px-2.5 py-2 text-xs font-medium transition-colors',
|
||||
isCurrent
|
||||
? 'bg-slate-100 text-slate-900 font-semibold'
|
||||
: 'text-slate-600 hover:bg-slate-50 hover:text-slate-900'
|
||||
)}
|
||||
>
|
||||
<span className={clsx('h-1.5 w-1.5 rounded-full shrink-0', project.dotColor)} />
|
||||
<span className="truncate">{project.name}</span>
|
||||
</Link>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
45
src/layouts/components/Sidebar/Sidebar.tsx
Normal file
45
src/layouts/components/Sidebar/Sidebar.tsx
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import React from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { WorkspaceSelector } from './WorkspaceSelector'
|
||||
import { SidebarNav } from './SidebarNav'
|
||||
import { RecentProjects } from './RecentProjects'
|
||||
import { StorageUsage } from './StorageUsage'
|
||||
import { UserInfo } from './UserInfo'
|
||||
|
||||
export const Sidebar: React.FC = () => {
|
||||
return (
|
||||
<aside className="w-[240px] shrink-0 bg-white border-r border-slate-200/80 flex flex-col justify-between h-screen sticky top-0 px-3.5 py-4 select-none">
|
||||
<div className="space-y-5">
|
||||
{/* Brand Logo */}
|
||||
<Link to="/projects" className="flex items-center gap-2.5 px-1">
|
||||
<div className="flex h-8 w-8 items-center justify-center rounded-lg bg-[#C95C3C] text-white shadow-sm">
|
||||
<svg className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2.2}>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
d="M4 8V6a2 2 0 012-2h2M4 16v2a2 2 0 002 2h2m8-16h2a2 2 0 012 2v2m-4 12h2a2 2 0 002-2v-2"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
<span className="text-xl font-bold tracking-tight text-slate-900">
|
||||
danable
|
||||
</span>
|
||||
</Link>
|
||||
|
||||
{/* Workspace Selector */}
|
||||
<WorkspaceSelector />
|
||||
|
||||
{/* Navigation Links */}
|
||||
<SidebarNav />
|
||||
|
||||
{/* Recent Projects */}
|
||||
<RecentProjects />
|
||||
</div>
|
||||
|
||||
<div className="space-y-4 pt-4">
|
||||
<StorageUsage />
|
||||
<UserInfo />
|
||||
</div>
|
||||
</aside>
|
||||
)
|
||||
}
|
||||
92
src/layouts/components/Sidebar/SidebarNav.tsx
Normal file
92
src/layouts/components/Sidebar/SidebarNav.tsx
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
import React from 'react'
|
||||
import { NavLink, useLocation } from 'react-router-dom'
|
||||
import clsx from 'clsx'
|
||||
|
||||
interface NavItem {
|
||||
to: string
|
||||
label: string
|
||||
badge: number
|
||||
icon: React.ReactNode
|
||||
matchPrefix: string
|
||||
}
|
||||
|
||||
export const SidebarNav: React.FC = () => {
|
||||
const location = useLocation()
|
||||
|
||||
const navItems: NavItem[] = [
|
||||
{
|
||||
to: '/projects',
|
||||
label: 'Dự án',
|
||||
badge: 3,
|
||||
matchPrefix: '/projects',
|
||||
icon: (
|
||||
<svg className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
d="M4 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2V6zM14 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V6zM4 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2v-2zM14 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z"
|
||||
/>
|
||||
</svg>
|
||||
),
|
||||
},
|
||||
{
|
||||
to: '/users',
|
||||
label: 'Người dùng',
|
||||
badge: 8,
|
||||
matchPrefix: '/users',
|
||||
icon: (
|
||||
<svg className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0z"
|
||||
/>
|
||||
</svg>
|
||||
),
|
||||
},
|
||||
]
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="px-2 mb-2 text-[10px] font-bold uppercase tracking-wider text-slate-500">
|
||||
KHÔNG GIAN LÀM VIỆC
|
||||
</div>
|
||||
<nav className="space-y-1">
|
||||
{navItems.map((item) => {
|
||||
const isActive =
|
||||
location.pathname === item.to ||
|
||||
location.pathname.startsWith(item.matchPrefix) ||
|
||||
(item.to === '/projects' && location.pathname === '/')
|
||||
|
||||
return (
|
||||
<NavLink
|
||||
key={item.to}
|
||||
to={item.to}
|
||||
className={clsx(
|
||||
'flex items-center justify-between rounded-xl px-3 py-2.5 text-sm font-medium transition-colors',
|
||||
isActive
|
||||
? 'bg-[#C95C3C] text-white shadow-sm'
|
||||
: 'text-slate-700 hover:bg-slate-100'
|
||||
)}
|
||||
>
|
||||
<div className="flex items-center gap-2.5">
|
||||
<span className={clsx(isActive ? 'text-white' : 'text-slate-500')}>
|
||||
{item.icon}
|
||||
</span>
|
||||
<span>{item.label}</span>
|
||||
</div>
|
||||
<span
|
||||
className={clsx(
|
||||
'text-xs font-semibold',
|
||||
isActive ? 'text-white/90' : 'text-slate-600'
|
||||
)}
|
||||
>
|
||||
{item.badge}
|
||||
</span>
|
||||
</NavLink>
|
||||
)
|
||||
})}
|
||||
</nav>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
21
src/layouts/components/Sidebar/StorageUsage.tsx
Normal file
21
src/layouts/components/Sidebar/StorageUsage.tsx
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import React from 'react'
|
||||
|
||||
export const StorageUsage: React.FC = () => {
|
||||
return (
|
||||
<div className="rounded-xl bg-slate-100/80 border border-slate-200/60 p-3.5">
|
||||
<div className="flex items-center justify-between text-xs font-medium text-slate-700 mb-2">
|
||||
<span>Dung lượng dữ liệu</span>
|
||||
<span className="font-semibold text-slate-900">24%</span>
|
||||
</div>
|
||||
<div className="h-1.5 w-full overflow-hidden rounded-full bg-slate-200">
|
||||
<div
|
||||
className="h-full rounded-full bg-[#3B5BDB]"
|
||||
style={{ width: '24%' }}
|
||||
/>
|
||||
</div>
|
||||
<div className="mt-2 text-[11px] text-slate-500">
|
||||
12 GB / 50 GB đã sử dụng
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
73
src/layouts/components/Sidebar/UserInfo.tsx
Normal file
73
src/layouts/components/Sidebar/UserInfo.tsx
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
import React from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { showToast } from '../../../components/feedback/Toast'
|
||||
|
||||
export const UserInfo: React.FC = () => {
|
||||
const navigate = useNavigate()
|
||||
|
||||
const handleLogout = () => {
|
||||
showToast.success('Đã đăng xuất khỏi phiên làm việc')
|
||||
navigate('/login')
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => showToast.info('Tài liệu hướng dẫn sử dụng danable v1.0')}
|
||||
className="flex w-full items-center gap-2 px-2 py-1.5 text-xs font-medium text-slate-600 hover:text-slate-900 transition-colors"
|
||||
>
|
||||
<svg
|
||||
className="h-4 w-4 text-slate-400"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
strokeWidth={1.8}
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
d="M8.228 9c.549-1.165 2.03-2 3.772-2 2.21 0 4 1.343 4 3 0 1.4-1.278 2.575-3.006 2.907-.542.104-.994.54-.994 1.093m0 3h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
|
||||
/>
|
||||
</svg>
|
||||
<span>Tài liệu & hỗ trợ</span>
|
||||
</button>
|
||||
|
||||
<div className="border-t border-slate-200 pt-3 flex items-center justify-between">
|
||||
<div className="flex items-center gap-2.5 min-w-0">
|
||||
<div className="flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-orange-100 text-xs font-bold text-slate-800">
|
||||
MA
|
||||
</div>
|
||||
<div className="min-w-0">
|
||||
<div className="truncate text-xs font-semibold text-slate-900">
|
||||
Minh Anh
|
||||
</div>
|
||||
<div className="truncate text-[11px] text-slate-500">
|
||||
Quản trị viên
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleLogout}
|
||||
title="Đăng xuất"
|
||||
className="rounded-lg p-1.5 text-slate-400 hover:bg-slate-100 hover:text-slate-700 transition-colors"
|
||||
>
|
||||
<svg
|
||||
className="h-4 w-4"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
strokeWidth={1.8}
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
69
src/layouts/components/Sidebar/WorkspaceSelector.tsx
Normal file
69
src/layouts/components/Sidebar/WorkspaceSelector.tsx
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
import React, { useState } from 'react'
|
||||
import { showToast } from '../../../components/feedback/Toast'
|
||||
|
||||
export const WorkspaceSelector: React.FC = () => {
|
||||
const [open, setOpen] = useState(false)
|
||||
|
||||
return (
|
||||
<div className="relative">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setOpen((prev) => !prev)}
|
||||
className="w-full flex items-center justify-between rounded-xl border border-slate-300/90 bg-white px-3 py-2.5 text-left hover:border-slate-400 transition-colors"
|
||||
>
|
||||
<div className="flex items-center gap-2.5 min-w-0">
|
||||
<div className="flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-indigo-50 text-xs font-bold text-slate-700">
|
||||
VL
|
||||
</div>
|
||||
<div className="min-w-0">
|
||||
<div className="truncate text-sm font-semibold text-slate-900 leading-tight">
|
||||
danable
|
||||
</div>
|
||||
<div className="truncate text-[11px] text-slate-500 mt-0.5">
|
||||
Không gian nhóm
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<svg
|
||||
className="h-4 w-4 text-slate-400 shrink-0"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
strokeWidth={1.8}
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
d="M8 9l4-4 4 4m0 6l-4 4-4-4"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
{open && (
|
||||
<div className="absolute left-0 right-0 z-30 mt-1.5 rounded-xl border border-slate-200 bg-white p-1.5 shadow-lg">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setOpen(false)
|
||||
showToast.info('Đang ở Không gian nhóm danable')
|
||||
}}
|
||||
className="flex w-full items-center justify-between rounded-lg bg-slate-50 px-2.5 py-2 text-xs font-medium text-slate-800"
|
||||
>
|
||||
<span>danable (Không gian nhóm)</span>
|
||||
<span className="text-[#C95C3C] font-bold">✓</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setOpen(false)
|
||||
showToast.info('Đã chuyển sang Không gian cá nhân')
|
||||
}}
|
||||
className="mt-0.5 flex w-full items-center justify-between rounded-lg px-2.5 py-2 text-xs text-slate-600 hover:bg-slate-50"
|
||||
>
|
||||
<span>VisionLab R&D</span>
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
11
src/layouts/components/index.ts
Normal file
11
src/layouts/components/index.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
export * from './Sidebar/Sidebar'
|
||||
export * from './Sidebar/WorkspaceSelector'
|
||||
export * from './Sidebar/SidebarNav'
|
||||
export * from './Sidebar/RecentProjects'
|
||||
export * from './Sidebar/StorageUsage'
|
||||
export * from './Sidebar/UserInfo'
|
||||
export * from './Header/Header'
|
||||
export * from './Header/Breadcrumb'
|
||||
export * from './Header/SystemStatus'
|
||||
export * from './Header/NotificationBell'
|
||||
export * from './Header/UserMenu'
|
||||
11
src/main.tsx
Normal file
11
src/main.tsx
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import React from 'react'
|
||||
import ReactDOM from 'react-dom/client'
|
||||
import App from './App'
|
||||
import './styles/globals.css'
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>
|
||||
)
|
||||
|
||||
167
src/pages/annotator/AnnotatorPage.tsx
Normal file
167
src/pages/annotator/AnnotatorPage.tsx
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
import React, { useEffect } from 'react'
|
||||
import { useParams, useSearchParams } from 'react-router-dom'
|
||||
import toast from 'react-hot-toast'
|
||||
import { TaskType } from '@/types'
|
||||
import { useAnnotatorStore } from './annotatorStore'
|
||||
import { AnnotatorHeader } from './components/header/AnnotatorHeader'
|
||||
import { ImageInfo } from './components/header/ImageInfo'
|
||||
import { ToolBar } from './components/canvas/ToolBar'
|
||||
import { AnnotationCanvas } from './components/canvas/AnnotationCanvas'
|
||||
import { ImageCounter } from './components/navigator/ImageCounter'
|
||||
import { ImageNavigator } from './components/navigator/ImageNavigator'
|
||||
import { ClassificationPanel } from './components/sidebar-right/ClassificationPanel'
|
||||
import { ObjectListPanel } from './components/sidebar-right/ObjectListPanel'
|
||||
import { SegmentationPanel } from './components/sidebar-right/SegmentationPanel'
|
||||
|
||||
export const AnnotatorPage: React.FC = () => {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const [searchParams] = useSearchParams()
|
||||
const taskParam = searchParams.get('task') as TaskType | null
|
||||
|
||||
const project = useAnnotatorStore((s) => s.project)
|
||||
const initProject = useAnnotatorStore((s) => s.initProject)
|
||||
|
||||
useEffect(() => {
|
||||
initProject(id ?? 'proj-1', taskParam ?? undefined)
|
||||
}, [id, taskParam, initProject])
|
||||
|
||||
// Global keyboard shortcuts for fast annotation
|
||||
useEffect(() => {
|
||||
const handleKeyDown = (e: KeyboardEvent) => {
|
||||
const target = e.target as HTMLElement | null
|
||||
if (
|
||||
target &&
|
||||
(target.tagName === 'INPUT' ||
|
||||
target.tagName === 'TEXTAREA' ||
|
||||
target.tagName === 'SELECT')
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
const state = useAnnotatorStore.getState()
|
||||
|
||||
// Undo / Redo
|
||||
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'z') {
|
||||
e.preventDefault()
|
||||
if (e.shiftKey) {
|
||||
state.redo()
|
||||
} else {
|
||||
state.undo()
|
||||
}
|
||||
return
|
||||
}
|
||||
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'y') {
|
||||
e.preventDefault()
|
||||
state.redo()
|
||||
return
|
||||
}
|
||||
|
||||
// 1-4 class selection
|
||||
if (['1', '2', '3', '4'].includes(e.key)) {
|
||||
const idx = Number(e.key) - 1
|
||||
const cls = state.project.classes[idx]
|
||||
if (cls) {
|
||||
if (state.project.taskType === 'classification') {
|
||||
state.setClassificationLabel(cls.id)
|
||||
} else {
|
||||
state.updateSelectedShapeClass(cls.id)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Tool shortcuts
|
||||
const keyLower = e.key.toLowerCase()
|
||||
if (keyLower === 'v') {
|
||||
state.setActiveTool('select')
|
||||
return
|
||||
}
|
||||
if (keyLower === 'b' && state.project.taskType === 'object_detection') {
|
||||
state.setActiveTool('bbox')
|
||||
return
|
||||
}
|
||||
if (keyLower === 'p' && state.project.taskType === 'segmentation') {
|
||||
state.setActiveTool('polygon')
|
||||
return
|
||||
}
|
||||
|
||||
// Enter: close draft polygon or approve classification
|
||||
if (e.key === 'Enter') {
|
||||
if (
|
||||
state.project.taskType === 'segmentation' &&
|
||||
state.draftPolygonPoints.length >= 3
|
||||
) {
|
||||
e.preventDefault()
|
||||
state.closeDraftPolygon()
|
||||
} else if (state.project.taskType === 'classification') {
|
||||
e.preventDefault()
|
||||
state.updateImageStatus('completed')
|
||||
toast.success('Đã duyệt nhãn ảnh hiện tại')
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Escape: cancel draft polygon
|
||||
if (e.key === 'Escape' && state.draftPolygonPoints.length > 0) {
|
||||
state.cancelDraftPolygon()
|
||||
return
|
||||
}
|
||||
|
||||
// Delete / Backspace: remove selected shape
|
||||
if (
|
||||
(e.key === 'Delete' || e.key === 'Backspace') &&
|
||||
state.selectedShapeId &&
|
||||
state.project.taskType !== 'classification'
|
||||
) {
|
||||
e.preventDefault()
|
||||
state.deleteShape(state.selectedShapeId)
|
||||
return
|
||||
}
|
||||
|
||||
// Left / Right arrow keys: navigate images
|
||||
if (e.key === 'ArrowLeft') {
|
||||
state.prevImage()
|
||||
} else if (e.key === 'ArrowRight') {
|
||||
state.nextImage()
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('keydown', handleKeyDown)
|
||||
return () => window.removeEventListener('keydown', handleKeyDown)
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
{/* Top Project Title & Action Buttons */}
|
||||
<AnnotatorHeader />
|
||||
|
||||
{/* Main 2-Column Workspace */}
|
||||
<div className="grid grid-cols-1 gap-4 lg:grid-cols-12 items-start">
|
||||
{/* Left Column: Image Info + Toolbar + Canvas + Navigator */}
|
||||
<div className="overflow-hidden rounded-2xl border border-slate-200/80 bg-white shadow-2xs lg:col-span-8 xl:col-span-9">
|
||||
{/* File Name, Resolution & Image Counter Bar */}
|
||||
<div className="flex items-center justify-between border-b border-slate-100 px-4 py-2.5">
|
||||
<ImageInfo />
|
||||
<ImageCounter />
|
||||
</div>
|
||||
|
||||
{/* Annotation Tools & Zoom Controls */}
|
||||
<ToolBar />
|
||||
|
||||
{/* Interactive SVG + Image Canvas */}
|
||||
<AnnotationCanvas />
|
||||
|
||||
{/* Bottom Hint, Thumbnail Strip & Save/Export Status */}
|
||||
<ImageNavigator />
|
||||
</div>
|
||||
|
||||
{/* Right Column: Task-Specific Panel */}
|
||||
<div className="lg:col-span-4 xl:col-span-3">
|
||||
{project.taskType === 'classification' && <ClassificationPanel />}
|
||||
{project.taskType === 'object_detection' && <ObjectListPanel />}
|
||||
{project.taskType === 'segmentation' && <SegmentationPanel />}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
1174
src/pages/annotator/annotatorStore.ts
Normal file
1174
src/pages/annotator/annotatorStore.ts
Normal file
File diff suppressed because it is too large
Load diff
303
src/pages/annotator/components/canvas/AnnotationCanvas.tsx
Normal file
303
src/pages/annotator/components/canvas/AnnotationCanvas.tsx
Normal file
|
|
@ -0,0 +1,303 @@
|
|||
import React, { useRef, useState } from 'react'
|
||||
import { AnnotationShape, BoundingBox, Point2D } from '@/types'
|
||||
import { normalizeBBox } from '@/utils/canvas'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
import { ImageViewer } from './ImageViewer'
|
||||
import { BoundingBoxTool, ResizeHandleCorner } from './BoundingBoxTool'
|
||||
import { PolygonTool } from './PolygonTool'
|
||||
import { PointTool } from './PointTool'
|
||||
import { SelectTool } from './SelectTool'
|
||||
import { CanvasOverlay } from './CanvasOverlay'
|
||||
|
||||
type DragInteraction =
|
||||
| { type: 'draw-bbox'; start: Point2D; current: Point2D }
|
||||
| { type: 'move-bbox'; shapeId: string; startMouse: Point2D; initialBox: BoundingBox }
|
||||
| {
|
||||
type: 'resize-bbox'
|
||||
shapeId: string
|
||||
corner: ResizeHandleCorner
|
||||
startMouse: Point2D
|
||||
initialBox: BoundingBox
|
||||
}
|
||||
| { type: 'drag-vertex'; shapeId: string; vertexIndex: number }
|
||||
|
||||
export const AnnotationCanvas: React.FC = () => {
|
||||
const svgRef = useRef<SVGSVGElement | null>(null)
|
||||
|
||||
const project = useAnnotatorStore((s) => s.project)
|
||||
const currentImage = useAnnotatorStore((s) => s.images[s.currentImageIndex])
|
||||
const activeTool = useAnnotatorStore((s) => s.activeTool)
|
||||
const selectedClassId = useAnnotatorStore((s) => s.selectedClassId)
|
||||
const selectedShapeId = useAnnotatorStore((s) => s.selectedShapeId)
|
||||
const shapesByImageId = useAnnotatorStore((s) => s.shapesByImageId)
|
||||
const showBoxes = useAnnotatorStore((s) => s.showBoxes)
|
||||
const showMasks = useAnnotatorStore((s) => s.showMasks)
|
||||
const maskOpacity = useAnnotatorStore((s) => s.maskOpacity)
|
||||
const vertexEditEnabled = useAnnotatorStore((s) => s.vertexEditEnabled)
|
||||
const zoom = useAnnotatorStore((s) => s.zoom)
|
||||
const draftPolygonPoints = useAnnotatorStore((s) => s.draftPolygonPoints)
|
||||
|
||||
const setSelectedShapeId = useAnnotatorStore((s) => s.setSelectedShapeId)
|
||||
const addBoundingBox = useAnnotatorStore((s) => s.addBoundingBox)
|
||||
const updateBoundingBox = useAnnotatorStore((s) => s.updateBoundingBox)
|
||||
const addDraftPolygonPoint = useAnnotatorStore((s) => s.addDraftPolygonPoint)
|
||||
const closeDraftPolygon = useAnnotatorStore((s) => s.closeDraftPolygon)
|
||||
const updatePolygonVertex = useAnnotatorStore((s) => s.updatePolygonVertex)
|
||||
const insertPolygonVertex = useAnnotatorStore((s) => s.insertPolygonVertex)
|
||||
const addPointShape = useAnnotatorStore((s) => s.addPointShape)
|
||||
|
||||
const [interaction, setInteraction] = useState<DragInteraction | null>(null)
|
||||
const [cursorPoint, setCursorPoint] = useState<Point2D | null>(null)
|
||||
|
||||
if (!currentImage) return null
|
||||
|
||||
const shapes = shapesByImageId[currentImage.id] ?? []
|
||||
const selectedShape = shapes.find((s) => s.id === selectedShapeId)
|
||||
const activeClass =
|
||||
project.classes.find((c) => c.id === selectedClassId) ?? project.classes[0]!
|
||||
|
||||
// Convert client mouse position to 1920x1080 SVG coordinate space
|
||||
const getSvgPoint = (e: React.MouseEvent): Point2D => {
|
||||
const svg = svgRef.current
|
||||
if (!svg) return { x: 0, y: 0 }
|
||||
const rect = svg.getBoundingClientRect()
|
||||
if (rect.width === 0 || rect.height === 0) return { x: 0, y: 0 }
|
||||
const scaleX = currentImage.width / rect.width
|
||||
const scaleY = currentImage.height / rect.height
|
||||
return {
|
||||
x: Math.max(0, Math.min(currentImage.width, (e.clientX - rect.left) * scaleX)),
|
||||
y: Math.max(0, Math.min(currentImage.height, (e.clientY - rect.top) * scaleY)),
|
||||
}
|
||||
}
|
||||
|
||||
const handleCanvasMouseDown = (e: React.MouseEvent) => {
|
||||
if (e.button !== 0) return
|
||||
const pt = getSvgPoint(e)
|
||||
|
||||
if (project.taskType === 'object_detection' && activeTool === 'bbox') {
|
||||
setInteraction({ type: 'draw-bbox', start: pt, current: pt })
|
||||
return
|
||||
}
|
||||
|
||||
if (project.taskType === 'segmentation' && activeTool === 'polygon') {
|
||||
addDraftPolygonPoint(pt)
|
||||
return
|
||||
}
|
||||
|
||||
if (activeTool === 'point' && project.taskType !== 'classification') {
|
||||
addPointShape(pt)
|
||||
return
|
||||
}
|
||||
|
||||
if (activeTool === 'select') {
|
||||
setSelectedShapeId(null)
|
||||
}
|
||||
}
|
||||
|
||||
const handleCanvasMouseMove = (e: React.MouseEvent) => {
|
||||
const pt = getSvgPoint(e)
|
||||
if (draftPolygonPoints.length > 0) {
|
||||
setCursorPoint(pt)
|
||||
}
|
||||
|
||||
if (!interaction) return
|
||||
|
||||
if (interaction.type === 'draw-bbox') {
|
||||
setInteraction({ ...interaction, current: pt })
|
||||
return
|
||||
}
|
||||
|
||||
if (interaction.type === 'move-bbox') {
|
||||
const dx = pt.x - interaction.startMouse.x
|
||||
const dy = pt.y - interaction.startMouse.y
|
||||
updateBoundingBox(interaction.shapeId, {
|
||||
x: interaction.initialBox.x + dx,
|
||||
y: interaction.initialBox.y + dy,
|
||||
width: interaction.initialBox.width,
|
||||
height: interaction.initialBox.height,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if (interaction.type === 'resize-bbox') {
|
||||
const { initialBox, corner, startMouse } = interaction
|
||||
const dx = pt.x - startMouse.x
|
||||
const dy = pt.y - startMouse.y
|
||||
|
||||
let newBox: BoundingBox = { ...initialBox }
|
||||
if (corner === 'nw') {
|
||||
newBox = {
|
||||
x: initialBox.x + dx,
|
||||
y: initialBox.y + dy,
|
||||
width: initialBox.width - dx,
|
||||
height: initialBox.height - dy,
|
||||
}
|
||||
} else if (corner === 'ne') {
|
||||
newBox = {
|
||||
x: initialBox.x,
|
||||
y: initialBox.y + dy,
|
||||
width: initialBox.width + dx,
|
||||
height: initialBox.height - dy,
|
||||
}
|
||||
} else if (corner === 'sw') {
|
||||
newBox = {
|
||||
x: initialBox.x + dx,
|
||||
y: initialBox.y,
|
||||
width: initialBox.width - dx,
|
||||
height: initialBox.height + dy,
|
||||
}
|
||||
} else if (corner === 'se') {
|
||||
newBox = {
|
||||
x: initialBox.x,
|
||||
y: initialBox.y,
|
||||
width: initialBox.width + dx,
|
||||
height: initialBox.height + dy,
|
||||
}
|
||||
}
|
||||
updateBoundingBox(interaction.shapeId, newBox)
|
||||
return
|
||||
}
|
||||
|
||||
if (interaction.type === 'drag-vertex') {
|
||||
updatePolygonVertex(interaction.shapeId, interaction.vertexIndex, pt)
|
||||
}
|
||||
}
|
||||
|
||||
const handleCanvasMouseUp = () => {
|
||||
if (!interaction) return
|
||||
if (interaction.type === 'draw-bbox') {
|
||||
const rawBox: BoundingBox = {
|
||||
x: interaction.start.x,
|
||||
y: interaction.start.y,
|
||||
width: interaction.current.x - interaction.start.x,
|
||||
height: interaction.current.y - interaction.start.y,
|
||||
}
|
||||
addBoundingBox(rawBox)
|
||||
}
|
||||
setInteraction(null)
|
||||
}
|
||||
|
||||
const handleDoubleClick = () => {
|
||||
if (project.taskType === 'segmentation' && draftPolygonPoints.length >= 3) {
|
||||
closeDraftPolygon()
|
||||
}
|
||||
}
|
||||
|
||||
const draftBox =
|
||||
interaction?.type === 'draw-bbox'
|
||||
? normalizeBBox(
|
||||
{
|
||||
x: interaction.start.x,
|
||||
y: interaction.start.y,
|
||||
width: interaction.current.x - interaction.start.x,
|
||||
height: interaction.current.y - interaction.start.y,
|
||||
},
|
||||
currentImage.width,
|
||||
currentImage.height
|
||||
)
|
||||
: null
|
||||
|
||||
const scaleFactor = zoom / 75
|
||||
|
||||
return (
|
||||
<div className="px-4 py-3">
|
||||
<div className="relative overflow-hidden rounded-xl border border-slate-200/80 bg-slate-900">
|
||||
<div
|
||||
className="w-full origin-center transition-transform duration-150"
|
||||
style={{
|
||||
transform: scaleFactor !== 1 ? `scale(${scaleFactor})` : undefined,
|
||||
}}
|
||||
>
|
||||
<svg
|
||||
ref={svgRef}
|
||||
viewBox={`0 0 ${currentImage.width} ${currentImage.height}`}
|
||||
className="block aspect-video w-full select-none"
|
||||
style={{
|
||||
cursor:
|
||||
activeTool === 'bbox' || activeTool === 'polygon' || activeTool === 'point'
|
||||
? 'crosshair'
|
||||
: 'default',
|
||||
}}
|
||||
onMouseDown={handleCanvasMouseDown}
|
||||
onMouseMove={handleCanvasMouseMove}
|
||||
onMouseUp={handleCanvasMouseUp}
|
||||
onDoubleClick={handleDoubleClick}
|
||||
>
|
||||
<ImageViewer
|
||||
url={currentImage.url}
|
||||
width={currentImage.width}
|
||||
height={currentImage.height}
|
||||
/>
|
||||
|
||||
{project.taskType === 'object_detection' && (
|
||||
<BoundingBoxTool
|
||||
shapes={shapes}
|
||||
selectedShapeId={selectedShapeId}
|
||||
showBoxes={showBoxes}
|
||||
draftBox={draftBox}
|
||||
activeClassColor={activeClass.color}
|
||||
activeClassName={activeClass.name}
|
||||
onSelectShape={setSelectedShapeId}
|
||||
onStartMoveBox={(e, shape) => {
|
||||
if (!shape.bbox) return
|
||||
setInteraction({
|
||||
type: 'move-bbox',
|
||||
shapeId: shape.id,
|
||||
startMouse: getSvgPoint(e),
|
||||
initialBox: { ...shape.bbox },
|
||||
})
|
||||
}}
|
||||
onStartResizeBox={(e, shape, corner) => {
|
||||
if (!shape.bbox) return
|
||||
setInteraction({
|
||||
type: 'resize-bbox',
|
||||
shapeId: shape.id,
|
||||
corner,
|
||||
startMouse: getSvgPoint(e),
|
||||
initialBox: { ...shape.bbox },
|
||||
})
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
{project.taskType === 'segmentation' && (
|
||||
<PolygonTool
|
||||
shapes={shapes}
|
||||
selectedShapeId={selectedShapeId}
|
||||
showMasks={showMasks}
|
||||
maskOpacity={maskOpacity}
|
||||
vertexEditEnabled={vertexEditEnabled}
|
||||
draftPolygonPoints={draftPolygonPoints}
|
||||
cursorPoint={cursorPoint}
|
||||
activeClassColor={activeClass.color}
|
||||
onSelectShape={setSelectedShapeId}
|
||||
onStartDragVertex={(_e, shapeId, vertexIndex) => {
|
||||
setInteraction({
|
||||
type: 'drag-vertex',
|
||||
shapeId,
|
||||
vertexIndex,
|
||||
})
|
||||
}}
|
||||
onInsertVertexOnEdge={(shapeId, afterIndex, pt) => {
|
||||
insertPolygonVertex(shapeId, afterIndex, pt)
|
||||
}}
|
||||
onCloseDraftPolygon={closeDraftPolygon}
|
||||
/>
|
||||
)}
|
||||
|
||||
<PointTool
|
||||
shapes={shapes}
|
||||
selectedShapeId={selectedShapeId}
|
||||
onSelectShape={setSelectedShapeId}
|
||||
/>
|
||||
|
||||
<SelectTool selectedShape={selectedShape} />
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
{/* Bottom-left dark translucent pill overlay */}
|
||||
<CanvasOverlay />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
163
src/pages/annotator/components/canvas/BoundingBoxTool.tsx
Normal file
163
src/pages/annotator/components/canvas/BoundingBoxTool.tsx
Normal file
|
|
@ -0,0 +1,163 @@
|
|||
import React from 'react'
|
||||
import { AnnotationShape, BoundingBox } from '@/types'
|
||||
|
||||
export type ResizeHandleCorner = 'nw' | 'ne' | 'sw' | 'se'
|
||||
|
||||
export interface BoundingBoxToolProps {
|
||||
shapes: AnnotationShape[]
|
||||
selectedShapeId: string | null
|
||||
showBoxes: boolean
|
||||
draftBox: BoundingBox | null
|
||||
activeClassColor: string
|
||||
activeClassName: string
|
||||
onSelectShape: (shapeId: string) => void
|
||||
onStartMoveBox: (e: React.MouseEvent, shape: AnnotationShape) => void
|
||||
onStartResizeBox: (
|
||||
e: React.MouseEvent,
|
||||
shape: AnnotationShape,
|
||||
corner: ResizeHandleCorner
|
||||
) => void
|
||||
}
|
||||
|
||||
export const BoundingBoxTool: React.FC<BoundingBoxToolProps> = ({
|
||||
shapes,
|
||||
selectedShapeId,
|
||||
showBoxes,
|
||||
draftBox,
|
||||
activeClassColor,
|
||||
activeClassName,
|
||||
onSelectShape,
|
||||
onStartMoveBox,
|
||||
onStartResizeBox,
|
||||
}) => {
|
||||
if (!showBoxes) return null
|
||||
|
||||
const bboxShapes = shapes.filter((s) => s.type === 'bbox' && s.visible && s.bbox)
|
||||
|
||||
return (
|
||||
<g>
|
||||
{bboxShapes.map((shape) => {
|
||||
const box = shape.bbox!
|
||||
const isSelected = shape.id === selectedShapeId
|
||||
const pillWidth = Math.max(82, shape.labelName.length * 14 + 24)
|
||||
const pillY = Math.max(4, box.y - 38)
|
||||
const isLightTag = shape.color === '#F59E0B' || shape.color === '#06B6D4'
|
||||
|
||||
const corners: { id: ResizeHandleCorner; cx: number; cy: number; cursor: string }[] = [
|
||||
{ id: 'nw', cx: box.x, cy: box.y, cursor: 'nwse-resize' },
|
||||
{ id: 'ne', cx: box.x + box.width, cy: box.y, cursor: 'nesw-resize' },
|
||||
{ id: 'sw', cx: box.x, cy: box.y + box.height, cursor: 'nesw-resize' },
|
||||
{ id: 'se', cx: box.x + box.width, cy: box.y + box.height, cursor: 'nwse-resize' },
|
||||
]
|
||||
|
||||
return (
|
||||
<g key={shape.id}>
|
||||
{/* Main Bounding Box Rectangle */}
|
||||
<rect
|
||||
x={box.x}
|
||||
y={box.y}
|
||||
width={box.width}
|
||||
height={box.height}
|
||||
fill={shape.color}
|
||||
fillOpacity={isSelected ? 0.14 : 0.05}
|
||||
stroke={shape.color}
|
||||
strokeWidth={isSelected ? 4 : 3}
|
||||
className="cursor-move"
|
||||
onMouseDown={(e) => {
|
||||
e.stopPropagation()
|
||||
onSelectShape(shape.id)
|
||||
onStartMoveBox(e, shape)
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* Top-left Label Pill matching wireframe */}
|
||||
<g
|
||||
className="cursor-pointer"
|
||||
onMouseDown={(e) => {
|
||||
e.stopPropagation()
|
||||
onSelectShape(shape.id)
|
||||
}}
|
||||
>
|
||||
<rect
|
||||
x={box.x}
|
||||
y={pillY}
|
||||
width={pillWidth}
|
||||
height={32}
|
||||
rx={8}
|
||||
fill={shape.color}
|
||||
fillOpacity={0.92}
|
||||
/>
|
||||
<text
|
||||
x={box.x + pillWidth / 2}
|
||||
y={pillY + 21}
|
||||
fill={isLightTag ? '#0F172A' : '#FFFFFF'}
|
||||
fontSize={17}
|
||||
fontWeight="bold"
|
||||
textAnchor="middle"
|
||||
className="select-none"
|
||||
>
|
||||
{shape.labelName}
|
||||
</text>
|
||||
</g>
|
||||
|
||||
{/* Corner Resize Handles when Selected */}
|
||||
{isSelected &&
|
||||
corners.map((corner) => (
|
||||
<rect
|
||||
key={corner.id}
|
||||
x={corner.cx - 8}
|
||||
y={corner.cy - 8}
|
||||
width={16}
|
||||
height={16}
|
||||
rx={3}
|
||||
fill="#FFFFFF"
|
||||
stroke={shape.color}
|
||||
strokeWidth={3.5}
|
||||
style={{ cursor: corner.cursor }}
|
||||
onMouseDown={(e) => {
|
||||
e.stopPropagation()
|
||||
onStartResizeBox(e, shape, corner.id)
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</g>
|
||||
)
|
||||
})}
|
||||
|
||||
{/* Active Draft Bounding Box while user drags */}
|
||||
{draftBox && draftBox.width > 4 && draftBox.height > 4 && (
|
||||
<g className="pointer-events-none">
|
||||
<rect
|
||||
x={draftBox.x}
|
||||
y={draftBox.y}
|
||||
width={draftBox.width}
|
||||
height={draftBox.height}
|
||||
fill={activeClassColor}
|
||||
fillOpacity={0.18}
|
||||
stroke={activeClassColor}
|
||||
strokeWidth={3.5}
|
||||
strokeDasharray="8 6"
|
||||
/>
|
||||
<rect
|
||||
x={draftBox.x}
|
||||
y={Math.max(4, draftBox.y - 34)}
|
||||
width={110}
|
||||
height={28}
|
||||
rx={6}
|
||||
fill={activeClassColor}
|
||||
/>
|
||||
<text
|
||||
x={draftBox.x + 55}
|
||||
y={Math.max(4, draftBox.y - 34) + 19}
|
||||
fill="#FFFFFF"
|
||||
fontSize={15}
|
||||
fontWeight="bold"
|
||||
textAnchor="middle"
|
||||
>
|
||||
{activeClassName}
|
||||
</text>
|
||||
</g>
|
||||
)}
|
||||
</g>
|
||||
)
|
||||
}
|
||||
54
src/pages/annotator/components/canvas/CanvasOverlay.tsx
Normal file
54
src/pages/annotator/components/canvas/CanvasOverlay.tsx
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import React from 'react'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
|
||||
export const CanvasOverlay: React.FC = () => {
|
||||
const project = useAnnotatorStore((s) => s.project)
|
||||
const currentImage = useAnnotatorStore((s) => s.images[s.currentImageIndex])
|
||||
const classificationByImageId = useAnnotatorStore((s) => s.classificationByImageId)
|
||||
const shapesByImageId = useAnnotatorStore((s) => s.shapesByImageId)
|
||||
const selectedShapeId = useAnnotatorStore((s) => s.selectedShapeId)
|
||||
|
||||
if (!currentImage) return null
|
||||
|
||||
const shapes = shapesByImageId[currentImage.id] ?? []
|
||||
const selectedShape = shapes.find((s) => s.id === selectedShapeId) ?? shapes[1] ?? shapes[0]
|
||||
|
||||
if (project.taskType === 'classification') {
|
||||
const classId = classificationByImageId[currentImage.id] ?? 'cls-car'
|
||||
const cls = project.classes.find((c) => c.id === classId) ?? project.classes[0]
|
||||
return (
|
||||
<div className="pointer-events-none absolute bottom-3 left-3 z-10 inline-flex items-center gap-2 rounded-lg bg-slate-900/80 px-3 py-1.5 text-xs font-medium text-white backdrop-blur-xs">
|
||||
<svg className="h-3.5 w-3.5 text-slate-300" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M20.59 13.41l-7.17 7.17a2 2 0 0 1-2.83 0L2 12V2h10l8.59 8.59a2 2 0 0 1 0 2.82z" />
|
||||
<line x1="7" y1="7" x2="7.01" y2="7" />
|
||||
</svg>
|
||||
<span>Nhãn ảnh: {cls?.name ?? 'Ô tô'}</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (project.taskType === 'object_detection') {
|
||||
return (
|
||||
<div className="pointer-events-none absolute bottom-3 left-3 z-10 inline-flex items-center gap-2 rounded-lg bg-slate-900/80 px-3 py-1.5 text-xs font-medium text-white backdrop-blur-xs">
|
||||
<svg className="h-3.5 w-3.5 text-slate-300" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3" />
|
||||
</svg>
|
||||
<span>{shapes.length} hộp giới hạn · Gán nhãn thủ công</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const vertexCount = selectedShape?.points?.length ?? 13
|
||||
const labelName = selectedShape?.labelName ?? 'Xe buýt'
|
||||
|
||||
return (
|
||||
<div className="pointer-events-none absolute bottom-3 left-3 z-10 inline-flex items-center gap-2 rounded-lg bg-slate-900/80 px-3 py-1.5 text-xs font-medium text-white backdrop-blur-xs">
|
||||
<svg className="h-3.5 w-3.5 text-slate-300" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<polygon points="12 2 22 8.5 18 21 6 21 2 8.5 12 2" />
|
||||
</svg>
|
||||
<span>
|
||||
Polygon · {labelName} · {vertexCount} đỉnh
|
||||
</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
21
src/pages/annotator/components/canvas/ImageViewer.tsx
Normal file
21
src/pages/annotator/components/canvas/ImageViewer.tsx
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import React from 'react'
|
||||
|
||||
export interface ImageViewerProps {
|
||||
url: string
|
||||
width: number
|
||||
height: number
|
||||
}
|
||||
|
||||
export const ImageViewer: React.FC<ImageViewerProps> = ({ url, width, height }) => {
|
||||
return (
|
||||
<image
|
||||
href={url}
|
||||
x={0}
|
||||
y={0}
|
||||
width={width}
|
||||
height={height}
|
||||
preserveAspectRatio="none"
|
||||
className="select-none pointer-events-none"
|
||||
/>
|
||||
)
|
||||
}
|
||||
64
src/pages/annotator/components/canvas/PointTool.tsx
Normal file
64
src/pages/annotator/components/canvas/PointTool.tsx
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
import React from 'react'
|
||||
import { AnnotationShape } from '@/types'
|
||||
|
||||
export interface PointToolProps {
|
||||
shapes: AnnotationShape[]
|
||||
selectedShapeId: string | null
|
||||
onSelectShape: (shapeId: string) => void
|
||||
}
|
||||
|
||||
export const PointTool: React.FC<PointToolProps> = ({
|
||||
shapes,
|
||||
selectedShapeId,
|
||||
onSelectShape,
|
||||
}) => {
|
||||
const pointShapes = shapes.filter((s) => s.type === 'point' && s.visible && s.point)
|
||||
|
||||
return (
|
||||
<g>
|
||||
{pointShapes.map((shape) => {
|
||||
const pt = shape.point!
|
||||
const isSelected = shape.id === selectedShapeId
|
||||
return (
|
||||
<g
|
||||
key={shape.id}
|
||||
className="cursor-pointer"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
onSelectShape(shape.id)
|
||||
}}
|
||||
>
|
||||
<circle
|
||||
cx={pt.x}
|
||||
cy={pt.y}
|
||||
r={isSelected ? 12 : 9}
|
||||
fill={shape.color}
|
||||
fillOpacity={0.35}
|
||||
stroke="#FFFFFF"
|
||||
strokeWidth={3}
|
||||
/>
|
||||
<circle cx={pt.x} cy={pt.y} r={5} fill={shape.color} />
|
||||
<rect
|
||||
x={pt.x - 36}
|
||||
y={pt.y - 38}
|
||||
width={72}
|
||||
height={24}
|
||||
rx={6}
|
||||
fill={shape.color}
|
||||
/>
|
||||
<text
|
||||
x={pt.x}
|
||||
y={pt.y - 22}
|
||||
fill="#FFFFFF"
|
||||
fontSize={14}
|
||||
fontWeight="bold"
|
||||
textAnchor="middle"
|
||||
>
|
||||
{shape.labelName}
|
||||
</text>
|
||||
</g>
|
||||
)
|
||||
})}
|
||||
</g>
|
||||
)
|
||||
}
|
||||
201
src/pages/annotator/components/canvas/PolygonTool.tsx
Normal file
201
src/pages/annotator/components/canvas/PolygonTool.tsx
Normal file
|
|
@ -0,0 +1,201 @@
|
|||
import React from 'react'
|
||||
import { AnnotationShape, Point2D } from '@/types'
|
||||
|
||||
export interface PolygonToolProps {
|
||||
shapes: AnnotationShape[]
|
||||
selectedShapeId: string | null
|
||||
showMasks: boolean
|
||||
maskOpacity: number
|
||||
vertexEditEnabled: boolean
|
||||
draftPolygonPoints: Point2D[]
|
||||
cursorPoint: Point2D | null
|
||||
activeClassColor: string
|
||||
onSelectShape: (shapeId: string) => void
|
||||
onStartDragVertex: (
|
||||
e: React.MouseEvent,
|
||||
shapeId: string,
|
||||
vertexIndex: number
|
||||
) => void
|
||||
onInsertVertexOnEdge: (
|
||||
shapeId: string,
|
||||
afterIndex: number,
|
||||
pt: Point2D
|
||||
) => void
|
||||
onCloseDraftPolygon: () => void
|
||||
}
|
||||
|
||||
export const PolygonTool: React.FC<PolygonToolProps> = ({
|
||||
shapes,
|
||||
selectedShapeId,
|
||||
showMasks,
|
||||
maskOpacity,
|
||||
vertexEditEnabled,
|
||||
draftPolygonPoints,
|
||||
cursorPoint,
|
||||
activeClassColor,
|
||||
onSelectShape,
|
||||
onStartDragVertex,
|
||||
onInsertVertexOnEdge,
|
||||
onCloseDraftPolygon,
|
||||
}) => {
|
||||
if (!showMasks) return null
|
||||
|
||||
const polygonShapes = shapes.filter(
|
||||
(s) => s.type === 'polygon' && s.visible && s.points && s.points.length >= 3
|
||||
)
|
||||
|
||||
return (
|
||||
<g>
|
||||
{polygonShapes.map((shape) => {
|
||||
const pts = shape.points!
|
||||
const isSelected = shape.id === selectedShapeId
|
||||
const pointsAttr = pts.map((p) => `${p.x},${p.y}`).join(' ')
|
||||
|
||||
// Find top-most vertex to place the label tag cleanly above the shape
|
||||
const topPoint = pts.reduce(
|
||||
(minPt, p) => (p.y < minPt.y ? p : minPt),
|
||||
pts[0]!
|
||||
)
|
||||
const tagText =
|
||||
shape.groupId !== undefined
|
||||
? `${shape.labelName} · group ${shape.groupId}`
|
||||
: shape.labelName
|
||||
const tagWidth = Math.max(135, tagText.length * 11 + 26)
|
||||
const tagX = topPoint.x - 20
|
||||
const tagY = Math.max(8, topPoint.y - 46)
|
||||
|
||||
return (
|
||||
<g key={shape.id}>
|
||||
{/* Polygon Filled Mask */}
|
||||
<polygon
|
||||
points={pointsAttr}
|
||||
fill={shape.color}
|
||||
fillOpacity={maskOpacity / 100}
|
||||
stroke={shape.color}
|
||||
strokeWidth={isSelected ? 4 : 3}
|
||||
strokeLinejoin="round"
|
||||
className="cursor-pointer transition-opacity"
|
||||
onMouseDown={(e) => {
|
||||
e.stopPropagation()
|
||||
onSelectShape(shape.id)
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* Clickable/Double-clickable Edges for inserting a new vertex */}
|
||||
{isSelected &&
|
||||
vertexEditEnabled &&
|
||||
pts.map((pt, idx) => {
|
||||
const nextPt = pts[(idx + 1) % pts.length]!
|
||||
return (
|
||||
<line
|
||||
key={`edge-${idx}`}
|
||||
x1={pt.x}
|
||||
y1={pt.y}
|
||||
x2={nextPt.x}
|
||||
y2={nextPt.y}
|
||||
stroke="transparent"
|
||||
strokeWidth={14}
|
||||
className="cursor-copy"
|
||||
onDoubleClick={(e) => {
|
||||
e.stopPropagation()
|
||||
const midX = (pt.x + nextPt.x) / 2
|
||||
const midY = (pt.y + nextPt.y) / 2
|
||||
onInsertVertexOnEdge(shape.id, idx, { x: midX, y: midY })
|
||||
}}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
|
||||
{/* Label Pill above Selected Polygon (e.g., "Xe buýt · group 2") */}
|
||||
{isSelected && (
|
||||
<g className="pointer-events-none">
|
||||
<rect
|
||||
x={tagX}
|
||||
y={tagY}
|
||||
width={tagWidth}
|
||||
height={34}
|
||||
rx={8}
|
||||
fill={shape.color}
|
||||
fillOpacity={0.88}
|
||||
/>
|
||||
<text
|
||||
x={tagX + tagWidth / 2}
|
||||
y={tagY + 22}
|
||||
fill="#0F172A"
|
||||
fontSize={16}
|
||||
fontWeight="bold"
|
||||
textAnchor="middle"
|
||||
className="select-none"
|
||||
>
|
||||
{tagText}
|
||||
</text>
|
||||
</g>
|
||||
)}
|
||||
|
||||
{/* Draggable Vertex Handles on Selected Polygon */}
|
||||
{isSelected &&
|
||||
pts.map((pt, idx) => (
|
||||
<circle
|
||||
key={`vertex-${idx}`}
|
||||
cx={pt.x}
|
||||
cy={pt.y}
|
||||
r={vertexEditEnabled ? 7.5 : 5.5}
|
||||
fill="#FFFFFF"
|
||||
stroke={shape.color}
|
||||
strokeWidth={3.5}
|
||||
className={
|
||||
vertexEditEnabled ? 'cursor-grab active:cursor-grabbing' : 'cursor-pointer'
|
||||
}
|
||||
onMouseDown={(e) => {
|
||||
e.stopPropagation()
|
||||
if (vertexEditEnabled) {
|
||||
onStartDragVertex(e, shape.id, idx)
|
||||
}
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</g>
|
||||
)
|
||||
})}
|
||||
|
||||
{/* In-progress Draft Polygon while clicking points */}
|
||||
{draftPolygonPoints.length > 0 && (
|
||||
<g>
|
||||
<polyline
|
||||
points={[
|
||||
...draftPolygonPoints.map((p) => `${p.x},${p.y}`),
|
||||
...(cursorPoint ? [`${cursorPoint.x},${cursorPoint.y}`] : []),
|
||||
].join(' ')}
|
||||
fill={activeClassColor}
|
||||
fillOpacity={0.18}
|
||||
stroke={activeClassColor}
|
||||
strokeWidth={3.5}
|
||||
strokeDasharray="8 5"
|
||||
className="pointer-events-none"
|
||||
/>
|
||||
{draftPolygonPoints.map((pt, idx) => {
|
||||
const isFirst = idx === 0
|
||||
return (
|
||||
<circle
|
||||
key={`draft-pt-${idx}`}
|
||||
cx={pt.x}
|
||||
cy={pt.y}
|
||||
r={isFirst ? 10 : 7}
|
||||
fill={isFirst ? activeClassColor : '#FFFFFF'}
|
||||
stroke="#FFFFFF"
|
||||
strokeWidth={3}
|
||||
className="cursor-pointer"
|
||||
onClick={(e) => {
|
||||
if (isFirst && draftPolygonPoints.length >= 3) {
|
||||
e.stopPropagation()
|
||||
onCloseDraftPolygon()
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
</g>
|
||||
)}
|
||||
</g>
|
||||
)
|
||||
}
|
||||
11
src/pages/annotator/components/canvas/SelectTool.tsx
Normal file
11
src/pages/annotator/components/canvas/SelectTool.tsx
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import React from 'react'
|
||||
import { AnnotationShape } from '@/types'
|
||||
|
||||
export interface SelectToolProps {
|
||||
selectedShape: AnnotationShape | undefined
|
||||
}
|
||||
|
||||
export const SelectTool: React.FC<SelectToolProps> = ({ selectedShape }) => {
|
||||
if (!selectedShape || !selectedShape.visible) return null
|
||||
return null
|
||||
}
|
||||
102
src/pages/annotator/components/canvas/ToolBar.tsx
Normal file
102
src/pages/annotator/components/canvas/ToolBar.tsx
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
import { AnnotationTool } from '@/types'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
import { UndoRedoButtons } from '../header/UndoRedoButtons'
|
||||
import { ZoomControls } from './ZoomControls'
|
||||
|
||||
export const ToolBar: React.FC = () => {
|
||||
const taskType = useAnnotatorStore((s) => s.project.taskType)
|
||||
const activeTool = useAnnotatorStore((s) => s.activeTool)
|
||||
const setActiveTool = useAnnotatorStore((s) => s.setActiveTool)
|
||||
|
||||
const tools: {
|
||||
id: AnnotationTool
|
||||
label: string
|
||||
shortcut: string
|
||||
enabled: boolean
|
||||
icon: React.ReactNode
|
||||
}[] = [
|
||||
{
|
||||
id: 'select',
|
||||
label: 'Chọn',
|
||||
shortcut: 'V',
|
||||
enabled: true,
|
||||
icon: (
|
||||
<svg className="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="m3 3 7.07 16.97 2.51-7.39 7.39-2.51L3 3z" />
|
||||
<path d="m13 13 6 6" />
|
||||
</svg>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'bbox',
|
||||
label: 'Hộp',
|
||||
shortcut: 'B',
|
||||
enabled: taskType === 'object_detection',
|
||||
icon: (
|
||||
<svg className="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeDasharray="3 2">
|
||||
<rect x="3" y="3" width="18" height="18" rx="2" />
|
||||
</svg>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'polygon',
|
||||
label: 'Polygon',
|
||||
shortcut: 'P',
|
||||
enabled: taskType === 'segmentation',
|
||||
icon: (
|
||||
<svg className="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<polygon points="12 2 22 8.5 18 21 6 21 2 8.5 12 2" />
|
||||
</svg>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'point',
|
||||
label: 'Điểm',
|
||||
shortcut: 'K',
|
||||
enabled: taskType !== 'classification',
|
||||
icon: (
|
||||
<svg className="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z" />
|
||||
<circle cx="12" cy="10" r="3" />
|
||||
</svg>
|
||||
),
|
||||
},
|
||||
]
|
||||
|
||||
return (
|
||||
<div className="flex items-center justify-between border-b border-slate-100 px-4 py-2">
|
||||
<div className="flex items-center gap-1.5">
|
||||
{tools.map((tool) => {
|
||||
const isActive = activeTool === tool.id
|
||||
return (
|
||||
<button
|
||||
key={tool.id}
|
||||
type="button"
|
||||
disabled={!tool.enabled}
|
||||
onClick={() => tool.enabled && setActiveTool(tool.id)}
|
||||
title={`${tool.label} (${tool.shortcut})`}
|
||||
className={clsx(
|
||||
'inline-flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-xs font-medium transition-colors',
|
||||
isActive
|
||||
? 'bg-[#FDECE7] text-[#4F46E5] font-semibold'
|
||||
: tool.enabled
|
||||
? 'text-slate-600 hover:bg-slate-100 hover:text-slate-900'
|
||||
: 'cursor-not-allowed text-slate-300'
|
||||
)}
|
||||
>
|
||||
{tool.icon}
|
||||
<span>{tool.label}</span>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
|
||||
<div className="mx-1.5 h-4 w-px bg-slate-200" />
|
||||
<UndoRedoButtons />
|
||||
</div>
|
||||
|
||||
<ZoomControls />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
55
src/pages/annotator/components/canvas/ZoomControls.tsx
Normal file
55
src/pages/annotator/components/canvas/ZoomControls.tsx
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import React from 'react'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
|
||||
export const ZoomControls: React.FC = () => {
|
||||
const zoom = useAnnotatorStore((s) => s.zoom)
|
||||
const zoomIn = useAnnotatorStore((s) => s.zoomIn)
|
||||
const zoomOut = useAnnotatorStore((s) => s.zoomOut)
|
||||
const resetZoom = useAnnotatorStore((s) => s.resetZoom)
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-1.5 text-slate-600">
|
||||
<button
|
||||
type="button"
|
||||
onClick={zoomOut}
|
||||
title="Thu nhỏ"
|
||||
className="inline-flex h-7 w-7 items-center justify-center rounded-lg transition-colors hover:bg-slate-100 hover:text-slate-900"
|
||||
>
|
||||
<svg className="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<circle cx="11" cy="11" r="8" />
|
||||
<line x1="21" y1="21" x2="16.65" y2="16.65" />
|
||||
<line x1="8" y1="11" x2="14" y2="11" />
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<span className="min-w-[38px] text-center font-mono text-xs font-medium text-slate-600">
|
||||
{zoom}%
|
||||
</span>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={zoomIn}
|
||||
title="Phóng to"
|
||||
className="inline-flex h-7 w-7 items-center justify-center rounded-lg transition-colors hover:bg-slate-100 hover:text-slate-900"
|
||||
>
|
||||
<svg className="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<circle cx="11" cy="11" r="8" />
|
||||
<line x1="21" y1="21" x2="16.65" y2="16.65" />
|
||||
<line x1="11" y1="8" x2="11" y2="14" />
|
||||
<line x1="8" y1="11" x2="14" y2="11" />
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={resetZoom}
|
||||
title="Khớp khung hình (75%)"
|
||||
className="inline-flex h-7 w-7 items-center justify-center rounded-lg transition-colors hover:bg-slate-100 hover:text-slate-900"
|
||||
>
|
||||
<svg className="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
71
src/pages/annotator/components/header/AnnotatorHeader.tsx
Normal file
71
src/pages/annotator/components/header/AnnotatorHeader.tsx
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
import React from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import clsx from 'clsx'
|
||||
import { TaskType } from '@/types'
|
||||
import { TASK_TYPE_LABELS } from '@/app/constants'
|
||||
import { formatNumber } from '@/utils/format'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
import { SaveButton } from './SaveButton'
|
||||
import { SaveAndNextButton } from './SaveAndNextButton'
|
||||
|
||||
export const AnnotatorHeader: React.FC = () => {
|
||||
const navigate = useNavigate()
|
||||
const project = useAnnotatorStore((s) => s.project)
|
||||
const switchTaskMode = useAnnotatorStore((s) => s.switchTaskMode)
|
||||
|
||||
const taskOptions: { type: TaskType; label: string }[] = [
|
||||
{ type: 'classification', label: 'Classification' },
|
||||
{ type: 'object_detection', label: 'Object Detection' },
|
||||
{ type: 'segmentation', label: 'Segmentation' },
|
||||
]
|
||||
|
||||
return (
|
||||
<div className="flex flex-wrap items-center justify-between gap-4 pb-3">
|
||||
<div>
|
||||
<div className="flex items-center gap-3">
|
||||
<h1 className="text-2xl font-bold tracking-tight text-slate-900">
|
||||
{project.name}
|
||||
</h1>
|
||||
{/* Quick Task Switcher Pill Bar so user can test all 3 Annotator modes effortlessly */}
|
||||
<div className="hidden items-center gap-1 rounded-xl border border-slate-200 bg-white p-0.5 shadow-2xs sm:inline-flex">
|
||||
{taskOptions.map((opt) => {
|
||||
const active = project.taskType === opt.type
|
||||
return (
|
||||
<button
|
||||
key={opt.type}
|
||||
type="button"
|
||||
onClick={() => switchTaskMode(opt.type)}
|
||||
className={clsx(
|
||||
'rounded-lg px-2.5 py-1 text-xs font-medium transition-colors',
|
||||
active
|
||||
? 'bg-[#FDF4F1] text-[#C95C3C] font-semibold'
|
||||
: 'text-slate-500 hover:text-slate-800'
|
||||
)}
|
||||
>
|
||||
{opt.label}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
<p className="mt-0.5 text-xs text-slate-500">
|
||||
{TASK_TYPE_LABELS[project.taskType]} · {project.slug} ·{' '}
|
||||
{formatNumber(project.stats.totalImages)} ảnh
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2.5">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => navigate(`/projects/${project.id}`)}
|
||||
className="inline-flex items-center gap-2 rounded-xl border border-slate-200 bg-white px-4 py-2 text-sm font-medium text-slate-700 shadow-2xs transition-colors hover:bg-slate-50"
|
||||
>
|
||||
<span>←</span>
|
||||
<span>Về tổng quan</span>
|
||||
</button>
|
||||
<SaveButton />
|
||||
<SaveAndNextButton />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
19
src/pages/annotator/components/header/ImageInfo.tsx
Normal file
19
src/pages/annotator/components/header/ImageInfo.tsx
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import React from 'react'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
|
||||
export const ImageInfo: React.FC = () => {
|
||||
const currentImage = useAnnotatorStore((s) => s.images[s.currentImageIndex])
|
||||
|
||||
if (!currentImage) return null
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-2.5">
|
||||
<span className="font-mono text-xs font-semibold text-slate-800">
|
||||
{currentImage.fileName}
|
||||
</span>
|
||||
<span className="text-xs text-slate-400">
|
||||
{currentImage.width} × {currentImage.height} px
|
||||
</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
25
src/pages/annotator/components/header/SaveAndNextButton.tsx
Normal file
25
src/pages/annotator/components/header/SaveAndNextButton.tsx
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import React from 'react'
|
||||
import toast from 'react-hot-toast'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
|
||||
export const SaveAndNextButton: React.FC = () => {
|
||||
const saveAndNext = useAnnotatorStore((s) => s.saveAndNext)
|
||||
const currentImage = useAnnotatorStore((s) => s.images[s.currentImageIndex])
|
||||
|
||||
const handleSaveAndNext = () => {
|
||||
const fileName = currentImage?.fileName ?? 'ảnh'
|
||||
saveAndNext()
|
||||
toast.success(`Đã lưu ${fileName} và chuyển sang ảnh tiếp theo`)
|
||||
}
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleSaveAndNext}
|
||||
className="inline-flex items-center gap-2 rounded-xl bg-[#C95C3C] px-4 py-2 text-sm font-medium text-white shadow-sm transition-colors hover:bg-[#B5492B] focus:outline-none focus:ring-2 focus:ring-[#C95C3C]/30"
|
||||
>
|
||||
<span>→</span>
|
||||
<span>Lưu & ảnh tiếp</span>
|
||||
</button>
|
||||
)
|
||||
}
|
||||
36
src/pages/annotator/components/header/SaveButton.tsx
Normal file
36
src/pages/annotator/components/header/SaveButton.tsx
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import React from 'react'
|
||||
import toast from 'react-hot-toast'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
|
||||
export const SaveButton: React.FC = () => {
|
||||
const saveCurrentAnnotation = useAnnotatorStore((s) => s.saveCurrentAnnotation)
|
||||
const currentImage = useAnnotatorStore((s) => s.images[s.currentImageIndex])
|
||||
|
||||
const handleSave = () => {
|
||||
saveCurrentAnnotation()
|
||||
toast.success(`Đã lưu nhãn cho ${currentImage?.fileName ?? 'ảnh hiện tại'}`)
|
||||
}
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleSave}
|
||||
className="inline-flex items-center gap-2 rounded-xl bg-[#C95C3C] px-4 py-2 text-sm font-medium text-white shadow-sm transition-colors hover:bg-[#B5492B] focus:outline-none focus:ring-2 focus:ring-[#C95C3C]/30"
|
||||
>
|
||||
<svg
|
||||
className="h-4 w-4 text-white/90"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z" />
|
||||
<polyline points="17 21 17 13 7 13 7 21" />
|
||||
<polyline points="7 3 7 8 15 8" />
|
||||
</svg>
|
||||
<span>Lưu</span>
|
||||
</button>
|
||||
)
|
||||
}
|
||||
54
src/pages/annotator/components/header/UndoRedoButtons.tsx
Normal file
54
src/pages/annotator/components/header/UndoRedoButtons.tsx
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import React from 'react'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
|
||||
export const UndoRedoButtons: React.FC = () => {
|
||||
const undo = useAnnotatorStore((s) => s.undo)
|
||||
const redo = useAnnotatorStore((s) => s.redo)
|
||||
const canUndo = useAnnotatorStore((s) => s.historyPast.length > 0)
|
||||
const canRedo = useAnnotatorStore((s) => s.historyFuture.length > 0)
|
||||
|
||||
return (
|
||||
<div className="inline-flex items-center gap-1">
|
||||
<button
|
||||
type="button"
|
||||
onClick={undo}
|
||||
disabled={!canUndo}
|
||||
title="Hoàn tác (Ctrl+Z)"
|
||||
className="inline-flex h-8 w-8 items-center justify-center rounded-lg text-slate-600 transition-colors hover:bg-slate-100 hover:text-slate-900 disabled:cursor-not-allowed disabled:opacity-40"
|
||||
>
|
||||
<svg
|
||||
className="h-4 w-4"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="M3 7v6h6" />
|
||||
<path d="M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13" />
|
||||
</svg>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={redo}
|
||||
disabled={!canRedo}
|
||||
title="Làm lại (Ctrl+Y)"
|
||||
className="inline-flex h-8 w-8 items-center justify-center rounded-lg text-slate-600 transition-colors hover:bg-slate-100 hover:text-slate-900 disabled:cursor-not-allowed disabled:opacity-40"
|
||||
>
|
||||
<svg
|
||||
className="h-4 w-4"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="M21 7v6h-6" />
|
||||
<path d="M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3l3 2.7" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
40
src/pages/annotator/components/navigator/ImageCounter.tsx
Normal file
40
src/pages/annotator/components/navigator/ImageCounter.tsx
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import React from 'react'
|
||||
import { formatNumber } from '@/utils/format'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
|
||||
export const ImageCounter: React.FC = () => {
|
||||
const displayImageCounter = useAnnotatorStore((s) => s.displayImageCounter)
|
||||
const totalImages = useAnnotatorStore((s) => s.project.stats.totalImages)
|
||||
const prevImage = useAnnotatorStore((s) => s.prevImage)
|
||||
const nextImage = useAnnotatorStore((s) => s.nextImage)
|
||||
|
||||
return (
|
||||
<div className="inline-flex items-center gap-3 text-xs font-medium text-slate-600">
|
||||
<button
|
||||
type="button"
|
||||
onClick={prevImage}
|
||||
title="Ảnh trước"
|
||||
className="inline-flex h-6 w-6 items-center justify-center rounded-md text-slate-500 transition-colors hover:bg-slate-100 hover:text-slate-900"
|
||||
>
|
||||
<svg className="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<polyline points="15 18 9 12 15 6" />
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<span className="font-mono text-xs text-slate-600">
|
||||
{displayImageCounter} / {formatNumber(totalImages)}
|
||||
</span>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={nextImage}
|
||||
title="Ảnh tiếp theo"
|
||||
className="inline-flex h-6 w-6 items-center justify-center rounded-md text-slate-500 transition-colors hover:bg-slate-100 hover:text-slate-900"
|
||||
>
|
||||
<svg className="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<polyline points="9 18 15 12 9 6" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
38
src/pages/annotator/components/navigator/ImageNavigator.tsx
Normal file
38
src/pages/annotator/components/navigator/ImageNavigator.tsx
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import React from 'react'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
import { ThumbnailStrip } from './ThumbnailStrip'
|
||||
import { SaveStatus } from './SaveStatus'
|
||||
|
||||
export const ImageNavigator: React.FC = () => {
|
||||
const taskType = useAnnotatorStore((s) => s.project.taskType)
|
||||
|
||||
const leftHint =
|
||||
taskType === 'classification'
|
||||
? 'Chọn lớp ở bảng bên phải · Không tạo shape'
|
||||
: taskType === 'object_detection'
|
||||
? 'Kéo để tạo box · Kéo góc để chỉnh kích thước'
|
||||
: 'Click để thêm đỉnh · Enter để đóng polygon'
|
||||
|
||||
const rightShortcut =
|
||||
taskType === 'classification'
|
||||
? 'Chọn [V]'
|
||||
: taskType === 'object_detection'
|
||||
? 'Hộp [B]'
|
||||
: 'Polygon [P]'
|
||||
|
||||
return (
|
||||
<div>
|
||||
{/* Hint Bar above Thumbnail Strip */}
|
||||
<div className="flex items-center justify-between border-t border-slate-100 px-4 py-2 text-[11px] text-slate-500">
|
||||
<span>{leftHint}</span>
|
||||
<span className="font-mono text-slate-400">{rightShortcut}</span>
|
||||
</div>
|
||||
|
||||
{/* 6 Image Thumbnails */}
|
||||
<ThumbnailStrip />
|
||||
|
||||
{/* Bottom Save & Export Status Bar */}
|
||||
<SaveStatus />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
63
src/pages/annotator/components/navigator/SaveStatus.tsx
Normal file
63
src/pages/annotator/components/navigator/SaveStatus.tsx
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
import React from 'react'
|
||||
import toast from 'react-hot-toast'
|
||||
import { exportToLabelMeJSON } from '@/utils/labelme'
|
||||
import { exportSegmentationMaskPNG } from '@/utils/mask'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
|
||||
export const SaveStatus: React.FC = () => {
|
||||
const project = useAnnotatorStore((s) => s.project)
|
||||
const currentImage = useAnnotatorStore((s) => s.images[s.currentImageIndex])
|
||||
const shapesByImageId = useAnnotatorStore((s) => s.shapesByImageId)
|
||||
const lastSavedAt = useAnnotatorStore((s) => s.lastSavedAt)
|
||||
|
||||
const shapes = currentImage ? shapesByImageId[currentImage.id] ?? [] : []
|
||||
|
||||
const handleExportLabelMe = () => {
|
||||
if (!currentImage) return
|
||||
exportToLabelMeJSON(currentImage, shapes, true)
|
||||
toast.success(`Đã xuất ${currentImage.fileName.replace(/\.[^/.]+$/, '')}_labelme.json`)
|
||||
}
|
||||
|
||||
const handleExportMask = () => {
|
||||
if (!currentImage) return
|
||||
exportSegmentationMaskPNG(currentImage, shapes, true)
|
||||
toast.success(`Đã xuất ${currentImage.fileName.replace(/\.[^/.]+$/, '')}_mask.png`)
|
||||
}
|
||||
|
||||
const rightStatusSummary =
|
||||
project.taskType === 'classification'
|
||||
? `Chờ duyệt · ${project.stats.pendingReview} ảnh`
|
||||
: project.taskType === 'object_detection'
|
||||
? `Chờ duyệt · ${project.stats.pendingReview} ảnh`
|
||||
: `Đang làm · ${project.stats.inProgress} ảnh`
|
||||
|
||||
return (
|
||||
<div className="flex flex-wrap items-center justify-between border-t border-slate-100 px-4 py-2.5 text-xs">
|
||||
<div className="flex items-center gap-1.5 font-medium text-[#15803D]">
|
||||
<span>✓</span>
|
||||
<span>Đã lưu lúc {lastSavedAt}</span>
|
||||
</div>
|
||||
|
||||
{project.taskType === 'segmentation' && (
|
||||
<div className="flex items-center gap-5">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleExportLabelMe}
|
||||
className="font-semibold text-[#4F46E5] transition-colors hover:text-[#3730A3] hover:underline"
|
||||
>
|
||||
Xuất LabelMe JSON ↓
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleExportMask}
|
||||
className="font-semibold text-[#4F46E5] transition-colors hover:text-[#3730A3] hover:underline"
|
||||
>
|
||||
Xuất mask PNG ↓
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="text-slate-500">{rightStatusSummary}</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
54
src/pages/annotator/components/navigator/ThumbnailStrip.tsx
Normal file
54
src/pages/annotator/components/navigator/ThumbnailStrip.tsx
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
|
||||
export const ThumbnailStrip: React.FC = () => {
|
||||
const images = useAnnotatorStore((s) => s.images)
|
||||
const currentImageIndex = useAnnotatorStore((s) => s.currentImageIndex)
|
||||
const selectImageByIndex = useAnnotatorStore((s) => s.selectImageByIndex)
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-6 gap-2.5 px-4 py-2.5">
|
||||
{images.map((img, index) => {
|
||||
const isActive = index === currentImageIndex
|
||||
// Shorten "urban_00124.jpg" -> "..00124.jpg" matching wireframe
|
||||
const shortName = img.fileName.replace(/^[a-z]+_/, '..')
|
||||
|
||||
return (
|
||||
<button
|
||||
key={img.id}
|
||||
type="button"
|
||||
onClick={() => selectImageByIndex(index)}
|
||||
className="group flex flex-col items-center gap-1 focus:outline-none"
|
||||
>
|
||||
<div
|
||||
className={clsx(
|
||||
'relative aspect-video w-full overflow-hidden rounded-lg border-2 transition-all',
|
||||
isActive
|
||||
? 'border-[#4F46E5] shadow-xs'
|
||||
: 'border-transparent opacity-85 hover:opacity-100'
|
||||
)}
|
||||
>
|
||||
<img
|
||||
src={img.thumbnailUrl}
|
||||
alt={img.fileName}
|
||||
className="h-full w-full object-cover"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<span
|
||||
className={clsx(
|
||||
'font-mono text-[10px] transition-colors',
|
||||
isActive
|
||||
? 'font-semibold text-[#4F46E5]'
|
||||
: 'text-slate-400 group-hover:text-slate-600'
|
||||
)}
|
||||
>
|
||||
{shortName}
|
||||
</span>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
import { StatusBadge } from './StatusBadge'
|
||||
import { ImageFlagCheckboxes } from './ImageFlagCheckboxes'
|
||||
import { ReviewActions } from './ReviewActions'
|
||||
|
||||
export const ClassificationPanel: React.FC = () => {
|
||||
const classes = useAnnotatorStore((s) => s.project.classes)
|
||||
const currentImage = useAnnotatorStore((s) => s.images[s.currentImageIndex])
|
||||
const classificationByImageId = useAnnotatorStore((s) => s.classificationByImageId)
|
||||
const statusByImageId = useAnnotatorStore((s) => s.statusByImageId)
|
||||
const setClassificationLabel = useAnnotatorStore((s) => s.setClassificationLabel)
|
||||
|
||||
if (!currentImage) return null
|
||||
|
||||
const activeClassId = classificationByImageId[currentImage.id] ?? 'cls-car'
|
||||
const activeClass = classes.find((c) => c.id === activeClassId) ?? classes[0]
|
||||
const currentStatus = statusByImageId[currentImage.id] ?? 'pending_review'
|
||||
|
||||
return (
|
||||
<div className="flex flex-col space-y-3.5 rounded-2xl border border-slate-200/80 bg-white p-5 shadow-2xs">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-sm font-bold text-slate-900">Nhãn cấp ảnh</h3>
|
||||
<span className="text-xs font-medium text-[#4F46E5]">1 nhãn / ảnh</span>
|
||||
</div>
|
||||
|
||||
{/* Status Badge */}
|
||||
<div>
|
||||
<StatusBadge status={currentStatus} />
|
||||
</div>
|
||||
|
||||
<p className="text-xs text-slate-500">Chọn một lớp cho toàn bộ ảnh.</p>
|
||||
|
||||
{/* Class Radio Cards */}
|
||||
<div className="space-y-2.5">
|
||||
{classes.map((cls, index) => {
|
||||
const isSelected = cls.id === activeClassId
|
||||
return (
|
||||
<button
|
||||
key={cls.id}
|
||||
type="button"
|
||||
onClick={() => setClassificationLabel(cls.id)}
|
||||
className={clsx(
|
||||
'flex w-full items-center justify-between rounded-xl border px-3.5 py-3 text-left transition-all',
|
||||
isSelected
|
||||
? 'border-[#4F46E5] bg-[#FDECE7] shadow-2xs'
|
||||
: 'border-slate-200 bg-white hover:border-slate-300'
|
||||
)}
|
||||
>
|
||||
<div className="flex items-center gap-2.5">
|
||||
<span
|
||||
className={clsx(
|
||||
'flex h-4 w-4 items-center justify-center rounded-full border transition-colors',
|
||||
isSelected
|
||||
? 'border-[#4F46E5] bg-[#4F46E5]'
|
||||
: 'border-slate-300 bg-white'
|
||||
)}
|
||||
>
|
||||
{isSelected && (
|
||||
<span className="h-1.5 w-1.5 rounded-full bg-white" />
|
||||
)}
|
||||
</span>
|
||||
<span className="text-xs font-semibold text-slate-900">
|
||||
{cls.name}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<span className="font-mono text-xs text-slate-400">
|
||||
{cls.shortcutKey ?? index + 1}
|
||||
</span>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* Image Flags */}
|
||||
<ImageFlagCheckboxes />
|
||||
|
||||
{/* Reviewer Info Box */}
|
||||
<div className="rounded-xl bg-slate-50 p-3.5">
|
||||
<p className="text-xs font-semibold text-slate-800">
|
||||
{currentImage.submittedBy ?? 'Hà Linh'} đã gửi nhãn {activeClass?.name ?? 'Ô tô'}
|
||||
</p>
|
||||
<p className="mt-1 text-[11px] text-slate-500">
|
||||
{currentImage.submittedAt ?? 'Hôm nay, 09:42'} · Người duyệt:{' '}
|
||||
{currentImage.reviewerName ?? 'Thu Hà'}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Review Actions */}
|
||||
<ReviewActions approveLabel="Duyệt nhãn" targetStatusOnApprove="completed" />
|
||||
|
||||
<p className="text-[11px] text-slate-400">
|
||||
Enter để duyệt · 1–4 chọn lớp
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
import React from 'react'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
|
||||
export const ImageFlagCheckboxes: React.FC = () => {
|
||||
const currentImage = useAnnotatorStore((s) => s.images[s.currentImageIndex])
|
||||
const flagsByImageId = useAnnotatorStore((s) => s.flagsByImageId)
|
||||
const toggleFlag = useAnnotatorStore((s) => s.toggleFlag)
|
||||
|
||||
if (!currentImage) return null
|
||||
|
||||
const flags = flagsByImageId[currentImage.id] ?? {
|
||||
blurryOrUncertain: false,
|
||||
needsRecheck: false,
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-2 pt-1">
|
||||
<h4 className="text-xs font-bold text-slate-800">Cờ cấp ảnh</h4>
|
||||
<label className="flex cursor-pointer items-center gap-2 text-xs text-slate-600 hover:text-slate-900">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={flags.blurryOrUncertain}
|
||||
onChange={() => toggleFlag('blurryOrUncertain')}
|
||||
className="h-3.5 w-3.5 rounded-xs border-slate-300 text-[#C95C3C] focus:ring-[#C95C3C]"
|
||||
/>
|
||||
<span>Ảnh mờ / khó xác định</span>
|
||||
</label>
|
||||
<label className="flex cursor-pointer items-center gap-2 text-xs text-slate-600 hover:text-slate-900">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={flags.needsRecheck}
|
||||
onChange={() => toggleFlag('needsRecheck')}
|
||||
className="h-3.5 w-3.5 rounded-xs border-slate-300 text-[#C95C3C] focus:ring-[#C95C3C]"
|
||||
/>
|
||||
<span>Cần kiểm tra lại</span>
|
||||
</label>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
import React from 'react'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
|
||||
export const LabelSelector: React.FC = () => {
|
||||
const classes = useAnnotatorStore((s) => s.project.classes)
|
||||
const selectedClassId = useAnnotatorStore((s) => s.selectedClassId)
|
||||
const activeGroupId = useAnnotatorStore((s) => s.activeGroupId)
|
||||
const updateSelectedShapeClass = useAnnotatorStore((s) => s.updateSelectedShapeClass)
|
||||
const setActiveGroupId = useAnnotatorStore((s) => s.setActiveGroupId)
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-3 gap-2.5 pt-1">
|
||||
<div className="col-span-2">
|
||||
<label className="mb-1 block text-[11px] font-medium text-slate-500">
|
||||
Nhãn
|
||||
</label>
|
||||
<div className="relative">
|
||||
<select
|
||||
value={selectedClassId}
|
||||
onChange={(e) => updateSelectedShapeClass(e.target.value)}
|
||||
className="w-full appearance-none rounded-xl border border-slate-200 bg-white px-3 py-2 pr-8 text-xs font-semibold text-slate-800 focus:border-[#4F46E5] focus:outline-none"
|
||||
>
|
||||
{classes.map((cls) => (
|
||||
<option key={cls.id} value={cls.id}>
|
||||
{cls.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<span className="pointer-events-none absolute inset-y-0 right-2.5 flex items-center text-slate-400">
|
||||
<svg className="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<polyline points="6 9 12 15 18 9" />
|
||||
</svg>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="mb-1 block text-[11px] font-medium text-slate-500">
|
||||
Mã nhóm
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
min={1}
|
||||
max={99}
|
||||
value={activeGroupId}
|
||||
onChange={(e) => setActiveGroupId(Math.max(1, Number(e.target.value) || 1))}
|
||||
className="w-full rounded-xl border border-slate-200 bg-white px-3 py-2 text-xs font-semibold text-slate-800 focus:border-[#4F46E5] focus:outline-none"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
100
src/pages/annotator/components/sidebar-right/ObjectItem.tsx
Normal file
100
src/pages/annotator/components/sidebar-right/ObjectItem.tsx
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
import { AnnotationShape, TaskType } from '@/types'
|
||||
|
||||
export interface ObjectItemProps {
|
||||
shape: AnnotationShape
|
||||
isSelected: boolean
|
||||
taskType: TaskType
|
||||
onSelect: () => void
|
||||
onToggleVisible: () => void
|
||||
onDelete: () => void
|
||||
}
|
||||
|
||||
export const ObjectItem: React.FC<ObjectItemProps> = ({
|
||||
shape,
|
||||
isSelected,
|
||||
taskType,
|
||||
onSelect,
|
||||
onToggleVisible,
|
||||
onDelete,
|
||||
}) => {
|
||||
const indexFormatted = String(shape.index).padStart(2, '0')
|
||||
|
||||
return (
|
||||
<div
|
||||
onClick={onSelect}
|
||||
className={clsx(
|
||||
'group cursor-pointer rounded-xl border px-3.5 py-2.5 transition-all',
|
||||
isSelected
|
||||
? 'border-[#C95C3C]/30 bg-[#FDECE7]/85'
|
||||
: 'border-slate-200/90 bg-white hover:border-slate-300'
|
||||
)}
|
||||
>
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<div className="flex items-center gap-2.5">
|
||||
<span
|
||||
className="h-2.5 w-2.5 shrink-0 rounded-xs"
|
||||
style={{ backgroundColor: shape.color }}
|
||||
/>
|
||||
<span className="text-xs font-semibold text-slate-800">
|
||||
{shape.labelName}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="font-mono text-[11px] text-slate-400">
|
||||
{taskType === 'segmentation' ? `#${indexFormatted}` : indexFormatted}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
onToggleVisible()
|
||||
}}
|
||||
title={shape.visible ? 'Ẩn đối tượng' : 'Hiện đối tượng'}
|
||||
className={clsx(
|
||||
'rounded-md p-0.5 transition-colors',
|
||||
shape.visible
|
||||
? 'text-slate-500 hover:text-slate-800'
|
||||
: 'text-slate-300 hover:text-slate-500'
|
||||
)}
|
||||
>
|
||||
<svg className="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" />
|
||||
<circle cx="12" cy="12" r="3" />
|
||||
</svg>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
onDelete()
|
||||
}}
|
||||
title="Xóa đối tượng (Delete)"
|
||||
className="hidden rounded-md p-0.5 text-slate-400 transition-colors hover:text-red-600 group-hover:inline-flex"
|
||||
>
|
||||
<svg className="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<polyline points="3 6 5 6 21 6" />
|
||||
<path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Selected subtitle: BBox coordinates or Polygon vertex/group metadata */}
|
||||
{isSelected && taskType === 'object_detection' && shape.bbox && (
|
||||
<div className="mt-1.5 font-mono text-[11px] text-slate-500">
|
||||
x: {shape.bbox.x} y: {shape.bbox.y} w: {shape.bbox.width} h:{' '}
|
||||
{shape.bbox.height}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{isSelected && taskType === 'segmentation' && shape.points && (
|
||||
<div className="mt-1 font-mono text-[11px] text-slate-500">
|
||||
polygon · {shape.points.length} đỉnh · group {shape.groupId ?? 1}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
141
src/pages/annotator/components/sidebar-right/ObjectListPanel.tsx
Normal file
141
src/pages/annotator/components/sidebar-right/ObjectListPanel.tsx
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
import { ObjectItem } from './ObjectItem'
|
||||
import { StatusBadge } from './StatusBadge'
|
||||
import { ReviewActions } from './ReviewActions'
|
||||
|
||||
export const ObjectListPanel: React.FC = () => {
|
||||
const classes = useAnnotatorStore((s) => s.project.classes)
|
||||
const currentImage = useAnnotatorStore((s) => s.images[s.currentImageIndex])
|
||||
const shapesByImageId = useAnnotatorStore((s) => s.shapesByImageId)
|
||||
const statusByImageId = useAnnotatorStore((s) => s.statusByImageId)
|
||||
const selectedShapeId = useAnnotatorStore((s) => s.selectedShapeId)
|
||||
const selectedClassId = useAnnotatorStore((s) => s.selectedClassId)
|
||||
const showBoxes = useAnnotatorStore((s) => s.showBoxes)
|
||||
|
||||
const setShowBoxes = useAnnotatorStore((s) => s.setShowBoxes)
|
||||
const setSelectedShapeId = useAnnotatorStore((s) => s.setSelectedShapeId)
|
||||
const updateSelectedShapeClass = useAnnotatorStore((s) => s.updateSelectedShapeClass)
|
||||
const toggleShapeVisibility = useAnnotatorStore((s) => s.toggleShapeVisibility)
|
||||
const toggleAllShapesVisibility = useAnnotatorStore((s) => s.toggleAllShapesVisibility)
|
||||
const deleteShape = useAnnotatorStore((s) => s.deleteShape)
|
||||
|
||||
if (!currentImage) return null
|
||||
|
||||
const shapes = shapesByImageId[currentImage.id] ?? []
|
||||
const currentStatus = statusByImageId[currentImage.id] ?? 'pending_review'
|
||||
|
||||
const getCountByClass = (classId: string) =>
|
||||
shapes.filter((s) => s.labelId === classId).length
|
||||
|
||||
return (
|
||||
<div className="flex flex-col space-y-3.5 rounded-2xl border border-slate-200/80 bg-white p-5 shadow-2xs">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-sm font-bold text-slate-900">Danh sách đối tượng</h3>
|
||||
<span className="text-xs font-medium text-[#4F46E5]">{shapes.length} hình</span>
|
||||
</div>
|
||||
|
||||
{/* Show Bounding Boxes Toggle Row */}
|
||||
<div className="flex items-center justify-between">
|
||||
<label className="flex cursor-pointer items-center gap-2 text-xs text-slate-600">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={showBoxes}
|
||||
onChange={(e) => setShowBoxes(e.target.checked)}
|
||||
className="h-3.5 w-3.5 rounded-xs border-slate-300 text-slate-700 focus:ring-[#C95C3C]"
|
||||
/>
|
||||
<span>Hiện hộp giới hạn</span>
|
||||
</label>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={toggleAllShapesVisibility}
|
||||
title="Ẩn/Hiện tất cả"
|
||||
className="text-slate-500 hover:text-slate-800"
|
||||
>
|
||||
<svg className="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" />
|
||||
<circle cx="12" cy="12" r="3" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Object Cards List */}
|
||||
<div className="max-h-[260px] space-y-2 overflow-y-auto pr-0.5">
|
||||
{shapes.map((shape) => (
|
||||
<ObjectItem
|
||||
key={shape.id}
|
||||
shape={shape}
|
||||
isSelected={shape.id === selectedShapeId}
|
||||
taskType="object_detection"
|
||||
onSelect={() => setSelectedShapeId(shape.id)}
|
||||
onToggleVisible={() => toggleShapeVisibility(shape.id)}
|
||||
onDelete={() => deleteShape(shape.id)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Project Classes Pills */}
|
||||
<div className="space-y-2 pt-1">
|
||||
<h4 className="text-xs font-bold text-slate-800">Lớp trong dự án</h4>
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{classes.map((cls) => {
|
||||
const count = getCountByClass(cls.id)
|
||||
const isActive = cls.id === selectedClassId
|
||||
return (
|
||||
<button
|
||||
key={cls.id}
|
||||
type="button"
|
||||
onClick={() => updateSelectedShapeClass(cls.id)}
|
||||
className={clsx(
|
||||
'inline-flex items-center gap-1.5 rounded-lg border px-2.5 py-1 text-xs font-medium transition-colors',
|
||||
isActive
|
||||
? 'border-[#C95C3C]/40 bg-[#FDF4F1] text-slate-900'
|
||||
: 'border-slate-200 bg-slate-50 text-slate-700 hover:bg-slate-100'
|
||||
)}
|
||||
>
|
||||
<span
|
||||
className="h-1.5 w-1.5 rounded-full"
|
||||
style={{ backgroundColor: cls.color }}
|
||||
/>
|
||||
<span>
|
||||
{cls.name} · {count}
|
||||
</span>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* Active Class Dropdown */}
|
||||
<div className="flex items-center gap-1.5 pt-1 text-xs text-slate-500">
|
||||
<span>Lớp đang chọn:</span>
|
||||
<select
|
||||
value={selectedClassId}
|
||||
onChange={(e) => updateSelectedShapeClass(e.target.value)}
|
||||
className="cursor-pointer bg-transparent font-medium text-slate-700 focus:outline-none"
|
||||
>
|
||||
{classes.map((cls) => (
|
||||
<option key={cls.id} value={cls.id}>
|
||||
{cls.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Image Status Row */}
|
||||
<div className="flex items-center justify-between pt-1">
|
||||
<span className="text-xs text-slate-500">Trạng thái ảnh</span>
|
||||
<StatusBadge status={currentStatus} />
|
||||
</div>
|
||||
|
||||
{/* Review Actions */}
|
||||
<ReviewActions
|
||||
approveLabel={`Duyệt ${shapes.length} nhãn`}
|
||||
targetStatusOnApprove="completed"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
import React from 'react'
|
||||
import toast from 'react-hot-toast'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
|
||||
export interface ReviewActionsProps {
|
||||
approveLabel: string
|
||||
targetStatusOnApprove?: 'completed' | 'pending_review'
|
||||
}
|
||||
|
||||
export const ReviewActions: React.FC<ReviewActionsProps> = ({
|
||||
approveLabel,
|
||||
targetStatusOnApprove = 'completed',
|
||||
}) => {
|
||||
const updateImageStatus = useAnnotatorStore((s) => s.updateImageStatus)
|
||||
const currentImage = useAnnotatorStore((s) => s.images[s.currentImageIndex])
|
||||
|
||||
const handleReject = () => {
|
||||
updateImageStatus('in_progress')
|
||||
toast(`Đã trả lại ảnh ${currentImage?.fileName ?? ''} để chỉnh sửa`, {
|
||||
icon: '↩️',
|
||||
})
|
||||
}
|
||||
|
||||
const handleApprove = () => {
|
||||
updateImageStatus(targetStatusOnApprove)
|
||||
toast.success(
|
||||
targetStatusOnApprove === 'pending_review'
|
||||
? `Đã gửi duyệt ${currentImage?.fileName ?? ''}`
|
||||
: `Đã duyệt nhãn cho ${currentImage?.fileName ?? ''}`
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-2.5 pt-1">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleReject}
|
||||
className="inline-flex items-center justify-center rounded-xl border border-slate-200 bg-white px-4 py-2 text-xs font-semibold text-slate-800 shadow-2xs transition-colors hover:bg-slate-50"
|
||||
>
|
||||
Trả lại
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleApprove}
|
||||
className="inline-flex flex-1 items-center justify-center gap-1.5 rounded-xl bg-[#C95C3C] px-4 py-2 text-xs font-semibold text-white shadow-sm transition-colors hover:bg-[#B5492B]"
|
||||
>
|
||||
<span>✓</span>
|
||||
<span>{approveLabel}</span>
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1,133 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
import { useAnnotatorStore } from '../../annotatorStore'
|
||||
import { ObjectItem } from './ObjectItem'
|
||||
import { LabelSelector } from './LabelSelector'
|
||||
import { StatusBadge } from './StatusBadge'
|
||||
import { ReviewActions } from './ReviewActions'
|
||||
|
||||
export const SegmentationPanel: React.FC = () => {
|
||||
const currentImage = useAnnotatorStore((s) => s.images[s.currentImageIndex])
|
||||
const shapesByImageId = useAnnotatorStore((s) => s.shapesByImageId)
|
||||
const statusByImageId = useAnnotatorStore((s) => s.statusByImageId)
|
||||
const selectedShapeId = useAnnotatorStore((s) => s.selectedShapeId)
|
||||
const showMasks = useAnnotatorStore((s) => s.showMasks)
|
||||
const maskOpacity = useAnnotatorStore((s) => s.maskOpacity)
|
||||
const vertexEditEnabled = useAnnotatorStore((s) => s.vertexEditEnabled)
|
||||
|
||||
const setShowMasks = useAnnotatorStore((s) => s.setShowMasks)
|
||||
const setMaskOpacity = useAnnotatorStore((s) => s.setMaskOpacity)
|
||||
const toggleVertexEdit = useAnnotatorStore((s) => s.toggleVertexEdit)
|
||||
const setSelectedShapeId = useAnnotatorStore((s) => s.setSelectedShapeId)
|
||||
const toggleShapeVisibility = useAnnotatorStore((s) => s.toggleShapeVisibility)
|
||||
const toggleAllShapesVisibility = useAnnotatorStore((s) => s.toggleAllShapesVisibility)
|
||||
const deleteShape = useAnnotatorStore((s) => s.deleteShape)
|
||||
|
||||
if (!currentImage) return null
|
||||
|
||||
const shapes = shapesByImageId[currentImage.id] ?? []
|
||||
const currentStatus = statusByImageId[currentImage.id] ?? 'in_progress'
|
||||
|
||||
return (
|
||||
<div className="flex flex-col space-y-3.5 rounded-2xl border border-slate-200/80 bg-white p-5 shadow-2xs">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-sm font-bold text-slate-900">Hình và nhãn</h3>
|
||||
<span className="text-xs font-medium text-[#4F46E5]">{shapes.length} hình</span>
|
||||
</div>
|
||||
|
||||
{/* Show Mask Checkbox */}
|
||||
<div className="flex items-center justify-between">
|
||||
<label className="flex cursor-pointer items-center gap-2 text-xs text-slate-600">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={showMasks}
|
||||
onChange={(e) => setShowMasks(e.target.checked)}
|
||||
className="h-3.5 w-3.5 rounded-xs border-slate-300 text-slate-700 focus:ring-[#C95C3C]"
|
||||
/>
|
||||
<span>Hiện mask</span>
|
||||
</label>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={toggleAllShapesVisibility}
|
||||
title="Ẩn/Hiện tất cả mask"
|
||||
className="text-slate-500 hover:text-slate-800"
|
||||
>
|
||||
<svg className="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" />
|
||||
<circle cx="12" cy="12" r="3" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Mask Opacity Slider */}
|
||||
<div className="space-y-1.5">
|
||||
<div className="flex items-center justify-between text-xs">
|
||||
<span className="text-slate-500">Độ trong suốt</span>
|
||||
<span className="font-semibold text-[#4F46E5]">{maskOpacity}%</span>
|
||||
</div>
|
||||
<input
|
||||
type="range"
|
||||
min={5}
|
||||
max={90}
|
||||
step={5}
|
||||
value={maskOpacity}
|
||||
onChange={(e) => setMaskOpacity(Number(e.target.value))}
|
||||
className="h-1.5 w-full cursor-pointer appearance-none rounded-lg bg-slate-200 accent-[#C95C3C]"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Polygon Objects List */}
|
||||
<div className="max-h-[240px] space-y-2 overflow-y-auto pr-0.5">
|
||||
{shapes.map((shape) => (
|
||||
<ObjectItem
|
||||
key={shape.id}
|
||||
shape={shape}
|
||||
isSelected={shape.id === selectedShapeId}
|
||||
taskType="segmentation"
|
||||
onSelect={() => setSelectedShapeId(shape.id)}
|
||||
onToggleVisible={() => toggleShapeVisibility(shape.id)}
|
||||
onDelete={() => deleteShape(shape.id)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Label & Group Selector */}
|
||||
<LabelSelector />
|
||||
|
||||
{/* Vertex Edit Mode Button */}
|
||||
<div className="space-y-1.5 pt-1">
|
||||
<button
|
||||
type="button"
|
||||
onClick={toggleVertexEdit}
|
||||
className={clsx(
|
||||
'flex w-full items-center gap-2 rounded-xl px-3.5 py-2.5 text-xs font-semibold transition-colors',
|
||||
vertexEditEnabled
|
||||
? 'bg-[#FDECE7] text-[#4F46E5]'
|
||||
: 'border border-slate-200 bg-slate-50 text-slate-600 hover:bg-slate-100'
|
||||
)}
|
||||
>
|
||||
<svg className="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||
<path d="m3 3 7.07 16.97 2.51-7.39 7.39-2.51L3 3z" />
|
||||
<path d="m13 13 6 6" />
|
||||
</svg>
|
||||
<span>{vertexEditEnabled ? 'Sửa đỉnh đang bật' : 'Bật chế độ sửa đỉnh'}</span>
|
||||
</button>
|
||||
|
||||
<p className="text-[11px] leading-relaxed text-slate-400">
|
||||
Kéo đỉnh để sửa · Double-click cạnh để thêm đỉnh · Delete để xóa đỉnh.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Image Status Row */}
|
||||
<div className="flex items-center justify-between pt-1">
|
||||
<span className="text-xs text-slate-500">Trạng thái ảnh</span>
|
||||
<StatusBadge status={currentStatus} />
|
||||
</div>
|
||||
|
||||
{/* Review Actions */}
|
||||
<ReviewActions approveLabel="Gửi duyệt" targetStatusOnApprove="pending_review" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
54
src/pages/annotator/components/sidebar-right/StatusBadge.tsx
Normal file
54
src/pages/annotator/components/sidebar-right/StatusBadge.tsx
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import React from 'react'
|
||||
import clsx from 'clsx'
|
||||
import { ImageAnnotationStatus } from '@/types'
|
||||
|
||||
export interface StatusBadgeProps {
|
||||
status: ImageAnnotationStatus
|
||||
}
|
||||
|
||||
export const StatusBadge: React.FC<StatusBadgeProps> = ({ status }) => {
|
||||
const config: Record<
|
||||
ImageAnnotationStatus,
|
||||
{ label: string; bg: string; text: string; dot: string }
|
||||
> = {
|
||||
unassigned: {
|
||||
label: 'Chưa gán',
|
||||
bg: 'bg-slate-100',
|
||||
text: 'text-slate-600',
|
||||
dot: 'bg-slate-400',
|
||||
},
|
||||
in_progress: {
|
||||
label: 'Đang làm',
|
||||
bg: 'bg-[#FEE2E2]',
|
||||
text: 'text-[#B91C1C]',
|
||||
dot: 'bg-[#EF4444]',
|
||||
},
|
||||
pending_review: {
|
||||
label: 'Chờ duyệt',
|
||||
bg: 'bg-[#FEF3C7]',
|
||||
text: 'text-[#B45309]',
|
||||
dot: 'bg-[#F59E0B]',
|
||||
},
|
||||
completed: {
|
||||
label: 'Hoàn thành',
|
||||
bg: 'bg-[#DCFCE7]',
|
||||
text: 'text-[#15803D]',
|
||||
dot: 'bg-[#22C55E]',
|
||||
},
|
||||
}
|
||||
|
||||
const current = config[status] ?? config.pending_review
|
||||
|
||||
return (
|
||||
<span
|
||||
className={clsx(
|
||||
'inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1 text-xs font-semibold',
|
||||
current.bg,
|
||||
current.text
|
||||
)}
|
||||
>
|
||||
<span className={clsx('h-1.5 w-1.5 rounded-full', current.dot)} />
|
||||
<span>{current.label}</span>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
131
src/pages/auth/ForgotPasswordPage.tsx
Normal file
131
src/pages/auth/ForgotPasswordPage.tsx
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
import React, { useState } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
|
||||
export const ForgotPasswordPage: React.FC = () => {
|
||||
const [email, setEmail] = useState('minhanh@visionlab.vn')
|
||||
const [submitted, setSubmitted] = useState(false)
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
if (!email.trim()) return
|
||||
setSubmitted(true)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-white flex flex-col justify-between p-6 sm:p-12">
|
||||
{/* Header */}
|
||||
<header className="max-w-[1360px] w-full mx-auto flex items-center justify-between">
|
||||
<Link to="/login" className="flex items-center gap-2.5">
|
||||
<div className="w-8 h-8 rounded-lg bg-[#C95C3C] flex items-center justify-center text-white shadow-sm">
|
||||
<svg
|
||||
className="w-4 h-4"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2.2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="M4 8V6a2 2 0 0 1 2-2h2" />
|
||||
<path d="M4 16v2a2 2 0 0 0 2 2h2" />
|
||||
<path d="M16 4h2a2 2 0 0 1 2 2v2" />
|
||||
<path d="M16 20h2a2 2 0 0 0 2-2v-2" />
|
||||
</svg>
|
||||
</div>
|
||||
<span className="text-xl font-bold tracking-tight text-slate-900">
|
||||
danable
|
||||
</span>
|
||||
</Link>
|
||||
|
||||
<Link
|
||||
to="/login"
|
||||
className="text-xs font-semibold text-indigo-600 hover:text-indigo-700"
|
||||
>
|
||||
← Quay lại đăng nhập
|
||||
</Link>
|
||||
</header>
|
||||
|
||||
{/* Main Recovery Card */}
|
||||
<main className="w-full max-w-[420px] mx-auto my-auto py-12">
|
||||
<p className="text-[11px] font-semibold uppercase tracking-[0.08em] text-indigo-600 mb-2">
|
||||
KHÔI PHỤC TÀI KHOẢN
|
||||
</p>
|
||||
<h1 className="text-2xl sm:text-[28px] font-bold text-slate-900 tracking-tight mb-2">
|
||||
Quên mật khẩu?
|
||||
</h1>
|
||||
<p className="text-sm text-slate-500 mb-6">
|
||||
Nhập email công việc của bạn để nhận liên kết đặt lại mật khẩu an toàn.
|
||||
</p>
|
||||
|
||||
{submitted ? (
|
||||
<div className="rounded-2xl border border-emerald-200 bg-emerald-50/70 p-5 space-y-4">
|
||||
<div className="flex items-center gap-2.5 text-emerald-800 font-semibold text-sm">
|
||||
<span className="w-2 h-2 rounded-full bg-emerald-500" />
|
||||
<span>Đã gửi hướng dẫn khôi phục mật khẩu</span>
|
||||
</div>
|
||||
<p className="text-xs text-slate-600 leading-relaxed">
|
||||
Nếu địa chỉ <span className="font-semibold text-slate-800">{email}</span> tồn tại trong không gian nhóm, bạn sẽ nhận được email hướng dẫn trong vòng vài phút.
|
||||
</p>
|
||||
<div className="pt-2 flex items-center justify-between">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setSubmitted(false)}
|
||||
className="text-xs font-medium text-slate-600 hover:text-slate-900"
|
||||
>
|
||||
Gửi lại với email khác
|
||||
</button>
|
||||
<Link
|
||||
to="/login"
|
||||
className="px-4 py-2 rounded-xl bg-[#C95C3C] text-white text-xs font-semibold hover:bg-[#B5492B] transition-colors"
|
||||
>
|
||||
Quay lại đăng nhập
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
<div>
|
||||
<label
|
||||
htmlFor="recovery-email"
|
||||
className="block text-[13px] font-medium text-slate-800 mb-1.5"
|
||||
>
|
||||
Email công việc
|
||||
</label>
|
||||
<input
|
||||
id="recovery-email"
|
||||
type="email"
|
||||
required
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
placeholder="minhanh@visionlab.vn"
|
||||
className="w-full px-4 py-2.5 rounded-xl border border-slate-200 bg-white text-sm text-slate-900 focus:outline-none focus:border-[#C95C3C] focus:ring-2 focus:ring-[#C95C3C]/15"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
className="w-full py-3 px-4 rounded-xl bg-[#C95C3C] hover:bg-[#B5492B] text-white text-sm font-semibold transition-colors"
|
||||
>
|
||||
Gửi liên kết đặt lại mật khẩu →
|
||||
</button>
|
||||
|
||||
<div className="text-center pt-2">
|
||||
<Link
|
||||
to="/login"
|
||||
className="text-xs font-medium text-slate-600 hover:text-slate-900"
|
||||
>
|
||||
← Quay lại trang đăng nhập
|
||||
</Link>
|
||||
</div>
|
||||
</form>
|
||||
)}
|
||||
</main>
|
||||
|
||||
<footer className="text-center text-xs text-slate-400">
|
||||
© 2026 danable. Dữ liệu của bạn, quyền kiểm soát của bạn.
|
||||
</footer>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default ForgotPasswordPage
|
||||
151
src/pages/auth/LoginPage.tsx
Normal file
151
src/pages/auth/LoginPage.tsx
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
import React, { useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { LoginRequest } from '../../types'
|
||||
import { HeroSection } from './components/HeroSection'
|
||||
import { LoginForm } from './components/LoginForm'
|
||||
|
||||
export const LoginPage: React.FC = () => {
|
||||
const navigate = useNavigate()
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const [contactModalOpen, setContactModalOpen] = useState(false)
|
||||
|
||||
const handleLogin = (_credentials: LoginRequest) => {
|
||||
setIsLoading(true)
|
||||
setTimeout(() => {
|
||||
setIsLoading(false)
|
||||
navigate('/projects')
|
||||
}, 250)
|
||||
}
|
||||
|
||||
const handleSSOLogin = () => {
|
||||
setIsLoading(true)
|
||||
setTimeout(() => {
|
||||
setIsLoading(false)
|
||||
navigate('/projects')
|
||||
}, 250)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-white text-slate-900 flex flex-col justify-between">
|
||||
{/* Top Navigation Bar matching wireframe */}
|
||||
<header className="w-full max-w-[1360px] mx-auto px-6 sm:px-12 pt-7 pb-4 flex items-center justify-between">
|
||||
<div className="flex items-center gap-16">
|
||||
{/* Brand Logo */}
|
||||
<div className="flex items-center gap-2.5">
|
||||
<div className="w-8 h-8 rounded-lg bg-[#C95C3C] flex items-center justify-center text-white shadow-sm">
|
||||
<svg
|
||||
className="w-4 h-4"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2.2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="M4 8V6a2 2 0 0 1 2-2h2" />
|
||||
<path d="M4 16v2a2 2 0 0 0 2 2h2" />
|
||||
<path d="M16 4h2a2 2 0 0 1 2 2v2" />
|
||||
<path d="M16 20h2a2 2 0 0 0 2-2v-2" />
|
||||
</svg>
|
||||
</div>
|
||||
<span className="text-xl font-bold tracking-tight text-slate-900">
|
||||
danable
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<span className="hidden md:inline-block text-[10px] font-semibold uppercase tracking-[0.14em] text-slate-500">
|
||||
NỀN TẢNG DỮ LIỆU CHO AI
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="text-xs text-slate-500">
|
||||
<span>Chưa có tài khoản? </span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setContactModalOpen(true)}
|
||||
className="font-semibold text-indigo-600 hover:text-indigo-700 inline-flex items-center gap-0.5"
|
||||
>
|
||||
<span>Liên hệ quản trị viên</span>
|
||||
<span aria-hidden="true">↗</span>
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{/* Main 2-Column Content */}
|
||||
<main className="w-full max-w-[1360px] mx-auto px-6 sm:px-12 py-6 flex-1 flex items-center">
|
||||
<div className="w-full grid grid-cols-1 lg:grid-cols-12 gap-12 lg:gap-8 items-center">
|
||||
{/* Left Column: HeroSection */}
|
||||
<div className="lg:col-span-6">
|
||||
<HeroSection />
|
||||
</div>
|
||||
|
||||
{/* Right Column: LoginForm */}
|
||||
<div className="lg:col-span-6 flex flex-col items-center">
|
||||
<LoginForm
|
||||
onSubmit={handleLogin}
|
||||
onSSOLogin={handleSSOLogin}
|
||||
isLoading={isLoading}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
{/* Bottom Footer Links */}
|
||||
<footer className="w-full max-w-[1360px] mx-auto px-6 sm:px-12 py-6 flex flex-col sm:flex-row items-center justify-end gap-6 text-xs text-slate-500">
|
||||
<div className="flex items-center gap-6 lg:w-1/2 justify-center">
|
||||
<a
|
||||
href="#terms"
|
||||
onClick={(e) => e.preventDefault()}
|
||||
className="hover:text-slate-800 transition-colors"
|
||||
>
|
||||
Điều khoản sử dụng
|
||||
</a>
|
||||
<a
|
||||
href="#privacy"
|
||||
onClick={(e) => e.preventDefault()}
|
||||
className="hover:text-slate-800 transition-colors"
|
||||
>
|
||||
Chính sách bảo mật
|
||||
</a>
|
||||
<button
|
||||
type="button"
|
||||
className="inline-flex items-center gap-1 hover:text-slate-800 transition-colors"
|
||||
>
|
||||
<span>Tiếng Việt</span>
|
||||
<span className="text-[10px]">∨</span>
|
||||
</button>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
{/* Contact Admin Info Modal */}
|
||||
{contactModalOpen && (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-slate-900/40 backdrop-blur-[1px] p-4">
|
||||
<div className="bg-white rounded-2xl max-w-md w-full p-6 shadow-xl border border-slate-200">
|
||||
<h3 className="text-lg font-bold text-slate-900 mb-2">
|
||||
Liên hệ quản trị viên không gian nhóm
|
||||
</h3>
|
||||
<p className="text-sm text-slate-600 leading-relaxed mb-4">
|
||||
danable hoạt động theo mô hình lời mời nội bộ để đảm bảo an toàn
|
||||
dữ liệu. Vui lòng liên hệ Quản trị viên nhóm của bạn (ví dụ:{' '}
|
||||
<span className="font-medium text-slate-900">
|
||||
minhanh@visionlab.vn
|
||||
</span>
|
||||
) để nhận email lời mời tham gia dự án.
|
||||
</p>
|
||||
<div className="flex justify-end">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setContactModalOpen(false)}
|
||||
className="px-4 py-2 rounded-xl bg-[#C95C3C] text-white text-sm font-medium hover:bg-[#B5492B] transition-colors"
|
||||
>
|
||||
Đã hiểu
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default LoginPage
|
||||
153
src/pages/auth/components/HeroSection.tsx
Normal file
153
src/pages/auth/components/HeroSection.tsx
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
import React, { useState } from 'react'
|
||||
|
||||
export const HeroSection: React.FC = () => {
|
||||
const [hoveredBox, setHoveredBox] = useState<'bus' | 'car' | null>(null)
|
||||
const [activeTask, setActiveTask] = useState<string>('Object Detection')
|
||||
|
||||
return (
|
||||
<div className="flex flex-col justify-between h-full max-w-[540px]">
|
||||
<div>
|
||||
<p className="text-[11px] font-semibold uppercase tracking-[0.12em] text-slate-600 mb-3">
|
||||
TỪ DỮ LIỆU THÔ ĐẾN NHÃN CHẤT LƯỢNG
|
||||
</p>
|
||||
|
||||
<h1 className="text-4xl sm:text-[42px] font-bold tracking-tight text-slate-900 leading-[1.15] mb-3.5">
|
||||
Giải pháp dữ liệu cho AI
|
||||
</h1>
|
||||
|
||||
<p className="text-[15px] text-slate-600 leading-relaxed mb-7">
|
||||
Kiểm soát chất lượng mô hình AI của bạn từ những bước bắt đầu.
|
||||
</p>
|
||||
|
||||
{/* Interactive Preview Card */}
|
||||
<div className="rounded-2xl border border-slate-300 bg-white shadow-sm overflow-hidden transition-shadow hover:shadow-md">
|
||||
{/* Card Top Bar */}
|
||||
<div className="flex items-center justify-between px-4 py-3 border-b border-slate-200 bg-white">
|
||||
<span className="text-xs font-medium text-slate-700">
|
||||
Giao thông đô thị
|
||||
</span>
|
||||
<span className="inline-flex items-center gap-1.5 text-xs font-medium text-slate-600">
|
||||
<span className="h-1.5 w-1.5 rounded-full bg-emerald-500" />
|
||||
Đã duyệt thủ công
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* Street Traffic Image + Bounding Box Overlays */}
|
||||
<div className="relative h-[265px] sm:h-[285px] w-full overflow-hidden bg-slate-900 select-none">
|
||||
<img
|
||||
src="https://images.unsplash.com/photo-1519003722824-194d4455a60c?auto=format&fit=crop&w=1080&q=85"
|
||||
alt="Giao thông đô thị Việt Nam"
|
||||
className="w-full h-full object-cover object-center brightness-95"
|
||||
/>
|
||||
|
||||
{/* Subtle road scene gradient for crisp bounding box contrast */}
|
||||
<div className="absolute inset-0 bg-gradient-to-t from-black/25 via-transparent to-black/10 pointer-events-none" />
|
||||
|
||||
{/* Purple Bounding Box: Xe buýt */}
|
||||
<div
|
||||
onMouseEnter={() => setHoveredBox('bus')}
|
||||
onMouseLeave={() => setHoveredBox(null)}
|
||||
style={{
|
||||
left: '28%',
|
||||
top: '35%',
|
||||
width: '20%',
|
||||
height: '31%',
|
||||
}}
|
||||
className={`absolute border-2 transition-all duration-150 cursor-pointer ${
|
||||
hoveredBox === 'bus'
|
||||
? 'border-[#A855F7] bg-[#A855F7]/20 shadow-[0_0_0_2px_rgba(168,85,247,0.3)]'
|
||||
: 'border-[#C084FC] bg-[#A855F7]/10'
|
||||
}`}
|
||||
>
|
||||
<span className="absolute -top-6 left-[-2px] inline-flex items-center px-2 py-0.5 rounded-t-md rounded-br-md bg-[#C084FC] text-slate-950 text-[11px] font-bold shadow-sm whitespace-nowrap">
|
||||
Xe buýt
|
||||
</span>
|
||||
{/* Corner handles */}
|
||||
<span className="absolute -top-1 -left-1 w-2 h-2 bg-white border border-[#A855F7] rounded-full" />
|
||||
<span className="absolute -top-1 -right-1 w-2 h-2 bg-white border border-[#A855F7] rounded-full" />
|
||||
<span className="absolute -bottom-1 -left-1 w-2 h-2 bg-white border border-[#A855F7] rounded-full" />
|
||||
<span className="absolute -bottom-1 -right-1 w-2 h-2 bg-white border border-[#A855F7] rounded-full" />
|
||||
</div>
|
||||
|
||||
{/* Cyan Bounding Box: Ô tô */}
|
||||
<div
|
||||
onMouseEnter={() => setHoveredBox('car')}
|
||||
onMouseLeave={() => setHoveredBox(null)}
|
||||
style={{
|
||||
left: '45.5%',
|
||||
top: '57%',
|
||||
width: '13.5%',
|
||||
height: '24%',
|
||||
}}
|
||||
className={`absolute border-2 transition-all duration-150 cursor-pointer ${
|
||||
hoveredBox === 'car'
|
||||
? 'border-[#06B6D4] bg-[#06B6D4]/25 shadow-[0_0_0_2px_rgba(6,182,212,0.35)]'
|
||||
: 'border-[#22D3EE] bg-[#06B6D4]/10'
|
||||
}`}
|
||||
>
|
||||
<span className="absolute -top-6 left-[-2px] inline-flex items-center px-2 py-0.5 rounded-t-md rounded-br-md bg-[#22D3EE] text-slate-950 text-[11px] font-bold shadow-sm whitespace-nowrap">
|
||||
Ô tô
|
||||
</span>
|
||||
{/* Corner handles */}
|
||||
<span className="absolute -top-1 -left-1 w-2 h-2 bg-white border border-[#06B6D4] rounded-full" />
|
||||
<span className="absolute -top-1 -right-1 w-2 h-2 bg-white border border-[#06B6D4] rounded-full" />
|
||||
<span className="absolute -bottom-1 -left-1 w-2 h-2 bg-white border border-[#06B6D4] rounded-full" />
|
||||
<span className="absolute -bottom-1 -right-1 w-2 h-2 bg-white border border-[#06B6D4] rounded-full" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Card Bottom Stats */}
|
||||
<div className="flex items-center justify-between px-5 py-4 bg-white border-t border-slate-200">
|
||||
<div>
|
||||
<div className="text-xl font-bold text-slate-900 tracking-tight">
|
||||
4.320
|
||||
</div>
|
||||
<div className="text-xs text-slate-500 mt-0.5">
|
||||
ảnh trong không gian nhóm
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="text-right">
|
||||
<div className="text-xl font-bold text-slate-900 tracking-tight">
|
||||
Bạn quyết định
|
||||
</div>
|
||||
<div className="text-xs text-slate-500 mt-0.5">
|
||||
duyệt nhãn trước khi xuất
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Bottom Task Tags */}
|
||||
<div className="flex items-center gap-6 mt-6">
|
||||
{(['Classification', 'Object Detection', 'Segmentation'] as const).map(
|
||||
(task) => {
|
||||
const isSelected = activeTask === task
|
||||
return (
|
||||
<button
|
||||
key={task}
|
||||
type="button"
|
||||
onClick={() => setActiveTask(task)}
|
||||
className={`text-xs transition-colors ${
|
||||
isSelected
|
||||
? 'font-semibold text-slate-900 underline decoration-[#C95C3C] decoration-2 underline-offset-4'
|
||||
: 'font-medium text-slate-600 hover:text-slate-900'
|
||||
}`}
|
||||
>
|
||||
{task}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Footer Copyright */}
|
||||
<p className="text-xs text-slate-500 mt-8">
|
||||
© 2026 danable. Dữ liệu của bạn, quyền kiểm soát của bạn.
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default HeroSection
|
||||
234
src/pages/auth/components/LoginForm.tsx
Normal file
234
src/pages/auth/components/LoginForm.tsx
Normal file
|
|
@ -0,0 +1,234 @@
|
|||
import React, { useState } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { LoginRequest } from '../../../types'
|
||||
import { SSOButton } from './SSOButton'
|
||||
|
||||
export interface LoginFormProps {
|
||||
onSubmit: (data: LoginRequest) => void
|
||||
onSSOLogin?: () => void
|
||||
isLoading?: boolean
|
||||
}
|
||||
|
||||
export const LoginForm: React.FC<LoginFormProps> = ({
|
||||
onSubmit,
|
||||
onSSOLogin,
|
||||
isLoading = false,
|
||||
}) => {
|
||||
const [email, setEmail] = useState<string>('minhanh@visionlab.vn')
|
||||
const [password, setPassword] = useState<string>('••••••••••••')
|
||||
const [rememberMe, setRememberMe] = useState<boolean>(true)
|
||||
const [showPassword, setShowPassword] = useState<boolean>(false)
|
||||
const [errorMessage, setErrorMessage] = useState<string | null>(null)
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
if (!email.trim()) {
|
||||
setErrorMessage('Vui lòng nhập email công việc của bạn.')
|
||||
return
|
||||
}
|
||||
if (!password) {
|
||||
setErrorMessage('Vui lòng nhập mật khẩu.')
|
||||
return
|
||||
}
|
||||
setErrorMessage(null)
|
||||
onSubmit({
|
||||
email: email.trim(),
|
||||
password,
|
||||
rememberMe,
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="w-full max-w-[420px] mx-auto">
|
||||
{/* Header */}
|
||||
<div className="mb-6">
|
||||
<p className="text-[11px] font-semibold uppercase tracking-[0.08em] text-indigo-600 mb-2">
|
||||
CHÀO MỪNG TRỞ LẠI
|
||||
</p>
|
||||
<h2 className="text-[28px] font-bold text-slate-900 tracking-tight leading-tight mb-2">
|
||||
Đăng nhập vào danable
|
||||
</h2>
|
||||
<p className="text-sm text-slate-500">
|
||||
Tiếp tục xây dựng bộ dữ liệu tốt hơn, cùng đội ngũ của bạn.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* SSO Button */}
|
||||
<SSOButton onClick={onSSOLogin} isLoading={isLoading} />
|
||||
|
||||
{/* Divider */}
|
||||
<div className="relative flex items-center justify-center my-6">
|
||||
<div className="w-full border-t border-slate-200" />
|
||||
<span className="bg-white px-3 text-xs text-slate-400 whitespace-nowrap">
|
||||
hoặc sử dụng email
|
||||
</span>
|
||||
<div className="w-full border-t border-slate-200" />
|
||||
</div>
|
||||
|
||||
{/* Error Alert */}
|
||||
{errorMessage && (
|
||||
<div className="mb-4 px-3.5 py-2.5 rounded-lg bg-red-50 border border-red-200 text-xs text-red-700">
|
||||
{errorMessage}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Form */}
|
||||
<form onSubmit={handleSubmit} className="space-y-4" noValidate>
|
||||
{/* Email Field */}
|
||||
<div>
|
||||
<label
|
||||
htmlFor="work-email"
|
||||
className="block text-[13px] font-medium text-slate-800 mb-1.5"
|
||||
>
|
||||
Email công việc
|
||||
</label>
|
||||
<div className="relative">
|
||||
<span className="absolute inset-y-0 left-0 pl-3.5 flex items-center pointer-events-none text-slate-400">
|
||||
<svg
|
||||
className="w-4 h-4"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.8"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<rect x="2" y="4" width="20" height="16" rx="2" />
|
||||
<path d="m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7" />
|
||||
</svg>
|
||||
</span>
|
||||
<input
|
||||
id="work-email"
|
||||
type="email"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
placeholder="name@company.vn"
|
||||
className="w-full pl-10 pr-4 py-2.5 rounded-xl border border-slate-200 bg-white text-sm text-slate-900 placeholder:text-slate-400 focus:outline-none focus:border-[#C95C3C] focus:ring-2 focus:ring-[#C95C3C]/15 transition-all"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Password Field */}
|
||||
<div>
|
||||
<label
|
||||
htmlFor="work-password"
|
||||
className="block text-[13px] font-medium text-slate-800 mb-1.5"
|
||||
>
|
||||
Mật khẩu
|
||||
</label>
|
||||
<div className="relative">
|
||||
<span className="absolute inset-y-0 left-0 pl-3.5 flex items-center pointer-events-none text-slate-400">
|
||||
<svg
|
||||
className="w-4 h-4"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.8"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<rect x="3" y="11" width="18" height="11" rx="2" ry="2" />
|
||||
<path d="M7 11V7a5 5 0 0 1 10 0v4" />
|
||||
</svg>
|
||||
</span>
|
||||
<input
|
||||
id="work-password"
|
||||
type={showPassword ? 'text' : 'password'}
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
placeholder="Nhập mật khẩu"
|
||||
className="w-full pl-10 pr-10 py-2.5 rounded-xl border border-slate-200 bg-white text-sm text-slate-900 placeholder:text-slate-400 focus:outline-none focus:border-[#C95C3C] focus:ring-2 focus:ring-[#C95C3C]/15 transition-all"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowPassword((prev) => !prev)}
|
||||
aria-label={showPassword ? 'Ẩn mật khẩu' : 'Hiện mật khẩu'}
|
||||
className="absolute inset-y-0 right-0 pr-3.5 flex items-center text-slate-500 hover:text-slate-700"
|
||||
>
|
||||
{showPassword ? (
|
||||
<svg
|
||||
className="w-4 h-4"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.8"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z" />
|
||||
<circle cx="12" cy="12" r="3" />
|
||||
</svg>
|
||||
) : (
|
||||
<svg
|
||||
className="w-4 h-4"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.8"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="M9.88 9.88a3 3 0 1 0 4.24 4.24" />
|
||||
<path d="M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68" />
|
||||
<path d="M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61" />
|
||||
<line x1="2" x2="22" y1="2" y2="22" />
|
||||
</svg>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Remember Me & Forgot Password */}
|
||||
<div className="flex items-center justify-between pt-1">
|
||||
<label className="inline-flex items-center gap-2 cursor-pointer select-none">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={rememberMe}
|
||||
onChange={(e) => setRememberMe(e.target.checked)}
|
||||
className="w-4 h-4 rounded border-slate-300 text-slate-700 focus:ring-slate-500 accent-slate-600"
|
||||
/>
|
||||
<span className="text-xs text-slate-600">Ghi nhớ đăng nhập</span>
|
||||
</label>
|
||||
|
||||
<Link
|
||||
to="/forgot-password"
|
||||
className="text-xs font-medium text-indigo-600 hover:text-indigo-700 hover:underline"
|
||||
>
|
||||
Quên mật khẩu?
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
{/* Terracotta Submit Button */}
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isLoading}
|
||||
className="w-full flex items-center justify-center gap-2 py-3 px-4 rounded-xl bg-[#C95C3C] hover:bg-[#B5492B] active:bg-[#A03E22] text-white text-sm font-semibold shadow-sm transition-colors disabled:opacity-60 mt-2"
|
||||
>
|
||||
<span>{isLoading ? 'Đang đăng nhập...' : 'Đăng nhập'}</span>
|
||||
<span aria-hidden="true" className="text-base leading-none">
|
||||
→
|
||||
</span>
|
||||
</button>
|
||||
</form>
|
||||
|
||||
{/* Security Badge */}
|
||||
<div className="flex items-center justify-center gap-1.5 mt-5 text-xs text-slate-500">
|
||||
<svg
|
||||
className="w-3.5 h-3.5 text-slate-500 shrink-0"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10" />
|
||||
<path d="m9 12 2 2 4-4" />
|
||||
</svg>
|
||||
<span>Kết nối được mã hóa. Dữ liệu luôn riêng tư.</span>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default LoginForm
|
||||
46
src/pages/auth/components/SSOButton.tsx
Normal file
46
src/pages/auth/components/SSOButton.tsx
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import React from 'react'
|
||||
|
||||
export interface SSOButtonProps {
|
||||
onClick?: () => void
|
||||
isLoading?: boolean
|
||||
}
|
||||
|
||||
export const SSOButton: React.FC<SSOButtonProps> = ({
|
||||
onClick,
|
||||
isLoading = false,
|
||||
}) => {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClick}
|
||||
disabled={isLoading}
|
||||
className="w-full flex items-center justify-center gap-2.5 px-4 py-3 rounded-xl border border-slate-200 bg-white text-slate-800 text-sm font-medium hover:bg-slate-50 hover:border-slate-300 active:bg-slate-100 transition-all disabled:opacity-60"
|
||||
>
|
||||
{/* Building Icon */}
|
||||
<svg
|
||||
className="w-4 h-4 text-slate-600 shrink-0"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.8"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<rect x="4" y="2" width="16" height="20" rx="2" ry="2" />
|
||||
<path d="M9 22v-4h6v4" />
|
||||
<path d="M8 6h.01" />
|
||||
<path d="M16 6h.01" />
|
||||
<path d="M12 6h.01" />
|
||||
<path d="M12 10h.01" />
|
||||
<path d="M12 14h.01" />
|
||||
<path d="M16 10h.01" />
|
||||
<path d="M16 14h.01" />
|
||||
<path d="M8 10h.01" />
|
||||
<path d="M8 14h.01" />
|
||||
</svg>
|
||||
<span>Đăng nhập bằng SSO công ty</span>
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
export default SSOButton
|
||||
205
src/pages/projects/ProjectDetailPage.tsx
Normal file
205
src/pages/projects/ProjectDetailPage.tsx
Normal file
|
|
@ -0,0 +1,205 @@
|
|||
import React, { useState, useEffect, useRef } from 'react'
|
||||
import { useParams, useNavigate } from 'react-router-dom'
|
||||
import { TaskType } from '@/types'
|
||||
import {
|
||||
OverviewTab,
|
||||
DataTab,
|
||||
LabelsTab,
|
||||
MembersTab,
|
||||
SettingsTab,
|
||||
} from './components'
|
||||
import {
|
||||
getProjectById,
|
||||
getProjectImages,
|
||||
addUploadedImagesToProject,
|
||||
updateProjectClasses,
|
||||
updateProjectMembers,
|
||||
updateProject,
|
||||
deleteProjectById,
|
||||
subscribeProjectsStore,
|
||||
} from './projectData'
|
||||
|
||||
type DetailTabKey = 'overview' | 'data' | 'labels' | 'members' | 'settings'
|
||||
|
||||
const TASK_DISPLAY_NAME: Record<TaskType, string> = {
|
||||
classification: 'Classification',
|
||||
object_detection: 'Object Detection',
|
||||
segmentation: 'Segmentation',
|
||||
}
|
||||
|
||||
const TABS: Array<{ key: DetailTabKey; label: string }> = [
|
||||
{ key: 'overview', label: 'Tổng quan' },
|
||||
{ key: 'data', label: 'Dữ liệu' },
|
||||
{ key: 'labels', label: 'Lớp nhãn' },
|
||||
{ key: 'members', label: 'Thành viên' },
|
||||
{ key: 'settings', label: 'Cài đặt' },
|
||||
]
|
||||
|
||||
export const ProjectDetailPage: React.FC = () => {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const navigate = useNavigate()
|
||||
const fileInputRef = useRef<HTMLInputElement | null>(null)
|
||||
|
||||
const [activeTab, setActiveTab] = useState<DetailTabKey>('overview')
|
||||
const [project, setProject] = useState(() => getProjectById(id))
|
||||
const [images, setImages] = useState(() => getProjectImages(project.id))
|
||||
|
||||
useEffect(() => {
|
||||
const current = getProjectById(id)
|
||||
setProject(current)
|
||||
setImages(getProjectImages(current.id))
|
||||
}, [id])
|
||||
|
||||
useEffect(() => {
|
||||
return subscribeProjectsStore(() => {
|
||||
const current = getProjectById(id)
|
||||
setProject(current)
|
||||
setImages(getProjectImages(current.id))
|
||||
})
|
||||
}, [id])
|
||||
|
||||
const handleUploadFiles = (fileList: FileList | null) => {
|
||||
if (!fileList || fileList.length === 0) return
|
||||
const names = Array.from(fileList).map((f) => f.name)
|
||||
addUploadedImagesToProject(project.id, names)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{/* Hidden file input for header "↑ Tải ảnh lên" button */}
|
||||
<input
|
||||
ref={fileInputRef}
|
||||
type="file"
|
||||
accept="image/*"
|
||||
multiple
|
||||
className="hidden"
|
||||
onChange={(e) => handleUploadFiles(e.target.files)}
|
||||
/>
|
||||
|
||||
{/* Top Header matching MVP · Project dashboard.png */}
|
||||
<div className="flex flex-wrap items-start justify-between gap-4">
|
||||
<div>
|
||||
<h1 className="text-[28px] font-bold leading-tight tracking-tight text-slate-900">
|
||||
{project.name}
|
||||
</h1>
|
||||
<p className="mt-1 text-xs text-slate-500">
|
||||
<span className="font-mono text-slate-600">{project.slug}</span>
|
||||
{' · '}
|
||||
<span>{TASK_DISPLAY_NAME[project.taskType]}</span>
|
||||
{' · '}
|
||||
<span>{project.stats.totalImages.toLocaleString('vi-VN')} ảnh</span>
|
||||
{' · '}
|
||||
<span>{project.updatedAt}</span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => fileInputRef.current?.click()}
|
||||
className="inline-flex h-10 items-center gap-2 rounded-xl border border-slate-200 bg-white px-4 text-xs font-bold text-slate-800 shadow-sm transition hover:bg-slate-50"
|
||||
>
|
||||
<svg
|
||||
className="h-4 w-4 text-slate-700"
|
||||
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>
|
||||
<span>Tải ảnh lên</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => navigate(`/projects/${project.id}/annotate`)}
|
||||
className="inline-flex h-10 items-center gap-2 rounded-xl bg-[#C95C3C] px-5 text-xs font-bold text-white shadow-sm transition hover:bg-[#B5492B]"
|
||||
>
|
||||
<span>↗</span>
|
||||
<span>Mở giao diện gán nhãn</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Tabs navigation matching MVP · Project dashboard.png */}
|
||||
<div className="border-b border-slate-200">
|
||||
<nav className="-mb-px flex flex-wrap gap-6">
|
||||
{TABS.map((tab) => {
|
||||
const isActive = activeTab === tab.key
|
||||
return (
|
||||
<button
|
||||
key={tab.key}
|
||||
type="button"
|
||||
onClick={() => setActiveTab(tab.key)}
|
||||
className={`border-b-2 pb-2.5 text-xs font-semibold transition ${
|
||||
isActive
|
||||
? 'border-indigo-600 text-indigo-600'
|
||||
: 'border-transparent text-slate-500 hover:border-slate-300 hover:text-slate-800'
|
||||
}`}
|
||||
>
|
||||
{tab.label}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
{/* Tab Content */}
|
||||
<div className="pt-1">
|
||||
{activeTab === 'overview' && (
|
||||
<OverviewTab
|
||||
project={project}
|
||||
images={images}
|
||||
onSwitchTab={(tab) => setActiveTab(tab)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{activeTab === 'data' && (
|
||||
<DataTab
|
||||
project={project}
|
||||
images={images}
|
||||
onUploadImages={(names) => addUploadedImagesToProject(project.id, names)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{activeTab === 'labels' && (
|
||||
<LabelsTab
|
||||
classes={project.classes}
|
||||
onUpdateClasses={(classes) => updateProjectClasses(project.id, classes)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{activeTab === 'members' && (
|
||||
<MembersTab
|
||||
members={project.members}
|
||||
onUpdateMembers={(members) => updateProjectMembers(project.id, members)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{activeTab === 'settings' && (
|
||||
<SettingsTab
|
||||
project={project}
|
||||
onSaveSettings={(updates) =>
|
||||
updateProject(project.id, (p) => ({
|
||||
...p,
|
||||
name: updates.name,
|
||||
slug: updates.slug,
|
||||
description: updates.description,
|
||||
taskType: updates.taskType,
|
||||
updatedAt: 'Vừa cập nhật',
|
||||
}))
|
||||
}
|
||||
onDeleteProject={() => deleteProjectById(project.id)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default ProjectDetailPage
|
||||
164
src/pages/projects/ProjectListPage.tsx
Normal file
164
src/pages/projects/ProjectListPage.tsx
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
import React, { useState, useEffect, useMemo } from 'react'
|
||||
import { CreateProjectInput, ProjectStatus, TaskType } from '@/types'
|
||||
import {
|
||||
ProjectStatsCards,
|
||||
ProjectFilters,
|
||||
ProjectCard,
|
||||
ActivityFeed,
|
||||
CreateProjectModal,
|
||||
} from './components'
|
||||
import {
|
||||
getProjects,
|
||||
getActivities,
|
||||
addProject,
|
||||
deleteProjectById,
|
||||
subscribeProjectsStore,
|
||||
} from './projectData'
|
||||
|
||||
export const ProjectListPage: React.FC = () => {
|
||||
const [projects, setProjects] = useState(() => getProjects())
|
||||
const [activities, setActivities] = useState(() => getActivities())
|
||||
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false)
|
||||
|
||||
const [searchQuery, setSearchQuery] = useState('')
|
||||
const [selectedTaskType, setSelectedTaskType] = useState<'all' | TaskType>('all')
|
||||
const [selectedStatus, setSelectedStatus] = useState<'all' | ProjectStatus>('all')
|
||||
const [sortBy, setSortBy] = useState<'updated' | 'name' | 'progress'>('updated')
|
||||
const [viewMode, setViewMode] = useState<'grid' | 'list'>('grid')
|
||||
|
||||
useEffect(() => {
|
||||
return subscribeProjectsStore(() => {
|
||||
setProjects(getProjects())
|
||||
setActivities(getActivities())
|
||||
})
|
||||
}, [])
|
||||
|
||||
const filteredProjects = useMemo(() => {
|
||||
const list = projects.filter((proj) => {
|
||||
const q = searchQuery.trim().toLowerCase()
|
||||
const matchesSearch =
|
||||
!q ||
|
||||
proj.name.toLowerCase().includes(q) ||
|
||||
proj.slug.toLowerCase().includes(q) ||
|
||||
proj.description.toLowerCase().includes(q)
|
||||
const matchesTask =
|
||||
selectedTaskType === 'all' || proj.taskType === selectedTaskType
|
||||
const matchesStatus =
|
||||
selectedStatus === 'all' || proj.status === selectedStatus
|
||||
|
||||
return matchesSearch && matchesTask && matchesStatus
|
||||
})
|
||||
|
||||
if (sortBy === 'name') {
|
||||
return [...list].sort((a, b) => a.name.localeCompare(b.name, 'vi'))
|
||||
}
|
||||
if (sortBy === 'progress') {
|
||||
return [...list].sort((a, b) => {
|
||||
const progA =
|
||||
a.stats.totalImages > 0
|
||||
? (a.stats.completed + a.stats.pendingReview) / a.stats.totalImages
|
||||
: 0
|
||||
const progB =
|
||||
b.stats.totalImages > 0
|
||||
? (b.stats.completed + b.stats.pendingReview) / b.stats.totalImages
|
||||
: 0
|
||||
return progB - progA
|
||||
})
|
||||
}
|
||||
return list
|
||||
}, [projects, searchQuery, selectedTaskType, selectedStatus, sortBy])
|
||||
|
||||
const handleCreateProject = (input: CreateProjectInput) => {
|
||||
addProject(input)
|
||||
}
|
||||
|
||||
const handleDeleteProject = (projectId: string) => {
|
||||
deleteProjectById(projectId)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-5">
|
||||
{/* Page Header matching MVP · Quản lý dự án.png */}
|
||||
<div className="flex flex-wrap items-start justify-between gap-4">
|
||||
<div>
|
||||
<h1 className="text-[28px] font-bold leading-tight tracking-tight text-slate-900">
|
||||
Dự án của bạn
|
||||
</h1>
|
||||
<p className="mt-1 text-xs text-slate-500">
|
||||
Quản lý dữ liệu, phân công gán nhãn và kiểm soát chất lượng trong một nơi.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setIsCreateModalOpen(true)}
|
||||
className="inline-flex items-center gap-2 rounded-xl bg-[#C95C3C] px-4 py-2.5 text-xs font-semibold text-white shadow-sm transition hover:bg-[#B5492B]"
|
||||
>
|
||||
<span className="text-base leading-none">+</span>
|
||||
<span>Tạo dự án</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* 4 Summary Cards */}
|
||||
<ProjectStatsCards projects={projects} />
|
||||
|
||||
{/* Filter Bar */}
|
||||
<ProjectFilters
|
||||
searchQuery={searchQuery}
|
||||
onSearchChange={setSearchQuery}
|
||||
selectedTaskType={selectedTaskType}
|
||||
onTaskTypeChange={setSelectedTaskType}
|
||||
selectedStatus={selectedStatus}
|
||||
onStatusChange={setSelectedStatus}
|
||||
sortBy={sortBy}
|
||||
onSortChange={setSortBy}
|
||||
viewMode={viewMode}
|
||||
onViewModeChange={setViewMode}
|
||||
/>
|
||||
|
||||
{/* Project Cards Grid / List */}
|
||||
{filteredProjects.length === 0 ? (
|
||||
<div className="rounded-2xl border border-slate-200/80 bg-white py-14 text-center">
|
||||
<p className="text-sm font-semibold text-slate-700">
|
||||
Không tìm thấy dự án phù hợp
|
||||
</p>
|
||||
<p className="mt-1 text-xs text-slate-400">
|
||||
Hãy thử thay đổi từ khóa tìm kiếm hoặc tạo dự án mới.
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<div
|
||||
className={
|
||||
viewMode === 'grid'
|
||||
? 'grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3'
|
||||
: 'grid grid-cols-1 gap-4'
|
||||
}
|
||||
>
|
||||
{filteredProjects.map((project) => (
|
||||
<ProjectCard
|
||||
key={project.id}
|
||||
project={project}
|
||||
onDelete={handleDeleteProject}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Activity Feed Bar */}
|
||||
<ActivityFeed
|
||||
activities={activities}
|
||||
totalCount={projects.length}
|
||||
visibleCount={filteredProjects.length}
|
||||
/>
|
||||
|
||||
{/* Create Project Modal */}
|
||||
<CreateProjectModal
|
||||
isOpen={isCreateModalOpen}
|
||||
onClose={() => setIsCreateModalOpen(false)}
|
||||
onCreate={handleCreateProject}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default ProjectListPage
|
||||
66
src/pages/projects/components/ActivityFeed.tsx
Normal file
66
src/pages/projects/components/ActivityFeed.tsx
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
import React, { useState } from 'react'
|
||||
import { ActivityLog } from '@/types'
|
||||
|
||||
interface ActivityFeedProps {
|
||||
activities: ActivityLog[]
|
||||
totalCount?: number
|
||||
visibleCount?: number
|
||||
}
|
||||
|
||||
export const ActivityFeed: React.FC<ActivityFeedProps> = ({
|
||||
activities,
|
||||
totalCount = 3,
|
||||
visibleCount = 3,
|
||||
}) => {
|
||||
const [expanded, setExpanded] = useState(false)
|
||||
const displayed = expanded ? activities : activities.slice(0, 2)
|
||||
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
{/* Main Activity Bar matching wireframe */}
|
||||
<div className="flex flex-wrap items-center justify-between gap-3 rounded-2xl border border-slate-200/80 bg-white px-5 py-3 shadow-[0_1px_2px_rgba(15,23,42,0.02)]">
|
||||
<div className="flex flex-wrap items-center gap-6 text-xs text-slate-500">
|
||||
{/* Pulse / Waveform icon */}
|
||||
<svg
|
||||
className="h-4 w-4 text-slate-400 shrink-0"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth={2}
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
d="M3 12h4l3-8 4 16 3-8h4"
|
||||
/>
|
||||
</svg>
|
||||
|
||||
{displayed.map((act) => (
|
||||
<span key={act.id} className="inline-flex items-center gap-1 text-slate-500">
|
||||
<span className="font-medium text-slate-600">{act.timestamp}</span>
|
||||
<span>·</span>
|
||||
<span className="font-medium text-slate-700">{act.userName}</span>
|
||||
<span>{act.actionText}</span>
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setExpanded((prev) => !prev)}
|
||||
className="text-xs font-semibold text-indigo-600 hover:text-indigo-700 transition"
|
||||
>
|
||||
{expanded ? 'Thu gọn ↑' : 'Xem tất cả →'}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Bottom caption line matching wireframe */}
|
||||
<div className="flex items-center justify-between px-1 text-[11px] text-slate-400">
|
||||
<span>
|
||||
Hiển thị {visibleCount} / {totalCount} dự án trong danable
|
||||
</span>
|
||||
<span>Nhãn được lưu theo từng dự án</span>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
125
src/pages/projects/components/CreateProjectModal.tsx
Normal file
125
src/pages/projects/components/CreateProjectModal.tsx
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
import React, { useState } from 'react'
|
||||
import { CreateProjectInput, TaskType } from '@/types'
|
||||
import { TaskTypeSelector } from './TaskTypeSelector'
|
||||
|
||||
interface CreateProjectModalProps {
|
||||
isOpen: boolean
|
||||
onClose: () => void
|
||||
onCreate: (input: CreateProjectInput) => void
|
||||
}
|
||||
|
||||
export const CreateProjectModal: React.FC<CreateProjectModalProps> = ({
|
||||
isOpen,
|
||||
onClose,
|
||||
onCreate,
|
||||
}) => {
|
||||
const [name, setName] = useState('')
|
||||
const [description, setDescription] = useState('')
|
||||
const [taskType, setTaskType] = useState<TaskType>('classification')
|
||||
const [error, setError] = useState('')
|
||||
|
||||
if (!isOpen) return null
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
if (!name.trim()) {
|
||||
setError('Vui lòng nhập tên dự án')
|
||||
return
|
||||
}
|
||||
onCreate({
|
||||
name: name.trim(),
|
||||
description: description.trim() || 'Dự án gán nhãn dữ liệu hình ảnh',
|
||||
taskType,
|
||||
})
|
||||
setName('')
|
||||
setDescription('')
|
||||
setTaskType('classification')
|
||||
setError('')
|
||||
onClose()
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className="fixed inset-0 z-50 flex items-center justify-center bg-slate-900/55 p-4 backdrop-blur-[1px]"
|
||||
onClick={onClose}
|
||||
>
|
||||
<div
|
||||
className="w-full max-w-[500px] rounded-2xl bg-white p-7 shadow-2xl"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{/* Header matching MVP · Tạo dự án.png */}
|
||||
<div>
|
||||
<p className="text-[26px] font-extrabold uppercase leading-none tracking-tight text-[#6336F5]">
|
||||
DỰ ÁN MỚI
|
||||
</p>
|
||||
<h2 className="mt-2.5 text-xl font-bold text-slate-900">Tạo dự án mới</h2>
|
||||
<p className="mt-1.5 text-xs text-slate-500">
|
||||
Thiết lập bộ dữ liệu và bài toán gán nhãn trước khi tải ảnh lên.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<form onSubmit={handleSubmit} className="mt-5 space-y-4">
|
||||
{/* Tên dự án */}
|
||||
<div
|
||||
className={`rounded-xl border px-3.5 py-2.5 transition focus-within:border-indigo-500 focus-within:ring-2 focus-within:ring-indigo-500/15 ${
|
||||
error ? 'border-rose-400' : 'border-slate-200'
|
||||
}`}
|
||||
>
|
||||
<label className="block text-xs font-semibold text-slate-800">
|
||||
Tên dự án
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
value={name}
|
||||
onChange={(e) => {
|
||||
setName(e.target.value)
|
||||
if (error) setError('')
|
||||
}}
|
||||
placeholder="e.g. City Streets"
|
||||
className="mt-0.5 w-full border-none bg-transparent p-0 text-sm text-slate-900 placeholder:text-slate-400 focus:outline-none"
|
||||
autoFocus
|
||||
/>
|
||||
</div>
|
||||
{error && <p className="text-xs font-medium text-rose-600">{error}</p>}
|
||||
|
||||
{/* Mô tả */}
|
||||
<div className="rounded-xl border border-slate-200 px-3.5 py-2.5 transition focus-within:border-indigo-500 focus-within:ring-2 focus-within:ring-indigo-500/15">
|
||||
<label className="block text-xs font-semibold text-slate-800">
|
||||
Mô tả
|
||||
</label>
|
||||
<textarea
|
||||
rows={3}
|
||||
value={description}
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
placeholder="Dự án này sẽ gán nhãn cho nội dung gì?"
|
||||
className="mt-1 w-full resize-none border-none bg-transparent p-0 text-sm text-slate-900 placeholder:text-slate-400 focus:outline-none"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Bài toán gán nhãn */}
|
||||
<div className="pt-1">
|
||||
<h3 className="mb-3 text-xl font-bold text-slate-900">Bài toán gán nhãn</h3>
|
||||
<TaskTypeSelector value={taskType} onChange={setTaskType} />
|
||||
</div>
|
||||
|
||||
{/* Footer actions */}
|
||||
<div className="flex items-center justify-between pt-4">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
className="rounded-xl border border-slate-200 bg-white px-6 py-2.5 text-xs font-semibold text-slate-700 transition hover:bg-slate-50"
|
||||
>
|
||||
Hủy
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
className="rounded-xl bg-[#C95C3C] px-9 py-2.5 text-xs font-semibold text-white shadow-sm transition hover:bg-[#B5492B]"
|
||||
>
|
||||
Tạo dự án
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
301
src/pages/projects/components/ProjectCard.tsx
Normal file
301
src/pages/projects/components/ProjectCard.tsx
Normal file
|
|
@ -0,0 +1,301 @@
|
|||
import React, { useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { Project, TaskType } from '@/types'
|
||||
|
||||
interface ProjectCardProps {
|
||||
project: Project
|
||||
onDelete?: (projectId: string) => void
|
||||
}
|
||||
|
||||
const TASK_BADGE_CONFIG: Record<
|
||||
TaskType,
|
||||
{ label: string; icon: React.ReactNode }
|
||||
> = {
|
||||
classification: {
|
||||
label: 'Classification',
|
||||
icon: (
|
||||
<svg className="h-3.5 w-3.5 text-slate-600" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2}>
|
||||
<path strokeLinecap="round" strokeLinejoin="round" d="M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z" />
|
||||
</svg>
|
||||
),
|
||||
},
|
||||
object_detection: {
|
||||
label: 'Object Detection',
|
||||
icon: (
|
||||
<svg className="h-3.5 w-3.5 text-slate-600" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2}>
|
||||
<path strokeLinecap="round" strokeLinejoin="round" d="M4 8V5a1 1 0 011-1h3M16 4h3a1 1 0 011 1v3M20 16v3a1 1 0 01-1 1h-3M8 20H5a1 1 0 01-1-1v-3" />
|
||||
</svg>
|
||||
),
|
||||
},
|
||||
segmentation: {
|
||||
label: 'Segmentation',
|
||||
icon: (
|
||||
<svg className="h-3.5 w-3.5 text-slate-600" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2}>
|
||||
<polygon points="12 3 20 8.5 17 19 7 19 4 8.5" strokeLinecap="round" strokeLinejoin="round" />
|
||||
</svg>
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
export const ProjectCard: React.FC<ProjectCardProps> = ({ project, onDelete }) => {
|
||||
const navigate = useNavigate()
|
||||
const [menuOpen, setMenuOpen] = useState(false)
|
||||
|
||||
const badge = TASK_BADGE_CONFIG[project.taskType]
|
||||
const annotatedCount = project.stats.completed + project.stats.pendingReview
|
||||
const progressPercent =
|
||||
project.stats.totalImages > 0
|
||||
? Math.round((annotatedCount / project.stats.totalImages) * 100)
|
||||
: 0
|
||||
|
||||
const formatNum = (n: number) => n.toLocaleString('vi-VN')
|
||||
|
||||
const isPendingReviewHighlight =
|
||||
project.status === 'pending_review' && project.stats.pendingReview > 0
|
||||
|
||||
const displayMembers = project.members.slice(0, 3)
|
||||
|
||||
const handleOpenOverview = () => {
|
||||
navigate(`/projects/${project.id}`)
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
onClick={handleOpenOverview}
|
||||
className="group relative flex cursor-pointer flex-col overflow-hidden rounded-2xl border border-slate-200/80 bg-white shadow-[0_1px_3px_rgba(15,23,42,0.04)] transition-all duration-200 hover:-translate-y-0.5 hover:border-slate-300 hover:shadow-md"
|
||||
>
|
||||
{/* Top Thumbnail with decorative overlays */}
|
||||
<div className="relative h-44 w-full overflow-hidden bg-slate-100">
|
||||
<img
|
||||
src={project.thumbnailUrl}
|
||||
alt={project.name}
|
||||
className="h-full w-full object-cover transition-transform duration-300 group-hover:scale-[1.02]"
|
||||
/>
|
||||
|
||||
{/* Decorative Bounding Box overlay for Object Detection */}
|
||||
{project.taskType === 'object_detection' && (
|
||||
<svg
|
||||
className="pointer-events-none absolute inset-0 h-full w-full"
|
||||
viewBox="0 0 400 180"
|
||||
preserveAspectRatio="none"
|
||||
>
|
||||
{/* Cyan bbox around car */}
|
||||
<rect
|
||||
x="105"
|
||||
y="72"
|
||||
width="66"
|
||||
height="48"
|
||||
fill="rgba(6, 182, 212, 0.14)"
|
||||
stroke="#06B6D4"
|
||||
strokeWidth="2"
|
||||
rx="2"
|
||||
/>
|
||||
<rect x="105" y="61" width="32" height="11" fill="#06B6D4" rx="1.5" />
|
||||
<text x="109" y="69" fill="#ffffff" fontSize="7.5" fontWeight="600">
|
||||
Ô tô
|
||||
</text>
|
||||
|
||||
{/* Red/Orange bbox around bus */}
|
||||
<rect
|
||||
x="212"
|
||||
y="34"
|
||||
width="124"
|
||||
height="84"
|
||||
fill="rgba(239, 68, 68, 0.14)"
|
||||
stroke="#EF4444"
|
||||
strokeWidth="2"
|
||||
rx="2"
|
||||
/>
|
||||
<rect x="212" y="23" width="44" height="11" fill="#EF4444" rx="1.5" />
|
||||
<text x="216" y="31" fill="#ffffff" fontSize="7.5" fontWeight="600">
|
||||
Xe buýt
|
||||
</text>
|
||||
|
||||
{/* Amber bbox around motorbike */}
|
||||
<rect
|
||||
x="248"
|
||||
y="112"
|
||||
width="34"
|
||||
height="52"
|
||||
fill="rgba(245, 158, 11, 0.16)"
|
||||
stroke="#F59E0B"
|
||||
strokeWidth="1.8"
|
||||
rx="2"
|
||||
/>
|
||||
<rect
|
||||
x="298"
|
||||
y="108"
|
||||
width="36"
|
||||
height="56"
|
||||
fill="rgba(34, 197, 94, 0.16)"
|
||||
stroke="#22C55E"
|
||||
strokeWidth="1.8"
|
||||
rx="2"
|
||||
/>
|
||||
</svg>
|
||||
)}
|
||||
|
||||
{/* Decorative Polygon Mask overlay for Segmentation */}
|
||||
{project.taskType === 'segmentation' && (
|
||||
<svg
|
||||
className="pointer-events-none absolute inset-0 h-full w-full"
|
||||
viewBox="0 0 400 180"
|
||||
preserveAspectRatio="none"
|
||||
>
|
||||
{/* Cyan polygon mask on car */}
|
||||
<polygon
|
||||
points="110,94 122,74 156,74 168,92 166,118 108,118"
|
||||
fill="rgba(6, 182, 212, 0.36)"
|
||||
stroke="#22D3EE"
|
||||
strokeWidth="2"
|
||||
/>
|
||||
{/* Red/Coral polygon mask on bus */}
|
||||
<polygon
|
||||
points="216,42 292,35 334,54 334,114 276,118 216,96"
|
||||
fill="rgba(239, 68, 68, 0.35)"
|
||||
stroke="#F87171"
|
||||
strokeWidth="2"
|
||||
/>
|
||||
{/* Green polygon masks on motorbikes */}
|
||||
<polygon
|
||||
points="254,124 268,112 280,128 276,162 252,160"
|
||||
fill="rgba(34, 197, 94, 0.38)"
|
||||
stroke="#4ADE80"
|
||||
strokeWidth="1.8"
|
||||
/>
|
||||
<polygon
|
||||
points="304,118 318,108 332,126 328,162 302,160"
|
||||
fill="rgba(168, 85, 247, 0.38)"
|
||||
stroke="#C084FC"
|
||||
strokeWidth="1.8"
|
||||
/>
|
||||
</svg>
|
||||
)}
|
||||
|
||||
{/* Top-left Task Badge */}
|
||||
<div className="absolute left-3.5 top-3.5 inline-flex items-center gap-1.5 rounded-lg bg-white/95 px-2.5 py-1 text-xs font-semibold text-slate-800 shadow-sm backdrop-blur-sm">
|
||||
{badge.icon}
|
||||
<span>{badge.label}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Card Content */}
|
||||
<div className="flex flex-1 flex-col p-5">
|
||||
{/* Title + 3-dots menu */}
|
||||
<div className="flex items-start justify-between gap-2">
|
||||
<h3 className="text-lg font-bold text-slate-900 group-hover:text-[#C95C3C] transition-colors">
|
||||
{project.name}
|
||||
</h3>
|
||||
<div className="relative" onClick={(e) => e.stopPropagation()}>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setMenuOpen((prev) => !prev)}
|
||||
className="flex h-7 w-7 items-center justify-center rounded-lg text-slate-400 hover:bg-slate-100 hover:text-slate-600"
|
||||
aria-label="Tùy chọn dự án"
|
||||
>
|
||||
<svg className="h-4 w-4" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path d="M6 10a2 2 0 11-4 0 2 2 0 014 0zm6 0a2 2 0 11-4 0 2 2 0 014 0zm6 0a2 2 0 11-4 0 2 2 0 014 0z" />
|
||||
</svg>
|
||||
</button>
|
||||
{menuOpen && (
|
||||
<div className="absolute right-0 top-8 z-20 w-44 rounded-xl border border-slate-200 bg-white py-1.5 shadow-lg">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setMenuOpen(false)
|
||||
navigate(`/projects/${project.id}`)
|
||||
}}
|
||||
className="flex w-full items-center px-3.5 py-2 text-left text-xs font-medium text-slate-700 hover:bg-slate-50"
|
||||
>
|
||||
Mở tổng quan dự án
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setMenuOpen(false)
|
||||
navigate(`/projects/${project.id}/annotate`)
|
||||
}}
|
||||
className="flex w-full items-center px-3.5 py-2 text-left text-xs font-medium text-slate-700 hover:bg-slate-50"
|
||||
>
|
||||
Mở giao diện gán nhãn
|
||||
</button>
|
||||
{onDelete && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setMenuOpen(false)
|
||||
onDelete(project.id)
|
||||
}}
|
||||
className="flex w-full items-center px-3.5 py-2 text-left text-xs font-medium text-rose-600 hover:bg-rose-50"
|
||||
>
|
||||
Xóa dự án
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Description & Monospace Slug */}
|
||||
<p className="mt-1 text-xs text-slate-500">{project.description}</p>
|
||||
<p className="mt-2 font-mono text-[11px] text-slate-400">{project.slug}</p>
|
||||
|
||||
{/* Image count & class count */}
|
||||
<div className="mt-3.5 flex items-center gap-3 text-xs font-medium text-slate-600">
|
||||
<span>{formatNum(project.stats.totalImages)} ảnh</span>
|
||||
<span>{project.classes.length} lớp</span>
|
||||
</div>
|
||||
|
||||
{/* Progress text & bar */}
|
||||
<div className="mt-3">
|
||||
<div className="flex items-center justify-between text-xs">
|
||||
<span className="text-slate-500">{formatNum(annotatedCount)} đã gán nhãn</span>
|
||||
<span className="font-bold text-indigo-600">{progressPercent}%</span>
|
||||
</div>
|
||||
<div className="mt-2 h-1.5 w-full overflow-hidden rounded-full bg-slate-100">
|
||||
<div
|
||||
className="h-full rounded-full bg-[#C95C3C] transition-all duration-300"
|
||||
style={{ width: `${Math.min(100, Math.max(0, progressPercent))}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Status Pill & Member Avatar Stack */}
|
||||
<div className="mt-4 flex items-center justify-between">
|
||||
{isPendingReviewHighlight ? (
|
||||
<span className="inline-flex items-center gap-1.5 rounded-full bg-[#FEF3C7] px-3 py-1 text-xs font-semibold text-[#B45309]">
|
||||
<span className="h-1.5 w-1.5 rounded-full bg-[#F59E0B]" />
|
||||
{formatNum(project.stats.pendingReview)} ảnh chờ duyệt
|
||||
</span>
|
||||
) : (
|
||||
<span className="inline-flex items-center gap-1.5 rounded-full bg-[#FEE2E2]/80 px-3 py-1 text-xs font-semibold text-[#B91C1C]">
|
||||
<span className="h-1.5 w-1.5 rounded-full bg-[#EF4444]" />
|
||||
Đang gán nhãn
|
||||
</span>
|
||||
)}
|
||||
|
||||
<div className="flex items-center -space-x-1.5">
|
||||
{displayMembers.map((member) => (
|
||||
<div
|
||||
key={member.id}
|
||||
title={member.name}
|
||||
style={{ backgroundColor: member.color }}
|
||||
className="flex h-6 w-6 items-center justify-center rounded-full border-2 border-white text-[10px] font-bold text-slate-700"
|
||||
>
|
||||
{member.initials}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Divider + Footer */}
|
||||
<div className="mt-4 flex items-center justify-between border-t border-slate-100 pt-3.5 text-xs">
|
||||
<span className="text-slate-400">{project.updatedAt}</span>
|
||||
<span className="inline-flex items-center gap-1 font-semibold text-indigo-600 group-hover:translate-x-0.5 transition-transform">
|
||||
Mở tổng quan →
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
148
src/pages/projects/components/ProjectFilters.tsx
Normal file
148
src/pages/projects/components/ProjectFilters.tsx
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
import React from 'react'
|
||||
import { TaskType, ProjectStatus } from '@/types'
|
||||
|
||||
interface ProjectFiltersProps {
|
||||
searchQuery: string
|
||||
onSearchChange: (val: string) => void
|
||||
selectedTaskType: 'all' | TaskType
|
||||
onTaskTypeChange: (val: 'all' | TaskType) => void
|
||||
selectedStatus: 'all' | ProjectStatus
|
||||
onStatusChange: (val: 'all' | ProjectStatus) => void
|
||||
sortBy: 'updated' | 'name' | 'progress'
|
||||
onSortChange: (val: 'updated' | 'name' | 'progress') => void
|
||||
viewMode: 'grid' | 'list'
|
||||
onViewModeChange: (val: 'grid' | 'list') => void
|
||||
}
|
||||
|
||||
export const ProjectFilters: React.FC<ProjectFiltersProps> = ({
|
||||
searchQuery,
|
||||
onSearchChange,
|
||||
selectedTaskType,
|
||||
onTaskTypeChange,
|
||||
selectedStatus,
|
||||
onStatusChange,
|
||||
sortBy,
|
||||
onSortChange,
|
||||
viewMode,
|
||||
onViewModeChange,
|
||||
}) => {
|
||||
return (
|
||||
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
{/* Search Input */}
|
||||
<div className="relative w-full sm:w-80">
|
||||
<svg
|
||||
className="pointer-events-none absolute left-3.5 top-1/2 h-4 w-4 -translate-y-1/2 text-slate-400"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
strokeWidth={2}
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
d="M21 21l-4.35-4.35m0 0A7.5 7.5 0 104.5 4.5a7.5 7.5 0 0012.15 12.15z"
|
||||
/>
|
||||
</svg>
|
||||
<input
|
||||
type="text"
|
||||
value={searchQuery}
|
||||
onChange={(e) => onSearchChange(e.target.value)}
|
||||
placeholder="Tìm theo tên dự án..."
|
||||
className="h-10 w-full rounded-xl border border-slate-200 bg-white pl-10 pr-4 text-sm text-slate-800 placeholder:text-slate-400 focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/15"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Task Type Filter */}
|
||||
<div className="relative">
|
||||
<select
|
||||
value={selectedTaskType}
|
||||
onChange={(e) => onTaskTypeChange(e.target.value as 'all' | TaskType)}
|
||||
className="h-10 appearance-none rounded-xl border border-slate-200 bg-white pl-3.5 pr-9 text-sm font-medium text-slate-700 focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/15"
|
||||
>
|
||||
<option value="all">Tất cả bài toán</option>
|
||||
<option value="classification">Classification</option>
|
||||
<option value="object_detection">Object Detection</option>
|
||||
<option value="segmentation">Segmentation</option>
|
||||
</select>
|
||||
<svg
|
||||
className="pointer-events-none absolute right-3 top-1/2 h-4 w-4 -translate-y-1/2 text-slate-500"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
strokeWidth={2}
|
||||
>
|
||||
<path strokeLinecap="round" strokeLinejoin="round" d="M19 9l-7 7-7-7" />
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
{/* Status Filter */}
|
||||
<div className="relative">
|
||||
<select
|
||||
value={selectedStatus}
|
||||
onChange={(e) => onStatusChange(e.target.value as 'all' | ProjectStatus)}
|
||||
className="h-10 appearance-none rounded-xl border border-slate-200 bg-white pl-3.5 pr-9 text-sm font-medium text-slate-700 focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/15"
|
||||
>
|
||||
<option value="all">Tất cả trạng thái</option>
|
||||
<option value="annotating">Đang gán nhãn</option>
|
||||
<option value="pending_review">Chờ duyệt</option>
|
||||
<option value="completed">Hoàn thành</option>
|
||||
</select>
|
||||
<svg
|
||||
className="pointer-events-none absolute right-3 top-1/2 h-4 w-4 -translate-y-1/2 text-slate-500"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
strokeWidth={2}
|
||||
>
|
||||
<path strokeLinecap="round" strokeLinejoin="round" d="M19 9l-7 7-7-7" />
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Right side: Sort + Grid/List toggle */}
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="relative flex items-center">
|
||||
<select
|
||||
value={sortBy}
|
||||
onChange={(e) => onSortChange(e.target.value as 'updated' | 'name' | 'progress')}
|
||||
className="appearance-none bg-transparent pr-5 text-xs font-medium text-slate-500 hover:text-slate-800 focus:outline-none cursor-pointer"
|
||||
>
|
||||
<option value="updated">Mới cập nhật</option>
|
||||
<option value="name">Tên dự án (A-Z)</option>
|
||||
<option value="progress">Tiến độ gán nhãn</option>
|
||||
</select>
|
||||
<svg
|
||||
className="pointer-events-none absolute right-0.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-slate-400"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
strokeWidth={2}
|
||||
>
|
||||
<path strokeLinecap="round" strokeLinejoin="round" d="M19 9l-7 7-7-7" />
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onViewModeChange(viewMode === 'grid' ? 'list' : 'grid')}
|
||||
title={viewMode === 'grid' ? 'Chuyển sang dạng danh sách' : 'Chuyển sang dạng lưới'}
|
||||
className="flex h-8 w-8 items-center justify-center rounded-lg text-indigo-600 transition hover:bg-indigo-50"
|
||||
>
|
||||
{viewMode === 'grid' ? (
|
||||
<svg className="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2}>
|
||||
<rect x="3" y="3" width="7" height="7" rx="1.5" />
|
||||
<rect x="14" y="3" width="7" height="7" rx="1.5" />
|
||||
<rect x="3" y="14" width="7" height="7" rx="1.5" />
|
||||
<rect x="14" y="14" width="7" height="7" rx="1.5" />
|
||||
</svg>
|
||||
) : (
|
||||
<svg className="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2}>
|
||||
<path strokeLinecap="round" strokeLinejoin="round" d="M4 6h16M4 12h16M4 18h16" />
|
||||
</svg>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
66
src/pages/projects/components/ProjectStatsCards.tsx
Normal file
66
src/pages/projects/components/ProjectStatsCards.tsx
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
import React from 'react'
|
||||
import { Project } from '@/types'
|
||||
|
||||
interface ProjectStatsCardsProps {
|
||||
projects?: Project[]
|
||||
}
|
||||
|
||||
export const ProjectStatsCards: React.FC<ProjectStatsCardsProps> = ({ projects }) => {
|
||||
const totalProjects = projects ? projects.length : 3
|
||||
const totalImages = projects
|
||||
? projects.reduce((sum, p) => sum + p.stats.totalImages, 0)
|
||||
: 4320
|
||||
const totalAnnotated = projects
|
||||
? projects.reduce((sum, p) => sum + p.stats.completed + p.stats.pendingReview, 0)
|
||||
: 3144
|
||||
const totalPendingReview = projects
|
||||
? projects.reduce((sum, p) => sum + p.stats.pendingReview, 0)
|
||||
: 372
|
||||
|
||||
const annotatedPercent =
|
||||
totalImages > 0
|
||||
? ((totalAnnotated / totalImages) * 100).toFixed(1).replace('.', ',')
|
||||
: '0'
|
||||
|
||||
const formatNumber = (num: number) => num.toLocaleString('vi-VN')
|
||||
|
||||
const cards = [
|
||||
{
|
||||
label: 'Tổng dự án',
|
||||
value: formatNumber(totalProjects),
|
||||
subtext: `${totalProjects} bài toán · đang hoạt động`,
|
||||
},
|
||||
{
|
||||
label: 'Tổng dữ liệu',
|
||||
value: formatNumber(totalImages),
|
||||
subtext: 'ảnh trong không gian nhóm',
|
||||
},
|
||||
{
|
||||
label: 'Đã gán nhãn',
|
||||
value: formatNumber(totalAnnotated),
|
||||
subtext: `${annotatedPercent}% · bao gồm ảnh chờ duyệt`,
|
||||
},
|
||||
{
|
||||
label: 'Chờ duyệt',
|
||||
value: formatNumber(totalPendingReview),
|
||||
subtext: 'ảnh cần kiểm tra chất lượng',
|
||||
},
|
||||
]
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4">
|
||||
{cards.map((card) => (
|
||||
<div
|
||||
key={card.label}
|
||||
className="rounded-2xl border border-slate-200/80 bg-white px-5 py-4 shadow-[0_1px_2px_rgba(15,23,42,0.03)]"
|
||||
>
|
||||
<p className="text-xs font-medium text-slate-500">{card.label}</p>
|
||||
<p className="mt-2 text-[28px] font-bold leading-tight tracking-tight text-slate-900">
|
||||
{card.value}
|
||||
</p>
|
||||
<p className="mt-2 text-xs text-slate-500">{card.subtext}</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
60
src/pages/projects/components/TaskTypeSelector.tsx
Normal file
60
src/pages/projects/components/TaskTypeSelector.tsx
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import React from 'react'
|
||||
import { TaskType } from '@/types'
|
||||
|
||||
interface TaskTypeSelectorProps {
|
||||
value: TaskType
|
||||
onChange: (taskType: TaskType) => void
|
||||
}
|
||||
|
||||
const TASK_OPTIONS: Array<{
|
||||
type: TaskType
|
||||
title: string
|
||||
subtitle: string
|
||||
}> = [
|
||||
{
|
||||
type: 'classification',
|
||||
title: 'Classification',
|
||||
subtitle: 'Bài toán phân loại ảnh',
|
||||
},
|
||||
{
|
||||
type: 'object_detection',
|
||||
title: 'Object Detection',
|
||||
subtitle: 'Phát hiện vật thể',
|
||||
},
|
||||
{
|
||||
type: 'segmentation',
|
||||
title: 'Segmentation',
|
||||
subtitle: 'Phân đoạn hình ảnh',
|
||||
},
|
||||
]
|
||||
|
||||
export const TaskTypeSelector: React.FC<TaskTypeSelectorProps> = ({ value, onChange }) => {
|
||||
return (
|
||||
<div className="grid grid-cols-1 gap-3.5 sm:grid-cols-2">
|
||||
{TASK_OPTIONS.map((opt) => {
|
||||
const isSelected = value === opt.type
|
||||
return (
|
||||
<button
|
||||
key={opt.type}
|
||||
type="button"
|
||||
onClick={() => onChange(opt.type)}
|
||||
className={`flex flex-col items-center justify-center rounded-xl border px-4 py-4 text-center transition-all ${
|
||||
isSelected
|
||||
? 'border-indigo-500 bg-indigo-50/70 shadow-sm'
|
||||
: 'border-slate-200 bg-white hover:border-slate-300 hover:bg-slate-50/60'
|
||||
}`}
|
||||
>
|
||||
<span
|
||||
className={`text-sm font-bold ${
|
||||
isSelected ? 'text-indigo-600' : 'text-slate-900'
|
||||
}`}
|
||||
>
|
||||
{opt.title}
|
||||
</span>
|
||||
<span className="mt-1 text-xs text-slate-500">{opt.subtitle}</span>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
216
src/pages/projects/components/detail/DataTab.tsx
Normal file
216
src/pages/projects/components/detail/DataTab.tsx
Normal 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>
|
||||
)
|
||||
}
|
||||
104
src/pages/projects/components/detail/ExportButton.tsx
Normal file
104
src/pages/projects/components/detail/ExportButton.tsx
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
import React, { useState } from 'react'
|
||||
import { ImageItem, LabelClass } from '@/types'
|
||||
|
||||
interface ExportButtonProps {
|
||||
projectSlug?: string
|
||||
images?: ImageItem[]
|
||||
classes?: LabelClass[]
|
||||
}
|
||||
|
||||
export const ExportButton: React.FC<ExportButtonProps> = ({
|
||||
projectSlug = 'traffic_camera_v2',
|
||||
images = [],
|
||||
classes = [],
|
||||
}) => {
|
||||
const [open, setOpen] = useState(false)
|
||||
|
||||
const triggerDownload = (format: 'coco' | 'yolo' | 'json') => {
|
||||
const payload = {
|
||||
dataset: projectSlug,
|
||||
exportFormat: format.toUpperCase(),
|
||||
exportedAt: new Date().toISOString(),
|
||||
classes: classes.map((c, idx) => ({ id: idx + 1, name: c.name, color: c.color, count: c.count })),
|
||||
images: images.map((img) => ({
|
||||
id: img.id,
|
||||
file_name: img.fileName,
|
||||
width: img.width,
|
||||
height: img.height,
|
||||
status: img.status,
|
||||
object_count: img.objectCount,
|
||||
assigned_to: img.assignedTo.name,
|
||||
})),
|
||||
}
|
||||
|
||||
const blob = new Blob([JSON.stringify(payload, null, 2)], {
|
||||
type: 'application/json',
|
||||
})
|
||||
const url = URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
a.download = `${projectSlug}_${format}_annotations.json`
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
document.body.removeChild(a)
|
||||
URL.revokeObjectURL(url)
|
||||
setOpen(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="relative">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setOpen((prev) => !prev)}
|
||||
className="inline-flex h-10 items-center gap-2 rounded-xl border border-slate-200 bg-white px-4 text-xs font-bold text-slate-800 shadow-sm transition hover:bg-slate-50"
|
||||
>
|
||||
<svg
|
||||
className="h-4 w-4 text-slate-600"
|
||||
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-2M7 10l5 5m0 0l5-5m-5 5V4"
|
||||
/>
|
||||
</svg>
|
||||
<span>Xuất nhãn</span>
|
||||
</button>
|
||||
|
||||
{open && (
|
||||
<div className="absolute right-0 top-11 z-20 w-52 rounded-xl border border-slate-200 bg-white py-1.5 shadow-lg">
|
||||
<div className="px-3.5 py-1.5 text-[11px] font-semibold uppercase tracking-wider text-slate-400">
|
||||
Định dạng xuất
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => triggerDownload('coco')}
|
||||
className="flex w-full items-center justify-between px-3.5 py-2 text-left text-xs font-medium text-slate-700 hover:bg-slate-50"
|
||||
>
|
||||
<span>COCO JSON (.json)</span>
|
||||
<span className="rounded bg-indigo-50 px-1.5 py-0.5 text-[10px] font-semibold text-indigo-600">
|
||||
Chuẩn
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => triggerDownload('yolo')}
|
||||
className="flex w-full items-center justify-between px-3.5 py-2 text-left text-xs font-medium text-slate-700 hover:bg-slate-50"
|
||||
>
|
||||
<span>YOLO Format (.json)</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => triggerDownload('json')}
|
||||
className="flex w-full items-center justify-between px-3.5 py-2 text-left text-xs font-medium text-slate-700 hover:bg-slate-50"
|
||||
>
|
||||
<span>LabelMe / Danable JSON</span>
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
190
src/pages/projects/components/detail/ImageTable.tsx
Normal file
190
src/pages/projects/components/detail/ImageTable.tsx
Normal file
|
|
@ -0,0 +1,190 @@
|
|||
import React, { useState, useMemo } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { ImageAnnotationStatus, ImageItem, LabelClass, ProjectStats } from '@/types'
|
||||
import { ImageTableFilters } from './ImageTableFilters'
|
||||
|
||||
interface ImageTableProps {
|
||||
projectId: string
|
||||
projectSlug: string
|
||||
images: ImageItem[]
|
||||
stats: ProjectStats
|
||||
classes: LabelClass[]
|
||||
}
|
||||
|
||||
const STATUS_BADGE_MAP: Record<
|
||||
ImageAnnotationStatus,
|
||||
{ label: string; bg: string; text: string; dot: string }
|
||||
> = {
|
||||
pending_review: {
|
||||
label: 'Chờ duyệt',
|
||||
bg: 'bg-[#FEF3C7]',
|
||||
text: 'text-[#B45309]',
|
||||
dot: 'bg-[#F59E0B]',
|
||||
},
|
||||
in_progress: {
|
||||
label: 'Đang làm',
|
||||
bg: 'bg-[#FEE2E2]/80',
|
||||
text: 'text-[#B91C1C]',
|
||||
dot: 'bg-[#EF4444]',
|
||||
},
|
||||
completed: {
|
||||
label: 'Hoàn thành',
|
||||
bg: 'bg-[#DCFCE7]',
|
||||
text: 'text-[#15803D]',
|
||||
dot: 'bg-[#22C55E]',
|
||||
},
|
||||
unassigned: {
|
||||
label: 'Chưa gán nhãn',
|
||||
bg: 'bg-slate-100',
|
||||
text: 'text-slate-600',
|
||||
dot: 'bg-slate-400',
|
||||
},
|
||||
}
|
||||
|
||||
export const ImageTable: React.FC<ImageTableProps> = ({
|
||||
projectId,
|
||||
projectSlug,
|
||||
images,
|
||||
stats,
|
||||
classes,
|
||||
}) => {
|
||||
const navigate = useNavigate()
|
||||
const [searchQuery, setSearchQuery] = useState('')
|
||||
const [selectedStatus, setSelectedStatus] = useState<'all' | ImageAnnotationStatus>('all')
|
||||
const [selectedMember, setSelectedMember] = useState('all')
|
||||
|
||||
const memberNames = useMemo(() => {
|
||||
const set = new Set<string>()
|
||||
images.forEach((img) => set.add(img.assignedTo.name))
|
||||
return Array.from(set)
|
||||
}, [images])
|
||||
|
||||
const filteredImages = useMemo(() => {
|
||||
return images.filter((img) => {
|
||||
const matchSearch =
|
||||
!searchQuery.trim() ||
|
||||
img.fileName.toLowerCase().includes(searchQuery.trim().toLowerCase())
|
||||
const matchStatus = selectedStatus === 'all' || img.status === selectedStatus
|
||||
const matchMember = selectedMember === 'all' || img.assignedTo.name === selectedMember
|
||||
return matchSearch && matchStatus && matchMember
|
||||
})
|
||||
}, [images, searchQuery, selectedStatus, selectedMember])
|
||||
|
||||
const totalObjects =
|
||||
stats.totalObjects ??
|
||||
classes.reduce((sum, cls) => sum + cls.count, 0)
|
||||
|
||||
const formatNum = (n: number) => n.toLocaleString('vi-VN')
|
||||
|
||||
return (
|
||||
<div className="overflow-hidden rounded-2xl border border-slate-200/80 bg-white shadow-[0_1px_2px_rgba(15,23,42,0.03)]">
|
||||
{/* Top Header + Filter Bar */}
|
||||
<div className="p-5">
|
||||
<div className="mb-4 flex items-center justify-between">
|
||||
<h3 className="text-base font-bold text-slate-900">Danh sách ảnh</h3>
|
||||
<span className="text-xs font-medium text-indigo-600">
|
||||
{formatNum(stats.totalImages)} ảnh · {formatNum(totalObjects)} đối tượng
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<ImageTableFilters
|
||||
searchQuery={searchQuery}
|
||||
onSearchChange={setSearchQuery}
|
||||
selectedStatus={selectedStatus}
|
||||
onStatusChange={setSelectedStatus}
|
||||
selectedMember={selectedMember}
|
||||
onMemberChange={setSelectedMember}
|
||||
memberNames={memberNames}
|
||||
projectSlug={projectSlug}
|
||||
images={images}
|
||||
classes={classes}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Table */}
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full border-collapse text-left">
|
||||
<thead>
|
||||
<tr className="border-y border-slate-200/70 bg-slate-50/70 text-[11px] font-bold uppercase tracking-wider text-slate-400">
|
||||
<th className="py-3 pl-5 pr-4">TÊN ẢNH</th>
|
||||
<th className="px-4 py-3">TRẠNG THÁI</th>
|
||||
<th className="px-4 py-3">NHÃN</th>
|
||||
<th className="px-4 py-3">PHÂN CÔNG</th>
|
||||
<th className="py-3 pl-4 pr-5">THAO TÁC</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-slate-100 text-xs">
|
||||
{filteredImages.length === 0 ? (
|
||||
<tr>
|
||||
<td colSpan={5} className="py-10 text-center text-slate-400">
|
||||
Không tìm thấy ảnh phù hợp với bộ lọc hiện tại.
|
||||
</td>
|
||||
</tr>
|
||||
) : (
|
||||
filteredImages.map((image) => {
|
||||
const badge = STATUS_BADGE_MAP[image.status]
|
||||
return (
|
||||
<tr
|
||||
key={image.id}
|
||||
onClick={() =>
|
||||
navigate(`/projects/${projectId}/annotate?imageId=${image.id}`)
|
||||
}
|
||||
className="cursor-pointer transition hover:bg-slate-50/80"
|
||||
>
|
||||
<td className="py-3.5 pl-5 pr-4">
|
||||
<div className="flex items-center gap-3.5">
|
||||
<img
|
||||
src={image.thumbnailUrl}
|
||||
alt={image.fileName}
|
||||
className="h-9 w-14 rounded-lg object-cover border border-slate-200/60 shrink-0"
|
||||
/>
|
||||
<div>
|
||||
<p className="font-mono text-xs font-semibold text-slate-900">
|
||||
{image.fileName}
|
||||
</p>
|
||||
<p className="mt-0.5 text-[11px] text-slate-400">
|
||||
{image.width} × {image.height} px
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<td className="px-4 py-3.5">
|
||||
<span
|
||||
className={`inline-flex items-center gap-1.5 rounded-full px-3 py-1 text-xs font-semibold ${badge.bg} ${badge.text}`}
|
||||
>
|
||||
<span className={`h-1.5 w-1.5 rounded-full ${badge.dot}`} />
|
||||
{badge.label}
|
||||
</span>
|
||||
</td>
|
||||
|
||||
<td className="px-4 py-3.5 text-slate-600">
|
||||
{image.objectCount} đối tượng
|
||||
</td>
|
||||
|
||||
<td className="px-4 py-3.5 font-semibold text-slate-800">
|
||||
{image.assignedTo.name}
|
||||
</td>
|
||||
|
||||
<td className="py-3.5 pl-4 pr-5">
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
navigate(`/projects/${projectId}/annotate?imageId=${image.id}`)
|
||||
}}
|
||||
className="font-semibold text-indigo-600 hover:text-indigo-700 transition"
|
||||
>
|
||||
Mở ảnh →
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
)
|
||||
})
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue