|
| 1 | +/** |
| 2 | + * SegmentList — 精细路径提取结果列表 |
| 3 | + * Extracted segment list for the fine capture path. |
| 4 | + * |
| 5 | + * @ai-context: 右侧内容区组件(fine 路径)。从 ClassroomPage 平移拆出, |
| 6 | + * 支持多选/批量插入(当前落地为复制剪贴板),新片段到达时自动滚动到底部。 |
| 7 | + * @ai-context: Right-pane component for the fine path, split out of |
| 8 | + * ClassroomPage; auto-scrolls to bottom when new segments arrive. |
| 9 | + */ |
| 10 | +import { useRef, useEffect } from 'react'; |
| 11 | +import { Eye, Plus, ListPlus, CheckCircle2 } from 'lucide-react'; |
| 12 | +import { cn } from '@/lib/utils'; |
| 13 | +import type { ExtractedSegment } from '@/lib/capture'; |
| 14 | + |
| 15 | +interface SegmentListProps { |
| 16 | + segments: ExtractedSegment[]; |
| 17 | + selectedIds: Set<string>; |
| 18 | + onToggleSelect: (id: string) => void; |
| 19 | + onInsertSelected: () => void; |
| 20 | + onInsertAll: () => void; |
| 21 | +} |
| 22 | + |
| 23 | +export function SegmentList({ segments, selectedIds, onToggleSelect, onInsertSelected, onInsertAll }: SegmentListProps) { |
| 24 | + const scrollRef = useRef<HTMLDivElement>(null); |
| 25 | + useEffect(() => { |
| 26 | + if (scrollRef.current) scrollRef.current.scrollTop = scrollRef.current.scrollHeight; |
| 27 | + }, [segments.length]); |
| 28 | + |
| 29 | + return ( |
| 30 | + <div className="flex-1 flex flex-col min-h-0"> |
| 31 | + <div className="flex items-center justify-between px-4 py-3 border-b border-border/20"> |
| 32 | + <span className="text-b2 font-medium text-text-secondary">提取结果 ({segments.length})</span> |
| 33 | + <div className="flex items-center gap-2"> |
| 34 | + <button onClick={onInsertSelected} disabled={selectedIds.size === 0} |
| 35 | + className={cn('inline-flex items-center gap-1 px-2.5 py-1.5 rounded-kb-sm text-b3 font-medium transition-all', |
| 36 | + selectedIds.size > 0 ? 'bg-brand-50 text-brand-600 hover:bg-brand-100' : 'text-text-tertiary cursor-not-allowed')}> |
| 37 | + <Plus className="w-3.5 h-3.5" strokeWidth={2} /> 插入选中 |
| 38 | + </button> |
| 39 | + <button onClick={onInsertAll} disabled={segments.length === 0} |
| 40 | + className={cn('inline-flex items-center gap-1 px-2.5 py-1.5 rounded-kb-sm text-b3 font-medium transition-all', |
| 41 | + segments.length > 0 ? 'bg-bg-secondary text-text-secondary hover:bg-bg-tertiary' : 'text-text-tertiary cursor-not-allowed')}> |
| 42 | + <ListPlus className="w-3.5 h-3.5" strokeWidth={2} /> 全部插入 |
| 43 | + </button> |
| 44 | + </div> |
| 45 | + </div> |
| 46 | + <div ref={scrollRef} className="flex-1 overflow-y-auto px-4 py-3 space-y-2"> |
| 47 | + {segments.length === 0 && ( |
| 48 | + <div className="flex flex-col items-center justify-center py-16 text-text-tertiary"> |
| 49 | + <Eye className="w-12 h-12 mb-3 opacity-20" strokeWidth={1} /> |
| 50 | + <p className="text-b2">采集进行中,提取结果将在此显示</p> |
| 51 | + </div> |
| 52 | + )} |
| 53 | + {segments.map((seg) => { |
| 54 | + const isSelected = selectedIds.has(seg.id); |
| 55 | + const sourceLabel = seg.source === 'vision' ? '视觉' : seg.source === 'audio' ? '音频' : 'UI'; |
| 56 | + const sourceColor = seg.source === 'vision' |
| 57 | + ? 'bg-accent-500/10 text-accent-600' |
| 58 | + : seg.source === 'audio' ? 'bg-emerald-500/10 text-emerald-600' : 'bg-amber-500/10 text-amber-600'; |
| 59 | + return ( |
| 60 | + <div key={seg.id} onClick={() => onToggleSelect(seg.id)} |
| 61 | + className={cn('group p-3 rounded-kb-md cursor-pointer transition-all border border-transparent', |
| 62 | + isSelected ? 'bg-brand-50/50 border-brand-200/50' : 'hover:bg-bg-tertiary/50')}> |
| 63 | + <div className="flex items-center gap-2 mb-1.5"> |
| 64 | + <span className={cn('px-1.5 py-0.5 rounded-kb-xs text-[10px] font-medium', sourceColor)}>{sourceLabel}</span> |
| 65 | + <span className="text-[10px] text-text-tertiary">{new Date(seg.timestamp).toLocaleTimeString()}</span> |
| 66 | + {isSelected && <CheckCircle2 className="ml-auto w-4 h-4 text-brand-500" strokeWidth={1.5} />} |
| 67 | + </div> |
| 68 | + <p className="text-b2 text-text-primary leading-relaxed">{seg.text}</p> |
| 69 | + </div> |
| 70 | + ); |
| 71 | + })} |
| 72 | + </div> |
| 73 | + </div> |
| 74 | + ); |
| 75 | +} |
0 commit comments