feat(release): prepare 1.1.0 candidate
This commit is contained in:
parent
5a34f66981
commit
5205dcdfa9
736 changed files with 115667 additions and 12203 deletions
340
apps/web/src/app/(app)/history/[id]/page.tsx
Normal file
340
apps/web/src/app/(app)/history/[id]/page.tsx
Normal file
|
|
@ -0,0 +1,340 @@
|
|||
'use client'
|
||||
|
||||
import Link from 'next/link'
|
||||
import { useParams, useRouter } from 'next/navigation'
|
||||
import React, { useCallback, useEffect, useState } from 'react'
|
||||
import {
|
||||
Alert,
|
||||
Box,
|
||||
Button,
|
||||
CircularProgress,
|
||||
IconButton,
|
||||
Stack,
|
||||
TextField,
|
||||
Tooltip,
|
||||
Typography
|
||||
} from '@mui/material'
|
||||
import { ArrowLeft, Check, Copy, RefreshCw, Save, Star, Trash2 } from 'lucide-react'
|
||||
import type { D3roSupabaseClient, HistoryEntry } from '@d3ro/api-client'
|
||||
import { MetalCard, PhosphorText } from '@d3ro/ui/components/ds'
|
||||
import { d3roFontMono, d3roPalette } from '@d3ro/ui/theme'
|
||||
import { getSupabaseBrowserClient } from '@/lib/supabase-browser'
|
||||
import {
|
||||
deleteHistoryEntryRevisionSafe,
|
||||
getHistoryEntry,
|
||||
HistoryClientError,
|
||||
updateHistoryEntryRevisionSafe
|
||||
} from '@/lib/history-client'
|
||||
|
||||
function asApiClient(): D3roSupabaseClient {
|
||||
return getSupabaseBrowserClient() as unknown as D3roSupabaseClient
|
||||
}
|
||||
|
||||
async function requireCurrentUser(client: D3roSupabaseClient): Promise<string> {
|
||||
const { data, error } = await client.auth.getUser()
|
||||
if (error || !data.user) {
|
||||
throw new HistoryClientError('auth', error?.message ?? 'Authenticated session is required')
|
||||
}
|
||||
return data.user.id
|
||||
}
|
||||
|
||||
function historyMessage(error: unknown): string {
|
||||
if (error instanceof HistoryClientError) {
|
||||
if (error.code === 'auth') return '세션이 만료되었습니다. 다시 로그인해 주세요.'
|
||||
if (error.code === 'not-found') return '이 전사 기록을 찾을 수 없습니다.'
|
||||
if (error.code === 'conflict') return '다른 기기에서 변경되었습니다. 최신 기록을 다시 불러와 주세요.'
|
||||
if (error.code === 'network') return '네트워크 연결을 확인한 뒤 다시 시도해 주세요.'
|
||||
}
|
||||
return '전사 기록을 처리하지 못했습니다. 잠시 후 다시 시도해 주세요.'
|
||||
}
|
||||
|
||||
export default function HistoryDetailPage(): React.ReactElement {
|
||||
const params = useParams<{ id: string }>()
|
||||
const router = useRouter()
|
||||
const entryId = params.id
|
||||
const [entry, setEntry] = useState<HistoryEntry | null>(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [saving, setSaving] = useState(false)
|
||||
const [deleting, setDeleting] = useState(false)
|
||||
const [editing, setEditing] = useState(false)
|
||||
const [copied, setCopied] = useState(false)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [title, setTitle] = useState('')
|
||||
const [originalText, setOriginalText] = useState('')
|
||||
const [polishedText, setPolishedText] = useState('')
|
||||
|
||||
const applyEntry = (next: HistoryEntry): void => {
|
||||
setEntry(next)
|
||||
setTitle(next.title ?? '')
|
||||
setOriginalText(next.original_text)
|
||||
setPolishedText(next.polished_text ?? '')
|
||||
}
|
||||
|
||||
const loadEntry = useCallback(async (): Promise<void> => {
|
||||
setLoading(true)
|
||||
setError(null)
|
||||
try {
|
||||
const client = asApiClient()
|
||||
const userId = await requireCurrentUser(client)
|
||||
applyEntry(await getHistoryEntry(client, userId, entryId))
|
||||
} catch (requestError) {
|
||||
setEntry(null)
|
||||
setError(historyMessage(requestError))
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [entryId])
|
||||
|
||||
useEffect(() => {
|
||||
void loadEntry()
|
||||
}, [loadEntry])
|
||||
|
||||
const cancelEdit = (): void => {
|
||||
if (!entry) return
|
||||
setTitle(entry.title ?? '')
|
||||
setOriginalText(entry.original_text)
|
||||
setPolishedText(entry.polished_text ?? '')
|
||||
setEditing(false)
|
||||
setError(null)
|
||||
}
|
||||
|
||||
const saveEntry = async (): Promise<void> => {
|
||||
if (!entry || saving) return
|
||||
if (originalText.trim().length === 0) {
|
||||
setError('원본 전사는 비워 둘 수 없습니다.')
|
||||
return
|
||||
}
|
||||
|
||||
setSaving(true)
|
||||
setError(null)
|
||||
try {
|
||||
const client = asApiClient()
|
||||
const userId = await requireCurrentUser(client)
|
||||
const updated = await updateHistoryEntryRevisionSafe(
|
||||
client,
|
||||
userId,
|
||||
entry.id,
|
||||
entry.revision,
|
||||
{
|
||||
title: title.trim() || null,
|
||||
original_text: originalText.trim(),
|
||||
polished_text: polishedText.trim() || null
|
||||
}
|
||||
)
|
||||
applyEntry(updated)
|
||||
setEditing(false)
|
||||
} catch (requestError) {
|
||||
setError(historyMessage(requestError))
|
||||
} finally {
|
||||
setSaving(false)
|
||||
}
|
||||
}
|
||||
|
||||
const toggleFavorite = async (): Promise<void> => {
|
||||
if (!entry || saving) return
|
||||
const previous = entry
|
||||
setSaving(true)
|
||||
setError(null)
|
||||
setEntry({ ...previous, is_favorite: !previous.is_favorite, revision: previous.revision + 1 })
|
||||
|
||||
try {
|
||||
const client = asApiClient()
|
||||
const userId = await requireCurrentUser(client)
|
||||
applyEntry(await updateHistoryEntryRevisionSafe(
|
||||
client,
|
||||
userId,
|
||||
previous.id,
|
||||
previous.revision,
|
||||
{ is_favorite: !previous.is_favorite }
|
||||
))
|
||||
} catch (requestError) {
|
||||
applyEntry(previous)
|
||||
setError(historyMessage(requestError))
|
||||
} finally {
|
||||
setSaving(false)
|
||||
}
|
||||
}
|
||||
|
||||
const deleteEntry = async (): Promise<void> => {
|
||||
if (!entry || deleting) return
|
||||
if (!window.confirm('이 전사 기록을 영구 삭제할까요?')) return
|
||||
|
||||
setDeleting(true)
|
||||
setError(null)
|
||||
try {
|
||||
const client = asApiClient()
|
||||
const userId = await requireCurrentUser(client)
|
||||
await deleteHistoryEntryRevisionSafe(client, userId, entry.id, entry.revision)
|
||||
router.push('/history')
|
||||
router.refresh()
|
||||
} catch (requestError) {
|
||||
setError(historyMessage(requestError))
|
||||
setDeleting(false)
|
||||
}
|
||||
}
|
||||
|
||||
const copyTranscript = async (): Promise<void> => {
|
||||
if (!entry) return
|
||||
try {
|
||||
await navigator.clipboard.writeText(entry.polished_text ?? entry.original_text)
|
||||
setCopied(true)
|
||||
window.setTimeout(() => setCopied(false), 2000)
|
||||
} catch {
|
||||
setError('클립보드에 복사하지 못했습니다. 브라우저 권한을 확인해 주세요.')
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Box sx={{ maxWidth: 920, mx: 'auto', p: { xs: 2.5, md: 4 }, pb: 10 }}>
|
||||
<Button component={Link} href="/history" color="inherit" startIcon={<ArrowLeft size={16} />} sx={{ mb: 3 }}>
|
||||
히스토리로 돌아가기
|
||||
</Button>
|
||||
|
||||
{loading ? (
|
||||
<Box role="status" sx={{ py: 10, display: 'flex', justifyContent: 'center' }}>
|
||||
<CircularProgress aria-label="전사 기록 불러오는 중" />
|
||||
</Box>
|
||||
) : entry === null ? (
|
||||
<MetalCard sx={{ p: 5, textAlign: 'center' }}>
|
||||
<Alert severity="error" sx={{ mb: 3 }}>{error ?? '전사 기록을 불러오지 못했습니다.'}</Alert>
|
||||
<Button variant="outlined" startIcon={<RefreshCw size={16} />} onClick={() => void loadEntry()}>
|
||||
다시 시도
|
||||
</Button>
|
||||
</MetalCard>
|
||||
) : (
|
||||
<Stack spacing={3}>
|
||||
<Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', gap: 2 }}>
|
||||
<Box>
|
||||
<PhosphorText variant="title">TRANSCRIPTION DETAIL</PhosphorText>
|
||||
<Typography sx={{ mt: 1, color: d3roPalette.text.muted, fontFamily: d3roFontMono, fontSize: 12 }}>
|
||||
{new Date(entry.created_at).toLocaleString('ko-KR')} · REV {entry.revision}
|
||||
</Typography>
|
||||
</Box>
|
||||
<Box sx={{ display: 'flex', gap: 0.5 }}>
|
||||
<Tooltip title={entry.is_favorite ? '즐겨찾기 해제' : '즐겨찾기'}>
|
||||
<span>
|
||||
<IconButton aria-label={entry.is_favorite ? '즐겨찾기 해제' : '즐겨찾기'} disabled={saving || editing} onClick={() => void toggleFavorite()} sx={{ color: entry.is_favorite ? '#ffb000' : 'var(--d3-text-label)' }}>
|
||||
<Star size={19} fill={entry.is_favorite ? 'currentColor' : 'none'} />
|
||||
</IconButton>
|
||||
</span>
|
||||
</Tooltip>
|
||||
<Tooltip title={copied ? '복사됨!' : '전사 복사'}>
|
||||
<IconButton aria-label="전사 복사" onClick={() => void copyTranscript()} sx={{ color: copied ? 'var(--d3-tag-green)' : 'var(--d3-text-label)' }}>
|
||||
{copied ? <Check size={19} /> : <Copy size={19} />}
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
{error && (
|
||||
<Alert
|
||||
severity="error"
|
||||
action={<Button color="inherit" size="small" onClick={() => void loadEntry()}>최신 내용 불러오기</Button>}
|
||||
>
|
||||
{error}
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
<MetalCard sx={{ p: { xs: 2.5, md: 4 } }}>
|
||||
<Stack spacing={3}>
|
||||
<HistoryField label="제목">
|
||||
{editing ? (
|
||||
<TextField fullWidth value={title} onChange={(event) => setTitle(event.target.value)} inputProps={{ maxLength: 160 }} />
|
||||
) : (
|
||||
<Typography sx={{ color: d3roPalette.text.primary }}>{entry.title ?? '제목 없음'}</Typography>
|
||||
)}
|
||||
</HistoryField>
|
||||
|
||||
<HistoryField label="원본 전사">
|
||||
{editing ? (
|
||||
<TextField fullWidth multiline minRows={8} value={originalText} onChange={(event) => setOriginalText(event.target.value)} />
|
||||
) : (
|
||||
<Typography sx={{ color: d3roPalette.text.primary, whiteSpace: 'pre-wrap', overflowWrap: 'anywhere', lineHeight: 1.7 }}>{entry.original_text}</Typography>
|
||||
)}
|
||||
</HistoryField>
|
||||
|
||||
<HistoryField label="다듬은 전사">
|
||||
{editing ? (
|
||||
<TextField fullWidth multiline minRows={8} value={polishedText} onChange={(event) => setPolishedText(event.target.value)} />
|
||||
) : (
|
||||
<Typography sx={{ color: entry.polished_text ? d3roPalette.text.primary : d3roPalette.text.muted, whiteSpace: 'pre-wrap', overflowWrap: 'anywhere', lineHeight: 1.7 }}>
|
||||
{entry.polished_text ?? '다듬은 전사가 없습니다.'}
|
||||
</Typography>
|
||||
)}
|
||||
</HistoryField>
|
||||
|
||||
<Box sx={{ display: 'flex', justifyContent: 'flex-end', gap: 1 }}>
|
||||
{editing ? (
|
||||
<>
|
||||
<Button color="inherit" disabled={saving} onClick={cancelEdit}>취소</Button>
|
||||
<Button variant="contained" disabled={saving} startIcon={saving ? <CircularProgress size={15} /> : <Save size={16} />} onClick={() => void saveEntry()}>
|
||||
저장
|
||||
</Button>
|
||||
</>
|
||||
) : (
|
||||
<Button variant="outlined" onClick={() => setEditing(true)}>내용 편집</Button>
|
||||
)}
|
||||
</Box>
|
||||
</Stack>
|
||||
</MetalCard>
|
||||
|
||||
{entry.summary_text && (
|
||||
<MetalCard sx={{ p: 3 }}>
|
||||
<PhosphorText variant="heading" sx={{ mb: 2 }}>SUMMARY</PhosphorText>
|
||||
<Typography sx={{ color: d3roPalette.text.primary, whiteSpace: 'pre-wrap', lineHeight: 1.7 }}>{entry.summary_text}</Typography>
|
||||
</MetalCard>
|
||||
)}
|
||||
|
||||
<MetalCard sx={{ p: 3 }}>
|
||||
<PhosphorText variant="heading" sx={{ mb: 2 }}>METADATA</PhosphorText>
|
||||
<Box sx={{ display: 'grid', gridTemplateColumns: { xs: '1fr', sm: 'repeat(2, 1fr)' }, gap: 1.5 }}>
|
||||
<Metadata label="모드" value={entry.mode} />
|
||||
<Metadata label="상태" value={entry.status} />
|
||||
<Metadata label="언어" value={entry.detected_language ?? '—'} />
|
||||
<Metadata label="길이" value={formatDuration(entry.duration)} />
|
||||
<Metadata label="단어" value={`${entry.word_count}`} />
|
||||
<Metadata label="STT 모델" value={entry.stt_model ?? '—'} />
|
||||
<Metadata label="LLM 모델" value={entry.llm_model ?? '—'} />
|
||||
<Metadata label="수정 시각" value={new Date(entry.updated_at).toLocaleString('ko-KR')} />
|
||||
</Box>
|
||||
</MetalCard>
|
||||
|
||||
<Box sx={{ display: 'flex', justifyContent: 'flex-end' }}>
|
||||
<Button color="error" variant="outlined" disabled={deleting} startIcon={deleting ? <CircularProgress size={15} /> : <Trash2 size={16} />} onClick={() => void deleteEntry()}>
|
||||
기록 삭제
|
||||
</Button>
|
||||
</Box>
|
||||
</Stack>
|
||||
)}
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
|
||||
function HistoryField({ label, children }: { label: string; children: React.ReactNode }): React.ReactElement {
|
||||
return (
|
||||
<Box>
|
||||
<Typography component="h2" sx={{ mb: 1, color: d3roPalette.text.muted, fontFamily: d3roFontMono, fontSize: 11, letterSpacing: 1.5 }}>
|
||||
{label.toUpperCase()}
|
||||
</Typography>
|
||||
{children}
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
|
||||
function Metadata({ label, value }: { label: string; value: string }): React.ReactElement {
|
||||
return (
|
||||
<Box sx={{ p: 1.5, bgcolor: d3roPalette.bg.inset, borderRadius: 1 }}>
|
||||
<Typography sx={{ color: d3roPalette.text.muted, fontFamily: d3roFontMono, fontSize: 10 }}>{label}</Typography>
|
||||
<Typography sx={{ mt: 0.5, color: d3roPalette.text.primary, fontSize: 13, overflowWrap: 'anywhere' }}>{value}</Typography>
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
|
||||
function formatDuration(durationSeconds: number): string {
|
||||
const totalSeconds = Number.isFinite(durationSeconds) ? Math.max(0, Math.floor(durationSeconds)) : 0
|
||||
const hours = Math.floor(totalSeconds / 3600)
|
||||
const minutes = Math.floor((totalSeconds % 3600) / 60)
|
||||
const seconds = totalSeconds % 60
|
||||
if (hours > 0) return `${hours}:${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`
|
||||
return `${minutes}:${String(seconds).padStart(2, '0')}`
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue