fix(history): tell users a memo tag is too long instead of offering a retry that always fails
Tags over 80 characters now show a length notice, and adding a tag that already exists in another case just closes the input, rather than both landing on a '#tag · retry' badge that repeats the same rejection.
This commit is contained in:
parent
90c96c6f80
commit
1b39afe9ff
5 changed files with 48 additions and 11 deletions
|
|
@ -11,6 +11,7 @@ import { PhysicalButton, TactileBadge } from '@d3ro/ui/components/ds'
|
|||
import { d3roPalette, d3roFocusRing, d3roRadius, d3roTransition, typoSx } from '@d3ro/ui/theme'
|
||||
import { useI18n } from '@d3ro/i18n'
|
||||
import type { HistoryEntry, MemoTag } from '@d3ro/core/types'
|
||||
import { MEMO_TAG_MAX_LENGTH } from '@d3ro/core/memo-tag-policy'
|
||||
import { formatDuration } from '../../utils/formatters'
|
||||
import { isImeComposingEvent } from '../../utils/keyboard'
|
||||
import { recordModeLabelKey } from '../../utils/display-labels'
|
||||
|
|
@ -38,7 +39,8 @@ const browserHistoryAudioPort: HistoryAudioPort = {
|
|||
}
|
||||
|
||||
interface TagFailure {
|
||||
kind: 'add' | 'remove'
|
||||
/** too-long 은 다시 시도해도 같으니 재시도 대신 안내만 한다. */
|
||||
kind: 'add' | 'remove' | 'too-long'
|
||||
tag: string
|
||||
}
|
||||
|
||||
|
|
@ -312,8 +314,16 @@ function RecordDetail({
|
|||
setTagFailure({ kind: 'add', tag: outcome.tag })
|
||||
return
|
||||
}
|
||||
if (outcome.status === 'too-long') {
|
||||
setTagFailure({ kind: 'too-long', tag: outcome.tag })
|
||||
return
|
||||
}
|
||||
setTagFailure(null)
|
||||
setTags((prev) => [...prev.filter((tg) => tg.tag !== outcome.tag.tag), outcome.tag])
|
||||
// 이미 붙어 있는 태그(대소문자만 다름)면 목록은 그대로 두고 입력만 닫는다.
|
||||
if (outcome.status === 'added') {
|
||||
const added = outcome.tag
|
||||
setTags((prev) => [...prev.filter((tg) => tg.tag !== added.tag), added])
|
||||
}
|
||||
setTagInput('')
|
||||
setShowTagInput(false)
|
||||
onTagsChanged?.()
|
||||
|
|
@ -334,7 +344,7 @@ function RecordDetail({
|
|||
)
|
||||
|
||||
const handleRetryTag = useCallback(() => {
|
||||
if (!tagFailure) return
|
||||
if (!tagFailure || tagFailure.kind === 'too-long') return
|
||||
if (tagFailure.kind === 'remove') {
|
||||
void handleRemoveTag(tagFailure.tag)
|
||||
return
|
||||
|
|
@ -354,7 +364,7 @@ function RecordDetail({
|
|||
e.stopPropagation()
|
||||
setShowTagInput(false)
|
||||
setTagInput('')
|
||||
setTagFailure((prev) => (prev?.kind === 'add' ? null : prev))
|
||||
setTagFailure((prev) => (prev?.kind === 'add' || prev?.kind === 'too-long' ? null : prev))
|
||||
}
|
||||
},
|
||||
[handleAddTag],
|
||||
|
|
@ -484,7 +494,7 @@ function RecordDetail({
|
|||
value={tagInput}
|
||||
onChange={(e) => {
|
||||
setTagInput(e.target.value)
|
||||
if (tagFailure?.kind === 'add') setTagFailure(null)
|
||||
if (tagFailure?.kind === 'add' || tagFailure?.kind === 'too-long') setTagFailure(null)
|
||||
}}
|
||||
onKeyDown={handleTagKeyDown}
|
||||
onBlur={() => {
|
||||
|
|
@ -492,7 +502,7 @@ function RecordDetail({
|
|||
}}
|
||||
autoFocus
|
||||
placeholder={t('memo.tagPlaceholder')}
|
||||
inputProps={{ 'aria-label': t('memo.addTag'), 'aria-invalid': tagFailure?.kind === 'add' }}
|
||||
inputProps={{ 'aria-label': t('memo.addTag'), 'aria-invalid': tagFailure?.kind === 'add' || tagFailure?.kind === 'too-long' }}
|
||||
sx={{
|
||||
...typoSx('small'),
|
||||
height: 24,
|
||||
|
|
@ -500,13 +510,18 @@ function RecordDetail({
|
|||
minWidth: 160,
|
||||
color: d3roPalette.text.primary,
|
||||
bgcolor: d3roPalette.bg.input,
|
||||
border: `1px solid ${tagFailure?.kind === 'add' ? d3roPalette.status.danger : d3roPalette.accent.main}`,
|
||||
border: `1px solid ${tagFailure?.kind === 'add' || tagFailure?.kind === 'too-long' ? d3roPalette.status.danger : d3roPalette.accent.main}`,
|
||||
borderRadius: d3roRadius.small,
|
||||
'& input::placeholder': { color: d3roPalette.text.tertiary, opacity: 1 },
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{tagFailure && (
|
||||
{tagFailure?.kind === 'too-long' && (
|
||||
<TactileBadge tone="error" role="alert">
|
||||
{t('memo.tagTooLong', { max: MEMO_TAG_MAX_LENGTH })}
|
||||
</TactileBadge>
|
||||
)}
|
||||
{tagFailure && tagFailure.kind !== 'too-long' && (
|
||||
<TactileBadge tone="error" role="alert" onClick={handleRetryTag} sx={{ cursor: 'pointer' }}>
|
||||
{`#${tagFailure.tag} · ${t('common.retry')}`}
|
||||
</TactileBadge>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@
|
|||
// 렌더러 전역(window.electronAPI, URL, Audio)에 직접 닿지 않고 포트를 주입받아
|
||||
// 노드 테스트에서 그대로 검증할 수 있다. 어댑터는 컴포넌트(구성 루트)가 만든다.
|
||||
|
||||
import type { IPCResult } from '@d3ro/core/errors'
|
||||
import { ErrorCode, type IPCResult } from '@d3ro/core/errors'
|
||||
import { validateMemoTag } from '@d3ro/core/memo-tag-policy'
|
||||
import type {
|
||||
AddTagParams,
|
||||
GetTagsParams,
|
||||
|
|
@ -25,6 +26,8 @@ export interface MemoTagPort {
|
|||
export type AddEntryTagOutcome =
|
||||
| { status: 'empty' }
|
||||
| { status: 'added'; tag: MemoTag }
|
||||
| { status: 'too-long'; tag: string }
|
||||
| { status: 'duplicate'; tag: string }
|
||||
| { status: 'failed'; tag: string }
|
||||
|
||||
/** 항목의 태그를 불러온다. 실패하면 null — 호출자가 기존 목록을 유지한다. */
|
||||
|
|
@ -45,9 +48,13 @@ export async function addEntryTag(
|
|||
): Promise<AddEntryTagOutcome> {
|
||||
const tag = rawTag.trim()
|
||||
if (!tag) return { status: 'empty' }
|
||||
// 다시 시도해도 똑같이 거절될 입력은 '재시도'로 보여 주지 않는다.
|
||||
if (validateMemoTag(tag) === 'too-long') return { status: 'too-long', tag }
|
||||
try {
|
||||
const result = await port.addTag({ historyId, tag })
|
||||
return result.success ? { status: 'added', tag: result.data } : { status: 'failed', tag }
|
||||
if (result.success) return { status: 'added', tag: result.data }
|
||||
if (result.error.code === ErrorCode.MemoTagDuplicate) return { status: 'duplicate', tag }
|
||||
return { status: 'failed', tag }
|
||||
} catch {
|
||||
return { status: 'failed', tag }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue