M2: 사이트 서버 · 사이트 v1 - gvr.tkrmagid.kr 배포
- site/server: Discord OAuth2 + 봇 토큰 멤버 확인, 세션, 1회용 등록 코드·기기 키 인증, 게임 PC WebSocket 중계(JSON·음성 바이너리), 15초 무응답 잠금, 게임 이미지 캐시, 관리 CLI - site/web: 타임라인·따라 읽기 재생(단어 강조·이어듣기·현장 모드·재생 게인)·필터·검색·실시간·교정, 발로란트/롤 경기 상세, 잠금 화면(관리자 등록 코드), 모바일, 효과음 - deploy/site: Dockerfile·compose·deploy.sh·make-env.sh (.5, 포트 2972) - 앱 코어: 사이트 필터 묶음(킬·라운드)과 유저 필터 규칙 맞춤, hello 에 서버 ID Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
184
site/web/src/components/EventRow.tsx
Normal file
184
site/web/src/components/EventRow.tsx
Normal file
@@ -0,0 +1,184 @@
|
||||
import { memo } from 'react';
|
||||
import { motion } from 'framer-motion';
|
||||
import type { ChatData, EventItem, KillData, ObjectData, PlayerRef, RoundEndData } from '@gvr/shared';
|
||||
import { CharIcon, PName, TimeCell } from './common';
|
||||
import { CHANNEL_KO, MULTI_KO, OBJECT_GLYPH, objectName, roundResultKo } from '../lib/game';
|
||||
import { useReducedMotion } from '../store/settings';
|
||||
import { realTip } from '../lib/format';
|
||||
|
||||
export function KillLine({ d, game, iconSize = 22 }: { d: KillData; game: 'valorant' | 'lol'; iconSize?: number }) {
|
||||
return (
|
||||
<>
|
||||
{d.killer ? (
|
||||
<>
|
||||
<CharIcon c={d.killer.character} size={iconSize} />
|
||||
<PName p={d.killer} />
|
||||
</>
|
||||
) : (
|
||||
<span className="dim">{game === 'lol' ? '처형' : '낙사'}</span>
|
||||
)}
|
||||
{d.weapon?.icon ? <img className="wk" src={d.weapon.icon} alt={d.weapon.name} title={d.weapon.name} /> : d.weapon ? <span className="dim wname">{d.weapon.name}</span> : null}
|
||||
<span className="arrow">▶</span>
|
||||
<CharIcon c={d.victim.character} size={iconSize} />
|
||||
<PName p={d.victim} />
|
||||
{d.headshot && <span className="dim">헤드샷</span>}
|
||||
{d.assists?.length > 0 && game === 'lol' && (
|
||||
<span className="dim">
|
||||
· 어시{' '}
|
||||
{d.assists.map((a: PlayerRef, i: number) => (
|
||||
<span key={i}>
|
||||
{i > 0 && ', '}
|
||||
<PName p={a} strong={false} />
|
||||
</span>
|
||||
))}
|
||||
</span>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export function isAllyDeath(e: EventItem) {
|
||||
const d = e.data as KillData;
|
||||
return e.type === 'kill' && (d.ally === false || (d.ally == null && !!d.victim?.userId));
|
||||
}
|
||||
|
||||
/** 이벤트 내용 (킬 · 채팅 · 오브젝트 · 스파이크 · 멀티킬) */
|
||||
export function EventBody({ e, iconSize = 22 }: { e: EventItem; iconSize?: number }) {
|
||||
switch (e.type) {
|
||||
case 'kill':
|
||||
return (
|
||||
<div className={`ev ${isAllyDeath(e) ? 'death' : 'kill'}`}>
|
||||
<KillLine d={e.data as KillData} game={e.game} iconSize={iconSize} />
|
||||
</div>
|
||||
);
|
||||
case 'multikill':
|
||||
case 'ace': {
|
||||
const d = e.data as { player?: PlayerRef; count?: number };
|
||||
return (
|
||||
<div className="ev kill multi">
|
||||
<CharIcon c={d.player?.character} size={iconSize} />
|
||||
<PName p={d.player} />
|
||||
<span className="kbadge">{e.type === 'ace' ? '에이스' : MULTI_KO[d.count ?? 2] ?? `${d.count}킬`}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
case 'chat': {
|
||||
const d = e.data as ChatData;
|
||||
return (
|
||||
<div className={`ev chat ${e.game}`}>
|
||||
<span aria-hidden>💬</span>
|
||||
<span className={`ctag ch-${d.channel}`}>{CHANNEL_KO[d.channel] ?? d.channel}</span>
|
||||
<PName p={d.sender} />
|
||||
{d.sender.character && <span className="dim">({d.sender.character.name})</span>}
|
||||
<span className="ctext">{d.text}</span>
|
||||
{d.source === 'ocr' && (
|
||||
<span className="ocr" title="게임 화면에서 글자 인식(OCR)으로 읽은 채팅">
|
||||
OCR
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
case 'object': {
|
||||
const d = e.data as ObjectData & { icon?: string | null };
|
||||
const name = objectName(d.object, d.subtype);
|
||||
const destroyed = d.object === 'tower' || d.object === 'inhibitor';
|
||||
return (
|
||||
<div className={`ev obj${d.ally === false ? ' enemy' : ''}`}>
|
||||
{d.icon ? <img className="oi" src={d.icon} alt="" /> : <span aria-hidden>{OBJECT_GLYPH[d.object] ?? '◆'}</span>}
|
||||
{destroyed ? (
|
||||
<span>
|
||||
{d.ally === false ? '우리' : '상대'} <b className="gold">{name}</b> 파괴
|
||||
</span>
|
||||
) : (
|
||||
<span>
|
||||
{d.ally === false ? '상대 팀' : '우리 팀'} <b className="gold">{name}</b> 처치
|
||||
</span>
|
||||
)}
|
||||
{d.killer && (
|
||||
<span className="dim">
|
||||
· <PName p={d.killer} strong={false} />
|
||||
{d.object === 'dragon' || d.object === 'baron' ? ' 강타' : ''}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
case 'spike': {
|
||||
const d = e.data as { action?: string; site?: string; player?: PlayerRef };
|
||||
const act = d.action === 'defuse' ? '해체' : d.action === 'detonate' ? '폭발' : '설치';
|
||||
return (
|
||||
<div className="ev spike">
|
||||
<span className="spike-ic">◆</span> 스파이크 {act}
|
||||
{d.site && <span className="dim">· {d.site} 사이트</span>}
|
||||
{d.player && (
|
||||
<span className="dim">
|
||||
· <PName p={d.player} strong={false} />
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
default:
|
||||
return <div className="ev">{e.type}</div>;
|
||||
}
|
||||
}
|
||||
|
||||
export const SEPARATOR_TYPES = new Set(['round_end', 'match_start', 'match_end']);
|
||||
|
||||
/** 라운드 종료 · 경기 시작/종료 구분선 (와이프 연출) */
|
||||
export const SeparatorRow = memo(function SeparatorRow({ e }: { e: EventItem }) {
|
||||
const reduce = useReducedMotion();
|
||||
let pill = '';
|
||||
let text = '';
|
||||
let score = '';
|
||||
let cls = '';
|
||||
if (e.type === 'round_end') {
|
||||
const d = e.data as RoundEndData & { winner?: string };
|
||||
const win = d.win ?? d.winner === 'ally';
|
||||
pill = `R${d.round}`;
|
||||
text = `${win ? '승리' : '패배'} · ${roundResultKo(d.result)}`;
|
||||
score = `${d.score.ally} : ${d.score.enemy}`;
|
||||
cls = win ? 'win' : 'loss';
|
||||
} else if (e.type === 'match_start') {
|
||||
const d = e.data as { map?: string; mode?: string };
|
||||
pill = '경기 시작';
|
||||
text = [d.map, d.mode].filter(Boolean).join(' · ');
|
||||
cls = 'start';
|
||||
} else {
|
||||
const d = e.data as { win?: boolean; score?: { ally: number; enemy: number } };
|
||||
pill = '경기 종료';
|
||||
text = d.win == null ? '' : d.win ? '승리' : '패배';
|
||||
score = d.score ? `${d.score.ally} : ${d.score.enemy}` : '';
|
||||
cls = d.win ? 'win' : 'loss';
|
||||
}
|
||||
return (
|
||||
<div className={`sep ${cls} g-${e.game}`} data-tip={realTip(e.ts)}>
|
||||
<span className="pill">{pill}</span>
|
||||
<span className="sep-text">{text}</span>
|
||||
{score && <span className="score mono">{score}</span>}
|
||||
<span className="sep-time mono">{e.time.primary}</span>
|
||||
<span className="sep-line">
|
||||
<motion.i
|
||||
initial={reduce ? false : { scaleX: 0 }}
|
||||
whileInView={{ scaleX: 1 }}
|
||||
viewport={{ once: true }}
|
||||
transition={{ duration: 0.7, ease: [0.2, 0.7, 0.2, 1] }}
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
export const EventRow = memo(function EventRow({ e }: { e: EventItem }) {
|
||||
if (SEPARATOR_TYPES.has(e.type)) return <SeparatorRow e={e} />;
|
||||
return (
|
||||
<div className={`it evrow t-${e.type}`} data-id={e.id}>
|
||||
<TimeCell time={e.time} />
|
||||
<span className="av-spacer" />
|
||||
<div className="body">
|
||||
<EventBody e={e} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
193
site/web/src/components/Header.tsx
Normal file
193
site/web/src/components/Header.tsx
Normal file
@@ -0,0 +1,193 @@
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { NavLink, useLocation, useNavigate, useSearchParams } from 'react-router';
|
||||
import { AnimatePresence, motion } from 'framer-motion';
|
||||
import { useAuth, useData, useStatus } from '../store/app';
|
||||
import { settings, useSettings, type SfxKind } from '../store/settings';
|
||||
import { sfx, SFX_LABEL } from '../lib/sfx';
|
||||
import { resumeAudio } from '../lib/audio';
|
||||
import { Avatar, Brand } from './common';
|
||||
import { IGear, ILogout, ISearch } from './Icons';
|
||||
|
||||
function SettingsPopover({ onClose }: { onClose: () => void }) {
|
||||
const s = useSettings();
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
useEffect(() => {
|
||||
const down = (e: PointerEvent) => {
|
||||
if (ref.current && !ref.current.contains(e.target as Node) && !(e.target as HTMLElement).closest('.gear-btn')) onClose();
|
||||
};
|
||||
const key = (e: KeyboardEvent) => e.key === 'Escape' && onClose();
|
||||
document.addEventListener('pointerdown', down);
|
||||
document.addEventListener('keydown', key);
|
||||
return () => {
|
||||
document.removeEventListener('pointerdown', down);
|
||||
document.removeEventListener('keydown', key);
|
||||
};
|
||||
}, [onClose]);
|
||||
return (
|
||||
<motion.div
|
||||
ref={ref}
|
||||
className="popover"
|
||||
initial={{ opacity: 0, y: -6, scale: 0.98 }}
|
||||
animate={{ opacity: 1, y: 0, scale: 1 }}
|
||||
exit={{ opacity: 0, y: -6, scale: 0.98 }}
|
||||
transition={{ duration: 0.16 }}
|
||||
role="dialog"
|
||||
aria-label="설정"
|
||||
>
|
||||
<h5>효과음</h5>
|
||||
<label className="row">
|
||||
<span>전체 볼륨</span>
|
||||
<input
|
||||
type="range"
|
||||
min={0}
|
||||
max={1}
|
||||
step={0.05}
|
||||
value={s.volume}
|
||||
onChange={(e) => settings.set({ volume: Number(e.target.value) })}
|
||||
onPointerUp={() => {
|
||||
resumeAudio();
|
||||
sfx('click');
|
||||
}}
|
||||
/>
|
||||
<span className="mono val">{Math.round(s.volume * 100)}</span>
|
||||
</label>
|
||||
{(Object.keys(SFX_LABEL) as SfxKind[]).map((k) => (
|
||||
<label className="row check" key={k}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={s.sfx[k]}
|
||||
onChange={(e) => {
|
||||
settings.set({ sfx: { ...s.sfx, [k]: e.target.checked } });
|
||||
resumeAudio();
|
||||
if (e.target.checked) window.setTimeout(() => sfx(k), 30);
|
||||
}}
|
||||
/>
|
||||
<span>{SFX_LABEL[k]}</span>
|
||||
<button
|
||||
className="mini-btn"
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
resumeAudio();
|
||||
window.setTimeout(() => sfx(k), 30);
|
||||
}}
|
||||
>
|
||||
미리 듣기
|
||||
</button>
|
||||
</label>
|
||||
))}
|
||||
<h5>화면</h5>
|
||||
<label className="row check">
|
||||
<input type="checkbox" checked={s.reduceMotion} onChange={(e) => settings.set({ reduceMotion: e.target.checked })} />
|
||||
<span>모션 줄이기</span>
|
||||
</label>
|
||||
<div className="pop-foot">단축키: Space 재생 · ←/→ 이전·다음 발화 · / 검색 · Esc 닫기</div>
|
||||
</motion.div>
|
||||
);
|
||||
}
|
||||
|
||||
export function SearchBox() {
|
||||
const [params, setParams] = useSearchParams();
|
||||
const loc = useLocation();
|
||||
const nav = useNavigate();
|
||||
const onTimeline = loc.pathname === '/';
|
||||
const urlQ = onTimeline ? params.get('q') ?? '' : '';
|
||||
const [v, setV] = useState(urlQ);
|
||||
useEffect(() => setV(urlQ), [urlQ]);
|
||||
const timer = useRef<number | null>(null);
|
||||
const commit = (q: string) => {
|
||||
if (!onTimeline) {
|
||||
nav(q ? `/?q=${encodeURIComponent(q)}` : '/');
|
||||
return;
|
||||
}
|
||||
const p = new URLSearchParams(params);
|
||||
if (q) p.set('q', q);
|
||||
else p.delete('q');
|
||||
setParams(p, { replace: true });
|
||||
};
|
||||
return (
|
||||
<form
|
||||
className="search"
|
||||
role="search"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
if (timer.current) window.clearTimeout(timer.current);
|
||||
commit(v.trim());
|
||||
}}
|
||||
>
|
||||
<ISearch width={16} height={16} />
|
||||
<input
|
||||
id="gvr-search"
|
||||
value={v}
|
||||
placeholder="대화 내용 검색 (예: 스파이크)"
|
||||
onChange={(e) => {
|
||||
const q = e.target.value;
|
||||
setV(q);
|
||||
if (!onTimeline) return;
|
||||
if (timer.current) window.clearTimeout(timer.current);
|
||||
timer.current = window.setTimeout(() => commit(q.trim()), 350);
|
||||
}}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Escape') (e.target as HTMLInputElement).blur();
|
||||
}}
|
||||
aria-label="대화 내용 검색"
|
||||
/>
|
||||
<kbd>/</kbd>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
export function Header() {
|
||||
const { auth, logout } = useAuth();
|
||||
const { overview } = useData();
|
||||
const { device, locked, conn } = useStatus();
|
||||
const [open, setOpen] = useState(false);
|
||||
const me = auth.status === 'ok' ? auth.me.user : null;
|
||||
const rec = overview?.recording;
|
||||
const nav = [
|
||||
['/', '타임라인'],
|
||||
['/matches', '경기'],
|
||||
['/users', '유저'],
|
||||
] as const;
|
||||
return (
|
||||
<header className="topbar">
|
||||
<NavLink to="/" className="brand-link" aria-label="겜녹이 홈">
|
||||
<Brand />
|
||||
</NavLink>
|
||||
<nav className="nav">
|
||||
{nav.map(([to, label]) => (
|
||||
<NavLink key={to} to={to} end={to === '/'} className={({ isActive }) => `chip${isActive ? ' on' : ''}`} onClick={() => sfx('click')}>
|
||||
{label}
|
||||
</NavLink>
|
||||
))}
|
||||
</nav>
|
||||
<SearchBox />
|
||||
<div className="hdr-right">
|
||||
{rec?.active && !locked && (
|
||||
<div className="rec" title={rec.since ? `녹음 시작 ${new Date(rec.since).toLocaleTimeString('ko-KR', { hour12: false })}` : undefined}>
|
||||
<i /> <span className="rec-txt">녹음 중{rec.channel ? ` · #${rec.channel}` : ''} · {rec.participants.length}명</span>
|
||||
<span className="rec-short">녹음 중</span>
|
||||
</div>
|
||||
)}
|
||||
{device && (
|
||||
<div className={`conn ${locked ? 'off' : conn === 'open' ? 'on' : 'warn'}`} title={conn === 'open' ? '실시간 연결됨' : '실시간 연결 재시도 중'}>
|
||||
<span className="dot" />
|
||||
<span className="conn-txt">{locked ? '게임 PC 연결 해제됨' : conn === 'open' ? '게임 PC 연결됨' : '실시간 재연결 중'}</span>
|
||||
</div>
|
||||
)}
|
||||
<button className="icon-btn gear-btn" onClick={() => setOpen((o) => !o)} aria-label="설정" title="효과음 · 모션 설정">
|
||||
<IGear />
|
||||
</button>
|
||||
<AnimatePresence>{open && <SettingsPopover onClose={() => setOpen(false)} />}</AnimatePresence>
|
||||
{me && (
|
||||
<div className="me">
|
||||
<Avatar name={me.name} src={me.avatar} color="#5865f2" size={26} />
|
||||
<span className="me-nm">{me.name}</span>
|
||||
<button className="icon-btn" onClick={logout} title="로그아웃" aria-label="로그아웃">
|
||||
<ILogout width={16} height={16} />
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
}
|
||||
98
site/web/src/components/Icons.tsx
Normal file
98
site/web/src/components/Icons.tsx
Normal file
@@ -0,0 +1,98 @@
|
||||
import type { SVGProps } from 'react';
|
||||
|
||||
const base = (p: SVGProps<SVGSVGElement>) => ({ width: 18, height: 18, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round' as const, strokeLinejoin: 'round' as const, 'aria-hidden': true, ...p });
|
||||
|
||||
export const IPlay = (p: SVGProps<SVGSVGElement>) => (
|
||||
<svg {...base(p)} fill="currentColor" stroke="none">
|
||||
<path d="M7 4.5v15a1 1 0 0 0 1.5.86l12-7.5a1 1 0 0 0 0-1.72l-12-7.5A1 1 0 0 0 7 4.5z" />
|
||||
</svg>
|
||||
);
|
||||
export const IPause = (p: SVGProps<SVGSVGElement>) => (
|
||||
<svg {...base(p)} fill="currentColor" stroke="none">
|
||||
<rect x="5.5" y="4" width="4.5" height="16" rx="1.2" />
|
||||
<rect x="14" y="4" width="4.5" height="16" rx="1.2" />
|
||||
</svg>
|
||||
);
|
||||
export const IPrev = (p: SVGProps<SVGSVGElement>) => (
|
||||
<svg {...base(p)} fill="currentColor" stroke="none">
|
||||
<rect x="4" y="5" width="2.6" height="14" rx="1" />
|
||||
<path d="M20 5.6v12.8a.9.9 0 0 1-1.38.76L8.8 12.76a.9.9 0 0 1 0-1.52l9.82-6.4A.9.9 0 0 1 20 5.6z" />
|
||||
</svg>
|
||||
);
|
||||
export const INext = (p: SVGProps<SVGSVGElement>) => (
|
||||
<svg {...base(p)} fill="currentColor" stroke="none">
|
||||
<rect x="17.4" y="5" width="2.6" height="14" rx="1" />
|
||||
<path d="M4 5.6v12.8a.9.9 0 0 0 1.38.76l9.82-6.4a.9.9 0 0 0 0-1.52L5.38 4.84A.9.9 0 0 0 4 5.6z" />
|
||||
</svg>
|
||||
);
|
||||
export const IEdit = (p: SVGProps<SVGSVGElement>) => (
|
||||
<svg {...base(p)}>
|
||||
<path d="M12 20h9" />
|
||||
<path d="M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4 12.5-12.5z" />
|
||||
</svg>
|
||||
);
|
||||
export const ISearch = (p: SVGProps<SVGSVGElement>) => (
|
||||
<svg {...base(p)}>
|
||||
<circle cx="11" cy="11" r="7" />
|
||||
<path d="m20 20-3.5-3.5" />
|
||||
</svg>
|
||||
);
|
||||
export const IGear = (p: SVGProps<SVGSVGElement>) => (
|
||||
<svg {...base(p)}>
|
||||
<circle cx="12" cy="12" r="3" />
|
||||
<path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 1 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 1 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 1 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 1 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z" />
|
||||
</svg>
|
||||
);
|
||||
export const ILogout = (p: SVGProps<SVGSVGElement>) => (
|
||||
<svg {...base(p)}>
|
||||
<path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4" />
|
||||
<path d="m16 17 5-5-5-5" />
|
||||
<path d="M21 12H9" />
|
||||
</svg>
|
||||
);
|
||||
export const ILoop = (p: SVGProps<SVGSVGElement>) => (
|
||||
<svg {...base(p)}>
|
||||
<path d="m17 2 4 4-4 4" />
|
||||
<path d="M3 11v-1a4 4 0 0 1 4-4h14" />
|
||||
<path d="m7 22-4-4 4-4" />
|
||||
<path d="M21 13v1a4 4 0 0 1-4 4H3" />
|
||||
</svg>
|
||||
);
|
||||
export const IVolume = (p: SVGProps<SVGSVGElement>) => (
|
||||
<svg {...base(p)}>
|
||||
<path d="M11 5 6 9H2v6h4l5 4V5z" />
|
||||
<path d="M15.5 8.5a5 5 0 0 1 0 7" />
|
||||
<path d="M19 5a10 10 0 0 1 0 14" />
|
||||
</svg>
|
||||
);
|
||||
export const IUsers = (p: SVGProps<SVGSVGElement>) => (
|
||||
<svg {...base(p)}>
|
||||
<path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2" />
|
||||
<circle cx="9" cy="7" r="4" />
|
||||
<path d="M23 21v-2a4 4 0 0 0-3-3.87" />
|
||||
<path d="M16 3.13a4 4 0 0 1 0 7.75" />
|
||||
</svg>
|
||||
);
|
||||
export const IClose = (p: SVGProps<SVGSVGElement>) => (
|
||||
<svg {...base(p)}>
|
||||
<path d="M18 6 6 18M6 6l12 12" />
|
||||
</svg>
|
||||
);
|
||||
export const IWaves = (p: SVGProps<SVGSVGElement>) => (
|
||||
<svg {...base(p)}>
|
||||
<path d="M2 12h2M6 8v8M10 5v14M14 8v8M18 10v4M22 12h0" />
|
||||
</svg>
|
||||
);
|
||||
export const IDiscord = (p: SVGProps<SVGSVGElement>) => (
|
||||
<svg width={22} height={22} viewBox="0 0 24 24" fill="currentColor" aria-hidden {...p}>
|
||||
<path d="M20.3 4.4A19.6 19.6 0 0 0 15.4 3l-.6 1.3a18 18 0 0 0-5.6 0L8.6 3a19.6 19.6 0 0 0-4.9 1.5C.6 9.1-.3 13.6.1 18a19.8 19.8 0 0 0 6 3l1.3-2a12.8 12.8 0 0 1-2-1l.5-.4a14 14 0 0 0 12.2 0l.5.4-2 1 1.3 2a19.7 19.7 0 0 0 6-3c.5-5.1-.8-9.6-3.6-13.6zM8 15.3c-1.2 0-2.2-1.1-2.2-2.4S6.8 10.5 8 10.5s2.2 1.1 2.2 2.4-1 2.4-2.2 2.4zm8 0c-1.2 0-2.2-1.1-2.2-2.4s1-2.4 2.2-2.4 2.2 1.1 2.2 2.4-1 2.4-2.2 2.4z" />
|
||||
</svg>
|
||||
);
|
||||
export const IPlug = (p: SVGProps<SVGSVGElement>) => (
|
||||
<svg width={34} height={34} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={1.8} strokeLinecap="round" strokeLinejoin="round" aria-hidden {...p}>
|
||||
<path d="M9 2v5M15 2v5" />
|
||||
<path d="M6 7h12v4a6 6 0 0 1-12 0V7z" />
|
||||
<path d="M12 17v5" />
|
||||
<path d="m3 3 18 18" stroke="#ff4655" />
|
||||
</svg>
|
||||
);
|
||||
135
site/web/src/components/LockOverlay.tsx
Normal file
135
site/web/src/components/LockOverlay.tsx
Normal file
@@ -0,0 +1,135 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { AnimatePresence, motion } from 'framer-motion';
|
||||
import { useAuth, useStatus } from '../store/app';
|
||||
import { fmtAgo, fmtWhen } from '../lib/format';
|
||||
import { sfx } from '../lib/sfx';
|
||||
import { api } from '../lib/api';
|
||||
import { IPlug } from './Icons';
|
||||
|
||||
/** 게임 PC 연결 해제 잠금. 다시 연결되면 열리는 전환과 함께 자동으로 사라진다. */
|
||||
export function LockOverlay() {
|
||||
const { device, serverOk, locked, recheck } = useStatus();
|
||||
const { logout, auth } = useAuth();
|
||||
const isOwner = auth.status === 'ok' && auth.me.isOwner;
|
||||
const [code, setCode] = useState<{ code: string; expiresAt: number } | null>(null);
|
||||
const [codeErr, setCodeErr] = useState<string | null>(null);
|
||||
const [, force] = useState(0);
|
||||
const [checking, setChecking] = useState(false);
|
||||
useEffect(() => {
|
||||
if (!locked) return;
|
||||
const t = window.setInterval(() => force((n) => n + 1), 15000);
|
||||
return () => window.clearInterval(t);
|
||||
}, [locked]);
|
||||
|
||||
const notRegistered = device && !device.registered;
|
||||
return (
|
||||
<AnimatePresence>
|
||||
{locked && device && (
|
||||
<motion.div
|
||||
key="lock"
|
||||
className="lock"
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
exit={{ opacity: 0, transition: { duration: 0.6, delay: 0.25 } }}
|
||||
role="alertdialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="lock-title"
|
||||
>
|
||||
<div className="lock-veil" />
|
||||
<motion.div
|
||||
className="lock-box"
|
||||
initial={{ opacity: 0, y: 24, scale: 0.97 }}
|
||||
animate={{ opacity: 1, y: 0, scale: 1, transition: { duration: 0.35 } }}
|
||||
exit={{ opacity: 0, scale: 1.08, y: -10, filter: 'blur(6px)', transition: { duration: 0.5, ease: [0.4, 0, 0.2, 1] } }}
|
||||
>
|
||||
<div className="lock-ic">
|
||||
<IPlug />
|
||||
</div>
|
||||
<div className="t h" id="lock-title">
|
||||
{notRegistered ? '등록된 게임 PC가 없습니다' : '게임 PC 프로그램과 연결이 끊어졌습니다'}
|
||||
</div>
|
||||
<div className="d">
|
||||
기록은 게임 PC에만 저장되어 있어서, 프로그램이 켜져 있을 때만 볼 수 있어요.
|
||||
<br />
|
||||
{notRegistered ? '게임 PC에서 겜녹이 프로그램을 등록하면 자동으로 열립니다.' : '프로그램이 다시 연결되면 자동으로 열립니다.'}
|
||||
</div>
|
||||
<div className="st">
|
||||
<div>
|
||||
<span className="muted">사이트 서버</span>
|
||||
{serverOk === false ? <span className="c-r">● 응답 없음</span> : <span className="c-g">● 정상</span>}
|
||||
</div>
|
||||
<div>
|
||||
<span className="muted">등록된 게임 PC</span>
|
||||
<span>
|
||||
{device.name ?? '없음'} {device.version && <span className="dim">(v{device.version})</span>}
|
||||
</span>
|
||||
</div>
|
||||
<div>
|
||||
<span className="muted">프로그램 상태</span>
|
||||
<span className="c-r">
|
||||
● {notRegistered ? '등록 안 됨' : '연결 해제됨'}
|
||||
{device.lastSeen ? ` · 마지막 응답 ${fmtWhen(device.lastSeen)} (${fmtAgo(device.lastSeen)})` : ''}
|
||||
</span>
|
||||
</div>
|
||||
<div>
|
||||
<span className="muted">다시 확인</span>
|
||||
<span className="c-y">
|
||||
5초마다 자동 확인 중
|
||||
<span className="dots">
|
||||
<i />
|
||||
<i />
|
||||
<i />
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{isOwner && (
|
||||
<div className="lock-reg">
|
||||
{code ? (
|
||||
<div>
|
||||
게임 PC 겜녹이 설정 → <b>저장 · 사이트</b> 탭에 이 코드를 입력하세요
|
||||
<div className="lock-code">{code.code}</div>
|
||||
<span className="dim">{fmtWhen(code.expiresAt)}까지 유효 · 한 번만 쓸 수 있음</span>
|
||||
</div>
|
||||
) : (
|
||||
<button
|
||||
className="btn"
|
||||
onClick={async () => {
|
||||
sfx('click');
|
||||
setCodeErr(null);
|
||||
try {
|
||||
setCode(await api.registrationCode());
|
||||
} catch {
|
||||
setCodeErr('코드를 만들지 못했습니다');
|
||||
}
|
||||
}}
|
||||
>
|
||||
🔑 {notRegistered ? '게임 PC 등록 코드 만들기' : '게임 PC 다시 등록 (새 코드)'}
|
||||
</button>
|
||||
)}
|
||||
{codeErr && <div className="c-r">{codeErr}</div>}
|
||||
</div>
|
||||
)}
|
||||
<div className="lock-btns">
|
||||
<button
|
||||
className="btn"
|
||||
disabled={checking}
|
||||
onClick={async () => {
|
||||
sfx('click');
|
||||
setChecking(true);
|
||||
await recheck();
|
||||
window.setTimeout(() => setChecking(false), 600);
|
||||
}}
|
||||
>
|
||||
↻ {checking ? '확인 중…' : '지금 다시 확인'}
|
||||
</button>
|
||||
<button className="btn" onClick={logout}>
|
||||
로그아웃
|
||||
</button>
|
||||
</div>
|
||||
</motion.div>
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
);
|
||||
}
|
||||
79
site/web/src/components/LoginPage.tsx
Normal file
79
site/web/src/components/LoginPage.tsx
Normal file
@@ -0,0 +1,79 @@
|
||||
import { motion } from 'framer-motion';
|
||||
import { IDiscord } from './Icons';
|
||||
|
||||
/** 블러 처리된 가짜 화면 (로그인 뒤 배경) */
|
||||
function FakeBackdrop() {
|
||||
return (
|
||||
<div className="login-bg" aria-hidden>
|
||||
<div className="fb-top" />
|
||||
<div className="fb-main">
|
||||
<div className="fb-side">
|
||||
{Array.from({ length: 5 }, (_, i) => (
|
||||
<i key={i} style={{ background: ['#3987e5', '#e5743f', '#1fb383', '#9085e9', '#c98500'][i] }} />
|
||||
))}
|
||||
</div>
|
||||
<div className="fb-list">
|
||||
{Array.from({ length: 9 }, (_, i) => (
|
||||
<div key={i} className={i === 3 ? 'hot' : ''}>
|
||||
<b />
|
||||
<span style={{ width: `${40 + ((i * 37) % 45)}%` }} />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div className="fb-right">
|
||||
<div />
|
||||
<div />
|
||||
</div>
|
||||
</div>
|
||||
<div className="fb-foot" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function LoginPage({ notMember = false, error }: { notMember?: boolean; error?: string }) {
|
||||
return (
|
||||
<div className="login">
|
||||
<FakeBackdrop />
|
||||
<div className="login-veil" />
|
||||
<motion.div className="login-box" initial={{ opacity: 0, y: 18 }} animate={{ opacity: 1, y: 0 }} transition={{ duration: 0.45, ease: [0.2, 0.8, 0.2, 1] }}>
|
||||
<picture>
|
||||
<source srcSet="/banner.webp" type="image/webp" />
|
||||
<img className="ban" src="/banner.png" alt="겜녹이 Game Voice Recorder" />
|
||||
</picture>
|
||||
<div className="in">
|
||||
{notMember ? (
|
||||
<>
|
||||
<div className="t h">들어올 수 없는 계정입니다</div>
|
||||
<div className="nm-warn">M&L 서버 멤버만 들어올 수 있습니다</div>
|
||||
<div className="d">겜녹이 봇이 있는 디스코드 서버(M&L)에 참여한 계정으로 다시 로그인해 주세요.</div>
|
||||
<a className="dc" href="/auth/discord">
|
||||
<IDiscord />
|
||||
다른 계정으로 로그인
|
||||
</a>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<div className="t h">디스코드 계정으로 로그인</div>
|
||||
{error && <div className="nm-warn">{error}</div>}
|
||||
<div className="d">
|
||||
겜녹이 봇이 있는 디스코드 서버(M&L)의 멤버만 들어올 수 있어요.
|
||||
<br />
|
||||
로그인하면 녹음된 대화와 경기 기록을 볼 수 있습니다.
|
||||
</div>
|
||||
<a className="dc" href="/auth/discord">
|
||||
<IDiscord />
|
||||
Discord로 로그인
|
||||
</a>
|
||||
</>
|
||||
)}
|
||||
<div className="st">
|
||||
<span>
|
||||
<span className="c-g">●</span> 사이트 서버 정상
|
||||
</span>
|
||||
<span>🔒 HTTPS · gvr.tkrmagid.kr</span>
|
||||
</div>
|
||||
</div>
|
||||
</motion.div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
162
site/web/src/components/PlayerBar.tsx
Normal file
162
site/web/src/components/PlayerBar.tsx
Normal file
@@ -0,0 +1,162 @@
|
||||
import { useEffect, useMemo, useRef, type MouseEvent } from 'react';
|
||||
import WaveSurfer from 'wavesurfer.js';
|
||||
import { player, usePlayer, type SceneInfo } from '../store/player';
|
||||
import { settings, useSettings } from '../store/settings';
|
||||
import { useData } from '../store/app';
|
||||
import { sfx } from '../lib/sfx';
|
||||
import { fmtClock, fmtSec } from '../lib/format';
|
||||
import { Avatar } from './common';
|
||||
import { IClose, ILoop, INext, IPause, IPlay, IPrev, IVolume } from './Icons';
|
||||
|
||||
const RATES = [1, 1.25, 1.5, 2];
|
||||
|
||||
function SceneLanes({ scene }: { scene: SceneInfo }) {
|
||||
const { userById } = useData();
|
||||
const ts = usePlayer((s) => s.sceneTs);
|
||||
const lanes = useMemo(() => [...new Set(scene.items.map((i) => i.userId))], [scene]);
|
||||
const span = Math.max(1, scene.end - scene.start);
|
||||
const seek = (e: MouseEvent<HTMLDivElement>) => {
|
||||
const r = e.currentTarget.getBoundingClientRect();
|
||||
player.seekScene(((e.clientX - r.left) / r.width) * span);
|
||||
};
|
||||
const pos = ts == null ? 0 : Math.min(1, Math.max(0, (ts - scene.start) / span));
|
||||
return (
|
||||
<div className="lanes" onClick={seek} title="눌러서 이동">
|
||||
{lanes.map((uid) => {
|
||||
const u = userById(uid);
|
||||
return (
|
||||
<div className="lane" key={uid}>
|
||||
<span className="lane-nm" style={{ color: u?.color }}>
|
||||
{u?.name ?? '?'}
|
||||
</span>
|
||||
<div className="lane-track">
|
||||
{scene.items
|
||||
.filter((i) => i.userId === uid)
|
||||
.map((i) => {
|
||||
const on = ts != null && ts >= i.ts && ts <= i.endTs;
|
||||
return (
|
||||
<i
|
||||
key={i.id}
|
||||
className={on ? 'on' : ''}
|
||||
style={{ left: `${((i.ts - scene.start) / span) * 100}%`, width: `${Math.max(0.4, ((i.endTs - i.ts) / span) * 100)}%`, background: u?.color ?? '#5b6b7b' }}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
<div className="lane-cursor" style={{ left: `calc(64px + (100% - 64px) * ${pos})` }} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function PlayerBar() {
|
||||
const s = usePlayer((x) => x);
|
||||
const cfg = useSettings();
|
||||
const { userById } = useData();
|
||||
const waveRef = useRef<HTMLDivElement>(null);
|
||||
const wsRef = useRef<WaveSurfer | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!waveRef.current) return;
|
||||
const mobile = window.matchMedia('(max-width: 720px)').matches;
|
||||
const ws = WaveSurfer.create({
|
||||
container: waveRef.current,
|
||||
media: player.el,
|
||||
height: mobile ? 30 : 52,
|
||||
waveColor: '#33495e',
|
||||
progressColor: '#ff4655',
|
||||
cursorColor: '#ffffff',
|
||||
cursorWidth: 2,
|
||||
barWidth: 3,
|
||||
barGap: 3,
|
||||
barRadius: 2,
|
||||
normalize: true,
|
||||
interact: true,
|
||||
dragToSeek: true,
|
||||
});
|
||||
wsRef.current = ws;
|
||||
player.attachWave(ws);
|
||||
return () => {
|
||||
player.attachWave(null);
|
||||
ws.destroy();
|
||||
wsRef.current = null;
|
||||
};
|
||||
}, []);
|
||||
|
||||
const lol = s.item?.game?.type === 'lol';
|
||||
useEffect(() => {
|
||||
wsRef.current?.setOptions({ progressColor: lol ? '#c8aa6e' : '#ff4655' });
|
||||
}, [lol]);
|
||||
|
||||
const user = userById(s.item?.userId);
|
||||
const idle = s.mode === 'idle';
|
||||
const scene = s.mode === 'scene' ? s.scene : null;
|
||||
const click = (fn: () => void) => () => {
|
||||
sfx('click');
|
||||
fn();
|
||||
};
|
||||
|
||||
return (
|
||||
<footer className={`playerbar${lol ? ' lol' : ''}${idle ? ' idle' : ''}`} aria-label="플레이어">
|
||||
<button className="pb-skip" onClick={() => player.prev()} title="이전 발화 (←)" aria-label="이전 발화">
|
||||
<IPrev width={20} height={20} />
|
||||
</button>
|
||||
<button className="ctrl" onClick={() => player.toggle()} title="재생/일시정지 (Space)" aria-label={s.playing ? '일시정지' : '재생'}>
|
||||
{s.playing ? <IPause width={20} height={20} /> : <IPlay width={20} height={20} style={{ marginLeft: 3 }} />}
|
||||
</button>
|
||||
<button className="pb-skip" onClick={() => player.next()} title="다음 발화 (→)" aria-label="다음 발화">
|
||||
<INext width={20} height={20} />
|
||||
</button>
|
||||
<span className="mono muted pb-time">
|
||||
{scene ? `${fmtClock(s.time * 1000)} / ${fmtClock(s.duration * 1000)}` : `${fmtSec(s.time)} / ${fmtSec(s.duration)}`}
|
||||
</span>
|
||||
<div className="pb-now">
|
||||
{scene ? (
|
||||
<>
|
||||
<span className="scene-tag">현장 모드</span>
|
||||
<span className="pb-now-txt">
|
||||
<b>{scene.label}</b>
|
||||
<small>{scene.items.length}개 발화 겹쳐 듣기</small>
|
||||
</span>
|
||||
</>
|
||||
) : s.item ? (
|
||||
<>
|
||||
<Avatar user={user} size={30} />
|
||||
<span className="pb-now-txt">
|
||||
<b style={{ color: user?.color }}>{user?.name ?? '알 수 없음'}</b>
|
||||
<small className="mono">{s.item.time.primary}</small>
|
||||
</span>
|
||||
</>
|
||||
) : (
|
||||
<span className="pb-hint">발화를 누르면 여기서 재생됩니다 · Space · ←/→</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="wave-box">
|
||||
<div ref={waveRef} className="wave" style={{ display: scene || s.message || idle ? 'none' : undefined }} />
|
||||
{scene && <SceneLanes scene={scene} />}
|
||||
{!scene && s.message && <div className="pb-msg">🗑 {s.message}</div>}
|
||||
{idle && !s.message && <div className="wave-empty" />}
|
||||
</div>
|
||||
<button className={`chip${cfg.continuous ? ' on' : ''}`} onClick={click(() => settings.set({ continuous: !cfg.continuous }))} title="끝나면 다음 발화로 자동으로 넘어갑니다">
|
||||
<ILoop width={14} height={14} /> 이어듣기
|
||||
</button>
|
||||
<button className="chip mono" onClick={click(() => settings.set({ rate: RATES[(RATES.indexOf(cfg.rate) + 1) % RATES.length] }))} title="재생 속도">
|
||||
{cfg.rate}x
|
||||
</button>
|
||||
<button
|
||||
className={`chip${cfg.normalize ? ' on-mint' : ''}`}
|
||||
onClick={click(() => settings.set({ normalize: !cfg.normalize }))}
|
||||
title={s.item?.audio ? `보정 게인 ${s.item.audio.gainDb > 0 ? '+' : ''}${s.item.audio.gainDb.toFixed(1)} dB` : '사람마다 다른 마이크 음량을 재생할 때 맞춥니다'}
|
||||
>
|
||||
<IVolume width={14} height={14} /> 보정 음량
|
||||
</button>
|
||||
{!idle && (
|
||||
<button className="icon-btn pb-close" onClick={click(() => player.stop())} title="닫기" aria-label="플레이어 닫기">
|
||||
<IClose width={16} height={16} />
|
||||
</button>
|
||||
)}
|
||||
</footer>
|
||||
);
|
||||
}
|
||||
33
site/web/src/components/TalkBars.tsx
Normal file
33
site/web/src/components/TalkBars.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
import { useMemo } from 'react';
|
||||
import type { UtteranceItem } from '@gvr/shared';
|
||||
import { useData } from '../store/app';
|
||||
import { fmtDuration } from '../lib/format';
|
||||
|
||||
export function TalkBars({ utts }: { utts: UtteranceItem[] }) {
|
||||
const { userById } = useData();
|
||||
const rows = useMemo(() => {
|
||||
const m = new Map<string, number>();
|
||||
for (const u of utts) if (!u.noise) m.set(u.userId, (m.get(u.userId) ?? 0) + (u.endTs - u.ts));
|
||||
return [...m].sort((a, b) => b[1] - a[1]);
|
||||
}, [utts]);
|
||||
const max = rows[0]?.[1] ?? 1;
|
||||
if (!rows.length) return <div className="dim small">아직 발화가 없습니다</div>;
|
||||
return (
|
||||
<div className="talkbars">
|
||||
{rows.map(([uid, ms]) => {
|
||||
const u = userById(uid);
|
||||
return (
|
||||
<div key={uid} className="tb-row" data-tip={`${u?.name ?? '?'} · ${fmtDuration(ms)}`}>
|
||||
<div className="kv">
|
||||
<span>{u?.name ?? '알 수 없음'}</span>
|
||||
<span className="mono">{fmtDuration(ms)}</span>
|
||||
</div>
|
||||
<div className="bar">
|
||||
<i style={{ width: `${(ms / max) * 100}%`, background: u?.color ?? '#5b6b7b' }} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
64
site/web/src/components/TimelineRows.tsx
Normal file
64
site/web/src/components/TimelineRows.tsx
Normal file
@@ -0,0 +1,64 @@
|
||||
import { Fragment } from 'react';
|
||||
import { motion } from 'framer-motion';
|
||||
import type { MatchSummary, TimelineItem, UtteranceItem } from '@gvr/shared';
|
||||
import { UtteranceRow } from './UtteranceRow';
|
||||
import { EventRow } from './EventRow';
|
||||
import { itemMatch } from '../lib/game';
|
||||
import { fmtWhen } from '../lib/format';
|
||||
import { useReducedMotion } from '../store/settings';
|
||||
|
||||
/** 경기가 바뀌는 지점에 넣는 맥락 구분선 */
|
||||
function ContextDivider({ m, matchId }: { m?: MatchSummary; matchId: string | null }) {
|
||||
if (!matchId)
|
||||
return (
|
||||
<div className="div ctx">
|
||||
<span>경기 밖 · 현실 시간</span>
|
||||
</div>
|
||||
);
|
||||
return (
|
||||
<div className={`div ctx g-${m?.game ?? 'valorant'}`}>
|
||||
<span className="pill">{m?.game === 'lol' ? 'LoL' : 'VALORANT'}</span>
|
||||
<span>{m ? `${m.map.name} · ${m.mode} · ${fmtWhen(m.startedAt)} 시작` : '경기'}</span>
|
||||
{m?.score && <span className="score mono">{`${m.score.ally} : ${m.score.enemy}`}</span>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function TimelineRows({
|
||||
items,
|
||||
matches,
|
||||
newIds,
|
||||
onUpdate,
|
||||
}: {
|
||||
items: TimelineItem[];
|
||||
matches: Map<string, MatchSummary>;
|
||||
newIds: Set<string>;
|
||||
onUpdate: (it: UtteranceItem) => void;
|
||||
}) {
|
||||
const reduce = useReducedMotion();
|
||||
let prevMatch: string | null | undefined = undefined;
|
||||
return (
|
||||
<>
|
||||
{items.map((it) => {
|
||||
const mid = itemMatch(it);
|
||||
const divider = mid !== prevMatch ? <ContextDivider m={mid ? matches.get(mid) : undefined} matchId={mid} /> : null;
|
||||
prevMatch = mid;
|
||||
const row = it.kind === 'utterance' ? <UtteranceRow item={it} onUpdate={onUpdate} /> : <EventRow e={it} />;
|
||||
const isNew = newIds.has(it.id);
|
||||
return (
|
||||
<Fragment key={it.id}>
|
||||
{divider}
|
||||
<motion.div
|
||||
className={`row-wrap${isNew ? ' is-new' : ''}`}
|
||||
initial={isNew && !reduce ? { opacity: 0, x: -24, height: 0 } : false}
|
||||
animate={{ opacity: 1, x: 0, height: 'auto' }}
|
||||
transition={{ duration: 0.45, ease: [0.2, 0.8, 0.2, 1] }}
|
||||
>
|
||||
{row}
|
||||
</motion.div>
|
||||
</Fragment>
|
||||
);
|
||||
})}
|
||||
</>
|
||||
);
|
||||
}
|
||||
222
site/web/src/components/UtteranceRow.tsx
Normal file
222
site/web/src/components/UtteranceRow.tsx
Normal file
@@ -0,0 +1,222 @@
|
||||
import { memo, useEffect, useRef, useState, type MouseEvent } from 'react';
|
||||
import type { UtteranceItem, Word } from '@gvr/shared';
|
||||
import { player, useIsActive, useLocalTime, usePlayer } from '../store/player';
|
||||
import { useData } from '../store/app';
|
||||
import { api } from '../lib/api';
|
||||
import { sfx } from '../lib/sfx';
|
||||
import { realTip } from '../lib/format';
|
||||
import { Avatar, TimeCell } from './common';
|
||||
import { IEdit } from './Icons';
|
||||
|
||||
const STATUS: Record<UtteranceItem['status'], [string, string]> = {
|
||||
realtime: ['실시간', 'st-rt'],
|
||||
precise: ['정밀', 'st-pr'],
|
||||
pending: ['처리 중', 'st-pd'],
|
||||
failed: ['인식 실패', 'st-fail'],
|
||||
};
|
||||
|
||||
export function MiniWave({ n = 5, live = false }: { n?: number; live?: boolean }) {
|
||||
const hs = [6, 12, 5, 9, 4, 11, 7, 13, 5, 8, 10, 6, 12, 4, 9, 7];
|
||||
return (
|
||||
<span className={`mini-wave${live ? ' live' : ''}`} aria-hidden>
|
||||
{Array.from({ length: n }, (_, i) => (
|
||||
<i key={i} style={{ height: hs[i % hs.length], animationDelay: `${(i * 0.09).toFixed(2)}s` }} />
|
||||
))}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
function wordClick(e: MouseEvent, item: UtteranceItem, w: Word) {
|
||||
e.stopPropagation();
|
||||
player.seekTo(item, w.s);
|
||||
}
|
||||
|
||||
/** 재생 중인 발화: 재생 위치에 따라 단어 강조 (이 컴포넌트만 매 프레임 갱신) */
|
||||
function ActiveWords({ item }: { item: UtteranceItem }) {
|
||||
const t = useLocalTime(item.ts);
|
||||
return (
|
||||
<>
|
||||
{item.words.map((w, i) => {
|
||||
const cls = t < 0 ? '' : t >= w.e ? 'done' : t >= w.s ? 'now' : 'todo';
|
||||
return (
|
||||
<span key={i}>
|
||||
<span className={`w ${cls}`} onClick={(e) => wordClick(e, item, w)}>
|
||||
{w.w}
|
||||
</span>{' '}
|
||||
</span>
|
||||
);
|
||||
})}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function Text({ item, active }: { item: UtteranceItem; active: boolean }) {
|
||||
if (item.noise)
|
||||
return (
|
||||
<span className="noise">
|
||||
[잡음] <MiniWave />
|
||||
</span>
|
||||
);
|
||||
if (item.status === 'pending' && !item.text)
|
||||
return (
|
||||
<span className="pending">
|
||||
<MiniWave n={16} live /> <span className="dim">음성 인식 중…</span>
|
||||
</span>
|
||||
);
|
||||
if (!item.text) return <span className="dim">{item.status === 'failed' ? '(인식하지 못함)' : '(내용 없음)'}</span>;
|
||||
if (!item.words.length) return <>{item.text}</>;
|
||||
if (active) return <ActiveWords item={item} />;
|
||||
return (
|
||||
<>
|
||||
{item.words.map((w, i) => (
|
||||
<span key={i}>
|
||||
<span className="w" onClick={(e) => wordClick(e, item, w)}>
|
||||
{w.w}
|
||||
</span>{' '}
|
||||
</span>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function Editor({ item, onDone }: { item: UtteranceItem; onDone: (it?: UtteranceItem) => void }) {
|
||||
const [text, setText] = useState(item.text ?? '');
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [err, setErr] = useState<string | null>(null);
|
||||
const ref = useRef<HTMLInputElement>(null);
|
||||
useEffect(() => {
|
||||
ref.current?.focus();
|
||||
ref.current?.select();
|
||||
}, []);
|
||||
const save = async () => {
|
||||
const v = text.trim();
|
||||
if (!v || v === item.text) return onDone();
|
||||
setBusy(true);
|
||||
setErr(null);
|
||||
try {
|
||||
const it = await api.correct(item.id, v);
|
||||
sfx('click');
|
||||
onDone(it);
|
||||
} catch {
|
||||
setErr('저장하지 못했습니다');
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
return (
|
||||
<div className="editor" onClick={(e) => e.stopPropagation()}>
|
||||
<input
|
||||
ref={ref}
|
||||
value={text}
|
||||
disabled={busy}
|
||||
onChange={(e) => setText(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') void save();
|
||||
if (e.key === 'Escape') {
|
||||
e.stopPropagation();
|
||||
onDone();
|
||||
}
|
||||
}}
|
||||
aria-label="발화 텍스트 교정"
|
||||
/>
|
||||
<button className="btn primary sm" disabled={busy} onClick={() => void save()}>
|
||||
저장
|
||||
</button>
|
||||
<button className="btn sm" disabled={busy} onClick={() => onDone()}>
|
||||
취소
|
||||
</button>
|
||||
{err && <span className="err">{err}</span>}
|
||||
<div className="hint">고친 문장은 교정 사전과 학습 데이터에 반영됩니다 · Enter 저장 · Esc 취소</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
interface Props {
|
||||
item: UtteranceItem;
|
||||
variant?: 'full' | 'compact';
|
||||
/** compact 에서 시간 칸에 쓸 라벨 (예: 라운드 시간만) */
|
||||
timeText?: string;
|
||||
sub?: string;
|
||||
onUpdate?: (it: UtteranceItem) => void;
|
||||
}
|
||||
|
||||
export const UtteranceRow = memo(function UtteranceRow({ item, variant = 'full', timeText, sub, onUpdate }: Props) {
|
||||
const { userById } = useData();
|
||||
const user = userById(item.userId);
|
||||
const active = useIsActive(item);
|
||||
const playing = usePlayer((s) => active && s.playing);
|
||||
const [editing, setEditing] = useState(false);
|
||||
const [st, stCls] = STATUS[item.status];
|
||||
|
||||
const click = () => {
|
||||
if (editing) return;
|
||||
if (active && player.state.mode === 'single') player.toggle();
|
||||
else void player.play(item);
|
||||
};
|
||||
const edit = (e: MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
sfx('click');
|
||||
setEditing(true);
|
||||
};
|
||||
const done = (it?: UtteranceItem) => {
|
||||
setEditing(false);
|
||||
if (it) onUpdate?.(it);
|
||||
};
|
||||
|
||||
const badges = (
|
||||
<>
|
||||
{(item.status !== 'precise' || variant === 'full') && <span className={`sbadge ${stCls}`}>{st}</span>}
|
||||
{item.corrected && <span className="sbadge st-fix">교정됨</span>}
|
||||
{!item.audio && <span className="sbadge st-del" title="음성 보관 기간(7일)이 지나 삭제됨">음성 삭제됨</span>}
|
||||
{active && <span className="playing-tag">{playing ? '▶ 재생 중' : '❚❚ 일시정지'}</span>}
|
||||
</>
|
||||
);
|
||||
const editBtn = !item.noise && item.status !== 'pending' && onUpdate && (
|
||||
<button className="icon-btn edit-btn" title="텍스트 교정" aria-label="텍스트 교정" onClick={edit}>
|
||||
<IEdit width={15} height={15} />
|
||||
</button>
|
||||
);
|
||||
|
||||
if (variant === 'compact') {
|
||||
return (
|
||||
<div className={`l utt${active ? ' cur' : ''}${item.noise ? ' is-noise' : ''}`} onClick={click} data-id={item.id}>
|
||||
<span className="t mono" data-tip={realTip(item.ts)}>
|
||||
{timeText ?? item.time.primary}
|
||||
</span>
|
||||
<div className="lb">
|
||||
<b style={{ color: user?.color }}>{user?.name ?? '알 수 없음'}</b>
|
||||
{sub && <span className="dim sub"> · {sub}</span>} {badges}
|
||||
{editing ? (
|
||||
<Editor item={item} onDone={done} />
|
||||
) : (
|
||||
<div className="txt">
|
||||
<Text item={item} active={active} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{!editing && editBtn}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={`it utt${active ? ' playing' : ''}${item.noise ? ' is-noise' : ''}`} onClick={click} data-id={item.id}>
|
||||
<TimeCell time={item.time} real={!item.game} />
|
||||
<Avatar user={user} size={30} />
|
||||
<div className="body">
|
||||
<div className="who">
|
||||
<span style={{ color: user?.color ?? '#8696a6' }}>{user?.name ?? '알 수 없음'}</span>
|
||||
{sub && <span className="dim sub">· {sub}</span>}
|
||||
{badges}
|
||||
</div>
|
||||
{editing ? (
|
||||
<Editor item={item} onDone={done} />
|
||||
) : (
|
||||
<div className="txt">
|
||||
<Text item={item} active={active} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{!editing && editBtn}
|
||||
</div>
|
||||
);
|
||||
});
|
||||
105
site/web/src/components/common.tsx
Normal file
105
site/web/src/components/common.tsx
Normal file
@@ -0,0 +1,105 @@
|
||||
import type { CSSProperties, ReactNode } from 'react';
|
||||
import type { PlayerRef, TimeLabel, User } from '@gvr/shared';
|
||||
import { useData } from '../store/app';
|
||||
import { realTip } from '../lib/format';
|
||||
|
||||
export function Brand({ compact = false }: { compact?: boolean }) {
|
||||
return (
|
||||
<div className={`brand${compact ? ' compact' : ''}`}>
|
||||
<img src="/icon-192.png" alt="" />
|
||||
<div>
|
||||
<div className="nm">겜녹이</div>
|
||||
{!compact && <div className="en">GAME VOICE RECORDER</div>}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function Avatar({ user, size = 28, name, color, src }: { user?: User | null; size?: number; name?: string; color?: string; src?: string | null }) {
|
||||
const nm = user?.name ?? name ?? '?';
|
||||
const bg = user?.color ?? color ?? '#3a4654';
|
||||
const img = user?.avatar ?? src;
|
||||
const style: CSSProperties = { width: size, height: size, fontSize: Math.round(size * 0.42), background: bg };
|
||||
return (
|
||||
<span className="av" style={style} title={nm}>
|
||||
{img ? <img src={img} alt="" /> : nm.slice(0, 1)}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
/** 요원 · 챔피언 아이콘. icon 이 null 이면 이름 첫 글자 */
|
||||
export function CharIcon({ c, size = 24, className = '' }: { c?: { name: string; icon: string | null } | null; size?: number; className?: string }) {
|
||||
if (!c) return null;
|
||||
const style: CSSProperties = { width: size, height: size };
|
||||
return c.icon ? (
|
||||
<img className={`ag ${className}`} src={c.icon} alt={c.name} title={c.name} style={style} loading="lazy" />
|
||||
) : (
|
||||
<span className={`ag ag-fallback ${className}`} style={{ ...style, fontSize: Math.round(size * 0.45) }} title={c.name}>
|
||||
{c.name.slice(0, 1)}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
/** 플레이어 이름: 디스코드 유저와 연결돼 있으면 유저 색 */
|
||||
export function PName({ p, strong = true }: { p: PlayerRef | null | undefined; strong?: boolean }) {
|
||||
const { userById } = useData();
|
||||
if (!p) return <span className="dim">?</span>;
|
||||
const u = userById(p.userId);
|
||||
const Tag = strong ? 'b' : 'span';
|
||||
return <Tag style={u ? { color: u.color } : undefined}>{u?.name ?? p.name}</Tag>;
|
||||
}
|
||||
|
||||
export function UserName({ id, fallback = '알 수 없음' }: { id: string | undefined; fallback?: string }) {
|
||||
const { userById } = useData();
|
||||
const u = userById(id);
|
||||
return <b style={{ color: u?.color ?? '#8696a6' }}>{u?.name ?? fallback}</b>;
|
||||
}
|
||||
|
||||
/** 시간 칸: 주 표시 + 보조 표시, 마우스를 올리면 현실 시간 */
|
||||
export function TimeCell({ time, real = false, className = '' }: { time: TimeLabel; real?: boolean; className?: string }) {
|
||||
return (
|
||||
<div className={`time mono ${real ? 'real' : ''} ${className}`} data-tip={realTip(time.real)}>
|
||||
{time.primary}
|
||||
<small>{time.secondary ?? (real ? '현실 시간' : '')}</small>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function Panel({ title, right, children, className = '' }: { title: ReactNode; right?: ReactNode; children: ReactNode; className?: string }) {
|
||||
return (
|
||||
<section className={`panel ${className}`}>
|
||||
<h4>
|
||||
<span>{title}</span>
|
||||
{right && <span className="ph-right">{right}</span>}
|
||||
</h4>
|
||||
{children}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
export function Spinner({ label = '불러오는 중' }: { label?: string }) {
|
||||
return (
|
||||
<div className="spinner" role="status">
|
||||
<i />
|
||||
<i />
|
||||
<i />
|
||||
<span>{label}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function ErrorBox({ error, onRetry }: { error: unknown; onRetry?: () => void }) {
|
||||
const code = (error as { code?: string; status?: number })?.code;
|
||||
const status = (error as { status?: number })?.status;
|
||||
const msg = code === 'device_offline' ? '게임 PC와 연결이 끊어져 있습니다' : status === 404 ? '찾을 수 없습니다' : code === 'network' ? '네트워크 오류' : '불러오지 못했습니다';
|
||||
return (
|
||||
<div className="errbox">
|
||||
<span>{msg}</span>
|
||||
{onRetry && (
|
||||
<button className="btn" onClick={onRetry}>
|
||||
다시 시도
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user