Rewrites the desktop mirror as services/sync/SyncEngine: a persistent outbox, per-account server-clock keyset cursors with paging, pulls that never overwrite unsent local edits, deletions both ways through sync_tombstones and per-row failure isolation. It now covers history titles and favorites, dictionary, every meeting's memos and documents, memo tags, user commands and dictation/meeting templates, and registers the desktop as a device that the phone can disconnect. Fixes shipped defects: the first pull after sign-in fetched nothing, only the first meeting's children were pushed, team meetings leaked into the personal database and lost team_id on re-push, and Realtime never connected because Electron's Node 20 has no global WebSocket (ws is now the transport). Anonymous local-mode records are imported into the first account that signs in. The settings sync section is translated and shows pending/rejected changes; synced screens reload on app:dataChanged.
393 lines
14 KiB
TypeScript
393 lines
14 KiB
TypeScript
// src/renderer/components/shared/HistoryEntryCard.tsx
|
|
// High-End Agency Dictation History Card with Audio Telemetry & Instant Actions
|
|
|
|
import React, { useState, useEffect, useCallback } from 'react'
|
|
import { Box, IconButton, Tooltip, Chip, Collapse } from '@mui/material'
|
|
import { Copy, Check, Trash2, Tag, X, ScrollText, ChevronDown, Sparkles, Volume2, Star } from 'lucide-react'
|
|
import { MetalCard, Led, TactileBadge } from '@d3ro/ui/components/ds'
|
|
import { d3roPalette, d3roFontSans, d3roFontMono, d3roTypo, d3roRadius, d3roShadow } from '@d3ro/ui/theme'
|
|
import { useI18n } from '@d3ro/i18n'
|
|
import { formatDuration } from '../../utils/formatters'
|
|
import { isImeComposingEvent } from '../../utils/keyboard'
|
|
import type { HistoryEntry, MemoTag, MeetingSummaryResult } from '@d3ro/core/types'
|
|
|
|
export interface HistoryEntryCardProps {
|
|
entry: HistoryEntry
|
|
onCopy?: (text: string) => void
|
|
onDelete?: (id: string) => void
|
|
/** 즐겨찾기 토글 — 모바일·웹과 공유되는 값 */
|
|
onToggleFavorite?: (entry: HistoryEntry) => void
|
|
showTags?: boolean
|
|
onTagClick?: (tag: string) => void
|
|
}
|
|
|
|
export function HistoryEntryCard({
|
|
entry,
|
|
onCopy,
|
|
onDelete,
|
|
onToggleFavorite,
|
|
showTags = false,
|
|
onTagClick,
|
|
}: HistoryEntryCardProps): React.ReactElement {
|
|
const { t, formatTime } = useI18n()
|
|
const displayText = entry.polishedText || entry.originalText
|
|
const isPolished = Boolean(entry.polishedText)
|
|
const [tags, setTags] = useState<MemoTag[]>([])
|
|
const [tagInput, setTagInput] = useState('')
|
|
const [showTagInput, setShowTagInput] = useState(false)
|
|
const [summaryExpanded, setSummaryExpanded] = useState(false)
|
|
const [summary, setSummary] = useState<MeetingSummaryResult | null>(null)
|
|
const [summaryLoading, setSummaryLoading] = useState(false)
|
|
const [copied, setCopied] = useState(false)
|
|
const hasSummary = !!entry.summaryText
|
|
|
|
const loadTags = useCallback(async () => {
|
|
if (!showTags) return
|
|
const result = await window.electronAPI.memo.getTags(entry.id)
|
|
if (result.success) setTags(result.data)
|
|
}, [entry.id, showTags])
|
|
|
|
useEffect(() => {
|
|
loadTags()
|
|
}, [loadTags])
|
|
|
|
const handleCopyClick = (e: React.MouseEvent) => {
|
|
e.stopPropagation()
|
|
onCopy?.(displayText)
|
|
setCopied(true)
|
|
setTimeout(() => setCopied(false), 1500)
|
|
}
|
|
|
|
const handleAddTag = useCallback(async () => {
|
|
const trimmed = tagInput.trim()
|
|
if (!trimmed) return
|
|
const result = await window.electronAPI.memo.addTag(entry.id, trimmed)
|
|
if (result.success) {
|
|
setTags((prev) => [...prev, result.data])
|
|
setTagInput('')
|
|
setShowTagInput(false)
|
|
}
|
|
}, [entry.id, tagInput])
|
|
|
|
const handleRemoveTag = useCallback(
|
|
async (tag: string) => {
|
|
const result = await window.electronAPI.memo.removeTag(entry.id, tag)
|
|
if (result.success) {
|
|
setTags((prev) => prev.filter((t) => t.tag !== tag))
|
|
}
|
|
},
|
|
[entry.id],
|
|
)
|
|
|
|
const handleTagKeyDown = useCallback(
|
|
(e: React.KeyboardEvent) => {
|
|
if (isImeComposingEvent(e)) return
|
|
if (e.key === 'Enter') {
|
|
e.preventDefault()
|
|
handleAddTag()
|
|
}
|
|
if (e.key === 'Escape') {
|
|
setShowTagInput(false)
|
|
setTagInput('')
|
|
}
|
|
},
|
|
[handleAddTag],
|
|
)
|
|
|
|
const handleToggleSummary = useCallback(
|
|
async (e: React.MouseEvent) => {
|
|
e.stopPropagation()
|
|
if (summaryExpanded) {
|
|
setSummaryExpanded(false)
|
|
return
|
|
}
|
|
setSummaryExpanded(true)
|
|
if (!summary) {
|
|
setSummaryLoading(true)
|
|
const result = await window.electronAPI.meetingSummary.getSummary({ historyId: entry.id })
|
|
if (result.success && result.data) {
|
|
setSummary(result.data)
|
|
}
|
|
setSummaryLoading(false)
|
|
}
|
|
},
|
|
[summaryExpanded, summary, entry.id],
|
|
)
|
|
|
|
return (
|
|
<MetalCard
|
|
sx={{
|
|
p: 2.5,
|
|
transition: 'transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease',
|
|
'&:hover': {
|
|
transform: 'translateY(-1px)',
|
|
},
|
|
}}
|
|
>
|
|
<Box sx={{ display: 'flex', alignItems: 'flex-start', gap: 2 }}>
|
|
{/* Status Indicator Bead */}
|
|
<Box sx={{ pt: 0.5 }}>
|
|
<Led
|
|
color={entry.status === 'completed' ? 'green' : 'red'}
|
|
size={7}
|
|
pulse={entry.status === 'processing'}
|
|
/>
|
|
</Box>
|
|
|
|
<Box sx={{ flex: 1, minWidth: 0 }}>
|
|
{/* Header Row: Title + Timestamp + Action Icons */}
|
|
<Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', mb: 0.75 }}>
|
|
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1, minWidth: 0 }}>
|
|
<Box
|
|
sx={{
|
|
fontSize: d3roTypo.compact.size,
|
|
fontWeight: 600,
|
|
fontFamily: d3roFontSans,
|
|
color: d3roPalette.text.primary,
|
|
lineHeight: 1.2,
|
|
overflow: 'hidden',
|
|
textOverflow: 'ellipsis',
|
|
whiteSpace: 'nowrap',
|
|
}}
|
|
>
|
|
{entry.title ?? displayText.slice(0, 50)}
|
|
</Box>
|
|
{isPolished && (
|
|
<Tooltip title="AI Polished">
|
|
<Box sx={{ display: 'flex', alignItems: 'center', color: d3roPalette.accent.light }}>
|
|
<Sparkles size={13} />
|
|
</Box>
|
|
</Tooltip>
|
|
)}
|
|
</Box>
|
|
|
|
{/* Quick Action Buttons */}
|
|
<Box sx={{ display: 'flex', alignItems: 'center', gap: 0.5, flexShrink: 0 }}>
|
|
{onToggleFavorite && (
|
|
<Tooltip title={entry.isFavorite ? t('history.unfavorite') : t('history.favorite')}>
|
|
<IconButton
|
|
size="small"
|
|
aria-pressed={entry.isFavorite}
|
|
aria-label={entry.isFavorite ? t('history.unfavorite') : t('history.favorite')}
|
|
onClick={(e) => {
|
|
e.stopPropagation()
|
|
onToggleFavorite(entry)
|
|
}}
|
|
sx={{
|
|
p: 0.6,
|
|
color: entry.isFavorite ? d3roPalette.tag.orange : d3roPalette.text.inactive,
|
|
bgcolor: entry.isFavorite ? d3roPalette.tag.orangeBg : 'transparent',
|
|
'&:hover': { color: d3roPalette.tag.orange, bgcolor: d3roPalette.tag.orangeBg },
|
|
}}
|
|
>
|
|
<Star size={14} fill={entry.isFavorite ? 'currentColor' : 'none'} />
|
|
</IconButton>
|
|
</Tooltip>
|
|
)}
|
|
<Tooltip title={copied ? t('common.copied') : t('common.copy')}>
|
|
<IconButton
|
|
size="small"
|
|
onClick={handleCopyClick}
|
|
sx={{
|
|
p: 0.6,
|
|
color: copied ? d3roPalette.tag.green : d3roPalette.text.inactive,
|
|
bgcolor: copied ? d3roPalette.tag.greenBg : 'transparent',
|
|
'&:hover': { color: d3roPalette.text.primary, bgcolor: d3roPalette.glass.raised },
|
|
}}
|
|
>
|
|
{copied ? <Check size={14} /> : <Copy size={14} />}
|
|
</IconButton>
|
|
</Tooltip>
|
|
|
|
{onDelete && (
|
|
<Tooltip title={t('common.delete')}>
|
|
<IconButton
|
|
size="small"
|
|
onClick={(e) => {
|
|
e.stopPropagation()
|
|
onDelete(entry.id)
|
|
}}
|
|
sx={{
|
|
p: 0.6,
|
|
color: d3roPalette.text.inactive,
|
|
'&:hover': { color: d3roPalette.tag.red, bgcolor: d3roPalette.tag.redBg },
|
|
}}
|
|
>
|
|
<Trash2 size={14} />
|
|
</IconButton>
|
|
</Tooltip>
|
|
)}
|
|
</Box>
|
|
</Box>
|
|
|
|
{/* Transcript Content Preview */}
|
|
<Box
|
|
sx={{
|
|
fontFamily: d3roFontSans,
|
|
fontSize: '13px',
|
|
color: d3roPalette.text.secondary,
|
|
lineHeight: 1.55,
|
|
overflow: 'hidden',
|
|
textOverflow: 'ellipsis',
|
|
display: '-webkit-box',
|
|
WebkitLineClamp: 2,
|
|
WebkitBoxOrient: 'vertical',
|
|
mb: 1.5,
|
|
}}
|
|
>
|
|
{displayText}
|
|
</Box>
|
|
|
|
{/* Metadata Telemetry Badges */}
|
|
<Box
|
|
sx={{
|
|
display: 'flex',
|
|
flexWrap: 'wrap',
|
|
alignItems: 'center',
|
|
gap: 1,
|
|
fontFamily: d3roFontMono,
|
|
fontSize: '11px',
|
|
color: d3roPalette.text.dimLabel,
|
|
}}
|
|
>
|
|
<TactileBadge mono tone="mono">
|
|
{formatTime(entry.createdAt)}
|
|
</TactileBadge>
|
|
|
|
<TactileBadge mono tone="default">
|
|
<Volume2 size={11} style={{ marginRight: 2 }} />
|
|
{formatDuration(entry.duration)}
|
|
</TactileBadge>
|
|
|
|
{entry.detectedLanguage && (
|
|
<TactileBadge mono tone="accent">
|
|
{entry.detectedLanguage.toUpperCase()}
|
|
</TactileBadge>
|
|
)}
|
|
|
|
{hasSummary && (
|
|
<TactileBadge
|
|
tone="success"
|
|
onClick={handleToggleSummary}
|
|
sx={{ cursor: 'pointer' }}
|
|
>
|
|
<ScrollText size={11} style={{ marginRight: 2 }} />
|
|
{t('meetingSummary.title')}
|
|
<ChevronDown
|
|
size={12}
|
|
style={{
|
|
transform: summaryExpanded ? 'rotate(180deg)' : 'none',
|
|
transition: 'transform 0.2s ease',
|
|
}}
|
|
/>
|
|
</TactileBadge>
|
|
)}
|
|
</Box>
|
|
|
|
{/* Tags Row */}
|
|
{showTags && (
|
|
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 0.5, mt: 1.25, alignItems: 'center' }}>
|
|
{tags.map((tag) => (
|
|
<Chip
|
|
key={tag.id}
|
|
label={`#${tag.tag}`}
|
|
size="small"
|
|
onClick={() => onTagClick?.(tag.tag)}
|
|
onDelete={() => handleRemoveTag(tag.tag)}
|
|
deleteIcon={<X size={11} />}
|
|
sx={{
|
|
height: 20,
|
|
fontFamily: d3roFontMono,
|
|
fontSize: '10.5px',
|
|
bgcolor: d3roPalette.tag.purpleBg,
|
|
color: d3roPalette.tag.purple,
|
|
borderRadius: d3roRadius.pill,
|
|
'& .MuiChip-deleteIcon': { color: d3roPalette.tag.purple, fontSize: 11 },
|
|
'&:hover': { bgcolor: d3roPalette.tag.purple, color: d3roPalette.text.inverse },
|
|
}}
|
|
/>
|
|
))}
|
|
{showTagInput ? (
|
|
<Box
|
|
component="input"
|
|
value={tagInput}
|
|
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setTagInput(e.target.value)}
|
|
onKeyDown={handleTagKeyDown}
|
|
onBlur={() => {
|
|
if (!tagInput.trim()) setShowTagInput(false)
|
|
}}
|
|
autoFocus
|
|
placeholder={t('memo.tagPlaceholder')}
|
|
sx={{
|
|
border: `1px solid ${d3roPalette.accent.main}`,
|
|
bgcolor: d3roPalette.bg.input,
|
|
color: d3roPalette.text.primary,
|
|
fontFamily: d3roFontMono,
|
|
fontSize: '11px',
|
|
px: 1,
|
|
py: 0.25,
|
|
borderRadius: d3roRadius.pill,
|
|
outline: 'none',
|
|
width: 90,
|
|
}}
|
|
/>
|
|
) : (
|
|
<IconButton
|
|
size="small"
|
|
onClick={() => setShowTagInput(true)}
|
|
sx={{
|
|
p: 0.4,
|
|
color: d3roPalette.text.inactive,
|
|
bgcolor: d3roPalette.bg.inset,
|
|
borderRadius: '50%',
|
|
'&:hover': { color: d3roPalette.accent.light, bgcolor: d3roPalette.glass.raised },
|
|
}}
|
|
>
|
|
<Tag size={11} />
|
|
</IconButton>
|
|
)}
|
|
</Box>
|
|
)}
|
|
|
|
{/* Expandable Meeting Summary Box */}
|
|
<Collapse in={summaryExpanded}>
|
|
<Box
|
|
sx={{
|
|
mt: 2,
|
|
p: 2,
|
|
borderRadius: d3roRadius.inner,
|
|
bgcolor: d3roPalette.bg.inset,
|
|
border: `1px solid ${d3roPalette.glass.hairlineStrong}`,
|
|
boxShadow: d3roShadow.inset,
|
|
}}
|
|
>
|
|
{summaryLoading ? (
|
|
<Box sx={{ fontFamily: d3roFontMono, fontSize: '11px', color: d3roPalette.text.dimLabel }}>
|
|
{t('common.loading')}...
|
|
</Box>
|
|
) : summary ? (
|
|
<Box>
|
|
<Box
|
|
sx={{
|
|
fontFamily: d3roFontSans,
|
|
fontSize: '13px',
|
|
color: d3roPalette.text.primary,
|
|
lineHeight: 1.6,
|
|
whiteSpace: 'pre-wrap',
|
|
}}
|
|
>
|
|
{summary.summaryText}
|
|
</Box>
|
|
</Box>
|
|
) : (
|
|
<Box sx={{ fontFamily: d3roFontMono, fontSize: '11px', color: d3roPalette.text.inactive }}>
|
|
{entry.summaryText || t('meetingSummary.empty')}
|
|
</Box>
|
|
)}
|
|
</Box>
|
|
</Collapse>
|
|
</Box>
|
|
</Box>
|
|
</MetalCard>
|
|
)
|
|
}
|