feat(upload): list user-only tasks, show date-time using formatTimeAgo, and use Shadcn Progress

This commit is contained in:
yiling
2026-06-01 11:20:58 +08:00
parent 747efe0358
commit 3bde1c1a82
4 changed files with 8 additions and 21 deletions
-1
View File
@@ -51,7 +51,6 @@ export const taskInfoSchema = z.object({
total: z.number(),
uploaded: z.number(),
createdAt: z.string(),
uploaderName: z.string().optional(),
})
export type TaskInfo = z.infer<typeof taskInfoSchema>
+1 -2
View File
@@ -311,7 +311,7 @@ describe('UploadService', () => {
expect(parentFolder?.sizeByte).toBe(3000)
})
it('should list upload tasks and include the creator name as uploaderName', async () => {
it('should list upload tasks', async () => {
const task = await prisma.task.create({
data: {
creatorId: userId,
@@ -326,6 +326,5 @@ describe('UploadService', () => {
expect(result.data).toHaveLength(1)
expect(result.data[0].id).toBe(task.id)
expect(result.data[0].name).toBe('test-upload-task')
expect(result.data[0].uploaderName).toBe('test')
})
})
-2
View File
@@ -346,7 +346,6 @@ export class UploadService {
async (skip, take) => {
return this.prismaClient.task.findMany({
where,
include: { creator: true },
orderBy: { id: 'desc' },
skip,
take,
@@ -362,7 +361,6 @@ export class UploadService {
total: t.total || 0,
uploaded: t.uploaded,
createdAt: t.createdAt.toISOString(),
uploaderName: t.creator?.name || undefined,
}))
return { data: infos, pageInfo }
+7 -16
View File
@@ -2,11 +2,12 @@ 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, CheckCircle2, Clock, User, UploadCloud } 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)
@@ -28,7 +29,7 @@ function UploadTaskItem({ task }: { task: TaskInfo }) {
let formattedTime = ''
try {
formattedTime = format(parseISO(task.createdAt), 'h:mm a')
formattedTime = formatTimeAgo(task.createdAt)
} catch {
formattedTime = 'unknown'
}
@@ -60,20 +61,10 @@ function UploadTaskItem({ task }: { task: TaskInfo }) {
</div>
</div>
{/* Middle row: Uploader Name & Created Time */}
<div className="flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground mb-3 font-medium">
{task.uploaderName && (
<div className="flex items-center gap-1">
<User className="w-3.5 h-3.5 text-muted-foreground/75" />
<span className="truncate max-w-[120px]" title={task.uploaderName}>
{task.uploaderName}
</span>
</div>
)}
<div className="flex items-center gap-1">
<Clock className="w-3.5 h-3.5 text-muted-foreground/75" />
<span>{formattedTime}</span>
</div>
{/* 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 */}