feat(webui): show comments count badge in file card preview area (#403)

* feat(webui): show comments count badge in file card preview area

* perf(db): add index on asset_comments asset_id
This commit is contained in:
Yiling-J
2026-09-13 21:12:21 +08:00
committed by GitHub
parent 87e88396d1
commit 7d56b5bf90
8 changed files with 288 additions and 3 deletions
@@ -214,4 +214,43 @@ describe('FileCard', () => {
expect(tooltip.textContent).toContain('Very Long Creator Name')
vi.useRealTimers()
})
it('renders comments count badge in preview area when commentsCount > 0', () => {
const itemWithComments: AssetInfo = {
...fileItem,
commentsCount: 5,
} as AssetInfo
renderComponent({ item: itemWithComments })
const commentsBadge = screen.getByTestId('file-card-comments-count')
expect(commentsBadge).toBeTruthy()
expect(commentsBadge.textContent).toContain('5')
expect(commentsBadge.className).toContain('absolute')
expect(commentsBadge.className).toContain('bottom-1')
expect(commentsBadge.className).toContain('left-1')
expect(commentsBadge.className).toContain('bg-black/60')
expect(commentsBadge.className).toContain('text-white')
expect(commentsBadge.className).toContain('pointer-events-none')
expect(commentsBadge.className).toContain('tabular-nums')
})
it('does not render comments count badge when commentsCount is 0 or undefined', () => {
const itemZeroComments: AssetInfo = {
...fileItem,
commentsCount: 0,
} as AssetInfo
const { unmount } = renderComponent({ item: itemZeroComments })
expect(screen.queryByTestId('file-card-comments-count')).toBeNull()
unmount()
const itemNoComments: AssetInfo = {
...fileItem,
commentsCount: undefined,
} as AssetInfo
renderComponent({ item: itemNoComments })
expect(screen.queryByTestId('file-card-comments-count')).toBeNull()
})
})
@@ -27,7 +27,15 @@ import { selectFileNameWithoutExtension } from '@/ui/lib/rename-utils'
import { cn } from '@/ui/lib/utils'
import { useUploadStore } from '@/ui/stores/upload'
import { useDraggable, useDroppable } from '@dnd-kit/react'
import { Download, Edit, History, Layers, MoreHorizontal, Trash2 } from 'lucide-react'
import {
Download,
Edit,
History,
Layers,
MessageCircleMore,
MoreHorizontal,
Trash2,
} from 'lucide-react'
import React, { useEffect, useMemo, useRef, useState } from 'react'
import type { DragState } from '../dnd-types'
import FieldRenderer from '../field-renderer'
@@ -323,7 +331,18 @@ export function FileCard({
)}
</div>
) : (
<FilePreview item={displayItem} showDuration />
<>
<FilePreview item={displayItem} showDuration />
{typeof displayItem.commentsCount === 'number' && displayItem.commentsCount > 0 && (
<span
data-testid="file-card-comments-count"
className="pointer-events-none absolute bottom-1 left-1 z-10 flex items-center gap-1 rounded bg-black/60 px-1 py-0.5 text-xs font-medium tabular-nums text-white"
>
<MessageCircleMore className="h-3.5 w-3.5" />
<span>{displayItem.commentsCount}</span>
</span>
)}
</>
)}
</div>