v1.4.0: 발화 우클릭 삭제(잡음이라 삭제 · 그냥 삭제) · 잡음 문장 배우기 · 새 발화/재생 시작 알림 기본 끄기

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-16 20:30:33 +09:00
parent 8047a2e948
commit 3115337706
21 changed files with 670 additions and 13 deletions

View File

@@ -3,13 +3,16 @@ import type { UtteranceInfo, UtteranceItem } from '@gvr/shared';
import { api, ApiError } from '../lib/api';
import { fmtWhen } from '../lib/format';
import { player } from '../store/player';
import { useData } from '../store/app';
import { useAuth, useData, useLive } from '../store/app';
import { IClose, IDownload, IPlay } from './Icons';
/** 발화 우클릭 메뉴 · 자세한 정보 창 (앱에 하나만 띄운다) */
type MenuState = { item: UtteranceItem; x: number; y: number } | null;
let menu: MenuState = null;
let infoFor: UtteranceItem | null = null;
let deleteFor: UtteranceItem | null = null;
/** 이 화면에서 지운 발화 (다른 사람이 지운 것도 실시간으로). 목록마다 따로 고치지 않고 줄이 스스로 숨는다 */
const deleted = new Set<string>();
const subs = new Set<() => void>();
const notify = () => subs.forEach((f) => f());
const subscribe = (f: () => void) => {
@@ -36,6 +39,25 @@ function closeInfo(): void {
infoFor = null;
notify();
}
function openDelete(item: UtteranceItem): void {
menu = null;
deleteFor = item;
notify();
}
function closeDelete(): void {
deleteFor = null;
notify();
}
function markDeleted(id: string): void {
if (deleted.has(id)) return;
deleted.add(id);
if (player.state.item?.id === id) player.stop();
notify();
}
/** 지운 발화인가 (줄을 숨긴다) */
export function useDeleted(id: string): boolean {
return useSyncExternalStore(subscribe, () => deleted.has(id));
}
/** 녹음 원본(.ogg)을 내려받는다. 게임 PC → 사이트 서버 중계로 받은 파일을 그대로 저장 */
export async function downloadAudio(item: UtteranceItem, fileName?: string | null): Promise<void> {
@@ -59,7 +81,16 @@ const copy = (text: string) => navigator.clipboard?.writeText(text).catch(() =>
export function UttMenuHost() {
const m = useSyncExternalStore(subscribe, () => menu);
const info = useSyncExternalStore(subscribe, () => infoFor);
const del = useSyncExternalStore(subscribe, () => deleteFor);
const [err, setErr] = useState<string | null>(null);
const [okMsg, setOkMsg] = useState<string | null>(null);
const { auth } = useAuth();
// 지우기: 관리자나 말한 사람만 (게임 PC 도 한 번 더 확인한다)
const canDelete = (it: UtteranceItem) => auth.status === 'ok' && (!!auth.me.canViewLogs || auth.me.user.id === it.userId);
useLive((e) => {
if (e.type === 'utterance.deleted') markDeleted(e.data.id);
});
useEffect(() => {
if (!m) return;
@@ -82,6 +113,11 @@ export function UttMenuHost() {
const t = setTimeout(() => setErr(null), 4000);
return () => clearTimeout(t);
}, [err]);
useEffect(() => {
if (!okMsg) return;
const t = setTimeout(() => setOkMsg(null), 4000);
return () => clearTimeout(t);
}, [okMsg]);
const act = (fn: () => unknown) => (e: React.PointerEvent | React.MouseEvent) => {
e.stopPropagation();
@@ -95,7 +131,7 @@ export function UttMenuHost() {
<div
className="ctx-menu"
role="menu"
style={{ left: Math.min(m.x, window.innerWidth - 230), top: Math.min(m.y, window.innerHeight - 190) }}
style={{ left: Math.min(m.x, window.innerWidth - 230), top: Math.min(m.y, window.innerHeight - 240) }}
onPointerDown={(e) => e.stopPropagation()}
onContextMenu={(e) => e.preventDefault()}
>
@@ -111,10 +147,32 @@ export function UttMenuHost() {
<button role="menuitem" disabled={!m.item.text} onClick={act(() => copy(m.item.text ?? ''))}>
<span className="ctx-ic">⧉</span> 내용 복사
</button>
<div className="ctx-sep" />
<button
role="menuitem"
className="danger"
disabled={!canDelete(m.item)}
title={canDelete(m.item) ? undefined : '관리자나 말한 사람만 지울 수 있습니다'}
onClick={act(() => openDelete(m.item))}
>
<span className="ctx-ic">🗑</span> 삭제…
</button>
</div>
)}
{info && <InfoDialog item={info} onError={setErr} />}
{del && (
<DeleteDialog
key={del.id}
item={del}
onDone={(learned) => {
markDeleted(del.id);
closeDelete();
setOkMsg(learned ? `삭제했습니다. 앞으로 "${learned.length > 40 ? learned.slice(0, 40) + '…' : learned}" 는 잡음으로 거릅니다` : '삭제했습니다');
}}
/>
)}
{err && <div className="ctx-toast">{err}</div>}
{okMsg && !err && <div className="ctx-toast ok">{okMsg}</div>}
</>
);
}
@@ -218,3 +276,73 @@ function InfoDialog({ item, onError }: { item: UtteranceItem; onError: (m: strin
</div>
);
}
/** 삭제 확인: 잡음이라 삭제(같은 문장을 다음부터 잡음으로 거름) · 그냥 삭제 · 취소 */
function DeleteDialog({ item, onDone }: { item: UtteranceItem; onDone: (learned: string | null) => void }) {
const { userById } = useData();
const [busy, setBusy] = useState<'noise' | 'plain' | null>(null);
const [failed, setFailed] = useState<string | null>(null);
const text = item.text?.trim() || null;
useEffect(() => {
const onKey = (e: KeyboardEvent) => e.key === 'Escape' && !busy && closeDelete();
window.addEventListener('keydown', onKey);
return () => window.removeEventListener('keydown', onKey);
}, [busy]);
const run = async (noise: boolean) => {
setBusy(noise ? 'noise' : 'plain');
setFailed(null);
try {
const r = await api.deleteUtterance(item.id, noise);
onDone(r.learned);
} catch (e) {
setBusy(null);
if (e instanceof ApiError && e.status === 404 && e.code === 'not_found') return onDone(null); // 이미 지워짐
setFailed(
e instanceof ApiError && e.status === 404
? '게임 PC 의 겜녹이가 예전 버전입니다. v1.4.0 이상으로 업데이트하면 지울 수 있습니다.'
: e instanceof ApiError && e.status === 403
? '관리자나 말한 사람만 지울 수 있습니다.'
: e instanceof ApiError && e.status === 503
? '게임 PC 가 꺼져 있어 지우지 못했습니다.'
: '지우지 못했습니다. 잠시 뒤 다시 시도해 주세요.',
);
}
};
return (
<div className="ctx-dim" onPointerDown={() => !busy && closeDelete()}>
<div className="ctx-dialog del-dialog" role="dialog" aria-label="발화 삭제" onPointerDown={(e) => e.stopPropagation()}>
<div className="ctx-head">
<b>발화 삭제</b>
<button className="icon-btn" onClick={closeDelete} disabled={!!busy} aria-label="닫기">
<IClose width={16} height={16} />
</button>
</div>
<div className="del-quote">
<span className="dim">{userById(item.userId)?.name ?? '알 수 없음'} · {fmtWhen(item.ts)}</span>
<p>{text ?? '(인식된 글 없음)'}</p>
</div>
<p className="del-help">
글과 음성 파일을 게임 PC 에서 지웁니다. 되돌릴 수 없습니다.
<br />
<b>잡음이라 삭제</b>를 고르면 이 문장을 잡음으로 배워서, 다음에 같은 문장이 인식되면 자동으로 잡음 처리합니다 (띄어쓰기 · 문장부호는 무시하고, 긴 문장은 한두 글자 달라도 같은 문장으로 봅니다).
배운 문장은 사전 화면에서 지울 수 있습니다.
</p>
{failed && <p className="del-err">{failed}</p>}
<div className="ctx-foot">
<button className="chip" onClick={closeDelete} disabled={!!busy}>
취소
</button>
<button className="chip danger" onClick={() => void run(false)} disabled={!!busy}>
{busy === 'plain' ? '지우는 중…' : '그냥 삭제'}
</button>
<button className="chip danger on" onClick={() => void run(true)} disabled={!!busy || !text} title={text ? undefined : '인식된 글이 없어 배울 문장이 없습니다'}>
{busy === 'noise' ? '지우는 중…' : '잡음이라 삭제'}
</button>
</div>
</div>
</div>
);
}

View File

@@ -7,7 +7,7 @@ import { sfx } from '../lib/sfx';
import { realTip } from '../lib/format';
import { Avatar, TimeCell } from './common';
import { IEdit } from './Icons';
import { openUttMenu } from './UttMenu';
import { openUttMenu, useDeleted } from './UttMenu';
const STATUS: Record<UtteranceItem['status'], [string, string]> = {
realtime: ['실시간', 'st-rt'],
@@ -147,6 +147,7 @@ export const UtteranceRow = memo(function UtteranceRow({ item, variant = 'full',
const playing = usePlayer((s) => active && s.playing);
const [editing, setEditing] = useState(false);
const [st, stCls] = STATUS[item.status];
const gone = useDeleted(item.id);
const click = () => {
if (editing) return;
@@ -183,6 +184,9 @@ export const UtteranceRow = memo(function UtteranceRow({ item, variant = 'full',
</button>
);
// 우클릭으로 지운 발화 (경기 화면 · 유저 화면 등 어느 목록이든 줄이 숨는다)
if (gone) return null;
if (variant === 'compact') {
return (
<div className={`l utt${active ? ' cur' : ''}${item.noise ? ' is-noise' : ''}`} onClick={click} onContextMenu={menu} data-id={item.id}>