mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-23 08:08:22 +00:00
Merge pull request #47 from shumaiOne/feat/upload-tasks-refactor
feat(upload): group tasks by day, show uploader name, and use system colors
This commit is contained in:
@@ -155,6 +155,10 @@ The frontend is built with:
|
||||
- **Framework**: React
|
||||
- **Styling**: Tailwind CSS + Shadcn UI (Components)
|
||||
|
||||
### UI Rules
|
||||
|
||||
- **Prefer System Colors**: Always prefer using semantic system color design tokens (e.g., `bg-background`, `text-foreground`, `text-sidebar-primary`, `text-muted-foreground`, etc.) over hardcoded color utilities (e.g., `bg-blue-50`, `text-emerald-600`, `bg-emerald-500`). This ensures seamless compatibility with light and dark themes.
|
||||
|
||||
### Development
|
||||
|
||||
- **Run Dev**: `bun --hot src/index.ts` (Runs on port 3000)
|
||||
|
||||
@@ -310,4 +310,21 @@ describe('UploadService', () => {
|
||||
const parentFolder = await prisma.asset.findUnique({ where: { id: parentId } })
|
||||
expect(parentFolder?.sizeByte).toBe(3000)
|
||||
})
|
||||
|
||||
it('should list upload tasks', async () => {
|
||||
const task = await prisma.task.create({
|
||||
data: {
|
||||
creatorId: userId,
|
||||
total: 3,
|
||||
uploaded: 1,
|
||||
type: 'upload',
|
||||
name: 'test-upload-task',
|
||||
},
|
||||
})
|
||||
|
||||
const result = await uploadService.listUploadTasks(userId, { first: 10 })
|
||||
expect(result.data).toHaveLength(1)
|
||||
expect(result.data[0].id).toBe(task.id)
|
||||
expect(result.data[0].name).toBe('test-upload-task')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -2,28 +2,92 @@ import { client } from '@/ui/api/client'
|
||||
import type { TaskInfo } from '@/dtos/upload'
|
||||
import { useTeamId } from '@/ui/hooks/use-team-id'
|
||||
import { useInfiniteQuery } from '@tanstack/react-query'
|
||||
import { Loader2 } from 'lucide-react'
|
||||
import { Loader2, CheckCircle2, Clock, UploadCloud } from 'lucide-react'
|
||||
import { useEffect } from 'react'
|
||||
import { useInView } from 'react-intersection-observer'
|
||||
import { format, parseISO, isToday, isYesterday } from 'date-fns'
|
||||
import { Progress } from '@/ui/components/ui/progress'
|
||||
import { formatTimeAgo } from '@/ui/lib/time'
|
||||
|
||||
function formatDayHeader(dateString: string): string {
|
||||
const date = parseISO(dateString)
|
||||
if (isNaN(date.getTime())) {
|
||||
return 'Unknown Date'
|
||||
}
|
||||
if (isToday(date)) {
|
||||
return 'Today'
|
||||
}
|
||||
if (isYesterday(date)) {
|
||||
return 'Yesterday'
|
||||
}
|
||||
return format(date, 'MMMM d, yyyy')
|
||||
}
|
||||
|
||||
function UploadTaskItem({ task }: { task: TaskInfo }) {
|
||||
const progress =
|
||||
task.total && task.total > 0 ? `${((task.uploaded ?? 0) / task.total) * 100}%` : '0%'
|
||||
const isCompleted = task.uploaded === task.total
|
||||
const percent = task.total > 0 ? (task.uploaded / task.total) * 100 : 0
|
||||
|
||||
let formattedTime = ''
|
||||
try {
|
||||
formattedTime = formatTimeAgo(task.createdAt)
|
||||
} catch {
|
||||
formattedTime = 'unknown'
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="p-2 rounded-md transition-colors hover:bg-sidebar-accent">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-sm font-medium truncate">{task.name ?? 'unknown'}</span>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{task.uploaded}/{task.total}
|
||||
</span>
|
||||
<div className="group relative flex flex-col p-4 rounded-xl border border-sidebar-border bg-sidebar-accent/30 text-sidebar-foreground shadow-xs transition-all duration-200 hover:shadow-md hover:border-sidebar-foreground/20 hover:bg-sidebar-accent/50">
|
||||
{/* Top row: Name & Status Badge */}
|
||||
<div className="flex items-start justify-between gap-2 mb-2">
|
||||
<div className="min-w-0 flex-1">
|
||||
<span
|
||||
className="text-sm font-semibold tracking-tight text-sidebar-foreground truncate block"
|
||||
title={task.name}
|
||||
>
|
||||
{task.name || 'Untitled Upload'}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex-shrink-0">
|
||||
{isCompleted ? (
|
||||
<span className="inline-flex items-center gap-1 text-xs font-semibold text-muted-foreground bg-muted px-2 py-0.5 rounded-full transition-colors">
|
||||
<CheckCircle2 className="w-3.5 h-3.5" />
|
||||
Done
|
||||
</span>
|
||||
) : (
|
||||
<span className="inline-flex items-center gap-1 text-xs font-semibold text-sidebar-primary bg-sidebar-primary/10 px-2 py-0.5 rounded-full animate-pulse">
|
||||
<Loader2 className="w-3.5 h-3.5 animate-spin" />
|
||||
Uploading
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-1 h-1 w-full bg-muted rounded-full">
|
||||
<div className="h-1 bg-primary rounded-full" style={{ width: progress }} />
|
||||
|
||||
{/* Middle row: Created Time (Date & Time together) */}
|
||||
<div className="flex items-center gap-1.5 text-xs text-muted-foreground mb-3 font-medium">
|
||||
<Clock className="w-3.5 h-3.5 text-muted-foreground/75" />
|
||||
<span>{formattedTime}</span>
|
||||
</div>
|
||||
|
||||
{/* Bottom row: Progress Bar and Fraction */}
|
||||
<div className="space-y-1.5 mt-auto">
|
||||
<div className="flex items-center justify-between text-xs font-semibold">
|
||||
<span className="text-muted-foreground/80">
|
||||
{task.uploaded} / {task.total} {task.total === 1 ? 'file' : 'files'}
|
||||
</span>
|
||||
{!isCompleted && (
|
||||
<span className="text-sidebar-primary font-mono font-bold">{Math.round(percent)}%</span>
|
||||
)}
|
||||
</div>
|
||||
<Progress value={percent} className="h-1.5 w-full bg-muted" />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
interface TaskGroup {
|
||||
day: string
|
||||
tasks: TaskInfo[]
|
||||
}
|
||||
|
||||
export function UploadTasks() {
|
||||
const teamId = useTeamId()
|
||||
const {
|
||||
@@ -61,20 +125,61 @@ export function UploadTasks() {
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center p-4">
|
||||
<Loader2 className="h-6 w-6 animate-spin" />
|
||||
<div className="flex items-center justify-center p-8">
|
||||
<Loader2 className="h-6 w-6 animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (tasks.length === 0) {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center p-8 text-center border border-dashed border-border rounded-xl bg-muted/10 my-4">
|
||||
<UploadCloud className="h-8 w-8 text-muted-foreground/50 mb-3" />
|
||||
<p className="text-sm font-semibold text-muted-foreground">No uploads yet</p>
|
||||
<p className="text-xs text-muted-foreground/60 mt-1 max-w-[180px]">
|
||||
Upload files in the project view to track progress here.
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// Group tasks by day (maintaining desc ordering)
|
||||
const taskGroups: TaskGroup[] = []
|
||||
tasks.forEach((task) => {
|
||||
const day = formatDayHeader(task.createdAt)
|
||||
let group = taskGroups.find((g) => g.day === day)
|
||||
if (!group) {
|
||||
group = { day, tasks: [] }
|
||||
taskGroups.push(group)
|
||||
}
|
||||
group.tasks.push(task)
|
||||
})
|
||||
|
||||
return (
|
||||
<div className="flex flex-col space-y-2">
|
||||
{tasks?.map((task) => (
|
||||
<UploadTaskItem key={task.id} task={task} />
|
||||
<div className="flex flex-col space-y-4">
|
||||
{taskGroups.map((group) => (
|
||||
<div key={group.day} className="relative flex flex-col">
|
||||
{/* Day Sticky Header */}
|
||||
<div className="sticky top-0 bg-sidebar/95 backdrop-blur-sm z-10 py-2 px-1 flex items-center justify-between border-b border-border/40">
|
||||
<span className="text-xs font-bold uppercase tracking-wider text-muted-foreground/80">
|
||||
{group.day}
|
||||
</span>
|
||||
<span className="text-[10px] font-semibold text-muted-foreground/60 bg-muted px-2 py-0.5 rounded-full">
|
||||
{group.tasks.length} {group.tasks.length === 1 ? 'task' : 'tasks'}
|
||||
</span>
|
||||
</div>
|
||||
{/* Tasks in Day */}
|
||||
<div className="mt-3 space-y-3">
|
||||
{group.tasks.map((task) => (
|
||||
<UploadTaskItem key={task.id} task={task} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
|
||||
{hasNextPage && (
|
||||
<div ref={ref} className="flex items-center justify-center p-2">
|
||||
{isFetchingNextPage && <Loader2 className="h-4 w-4 animate-spin" />}
|
||||
<div ref={ref} className="flex items-center justify-center p-4">
|
||||
{isFetchingNextPage && <Loader2 className="h-5 w-5 animate-spin text-muted-foreground" />}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user