이지선다 모드: 조회수가 더 높은 곡 고르기. 이지선다 퀴즈는 조회수가 든 파일로 만들고(custom_quizzes.kind='duel', custom_quiz_items.views, 013 마이그레이션; 1,234,567·123만·1.2억도 읽음, 조회수 없는 줄은 빠짐) 이지선다에서만, 일반 퀴즈는 듣고맞추기에서만 쓴다. 서버 game/duel.ts: 문제마다 A/B 카드, 카드를 누르면 고른 것(시간 전까지 바꾸기), 시간이 끝나면 조회수 공개·높은 쪽 1점·역배(혼자 맞히고 반대쪽 2명 이상) 2점·같으면 둘 다 정답, 매번 새 두 곡/연속(이긴 곡이 조회수를 보인 채 A로 남음). 화면 DuelScreen: 고른 사람 프로필이 카드 밑에, 카드마다 숨은 플레이어(net/duel-player.ts)로 각자 듣고 다시 누르면 멈춘 곳부터 이어서. 방 설정 이지선다(제한 시간 기본 30초·진행 방식·재생위치·문제 수, 이지선다 퀴즈만 목록에), 결과 화면 역배 성공 수. 관리자 파일로 만들기 종류 선택(조회수 열이 있으면 이지선다), 조회수 편집·내보내기·빈 양식. 폰 점수판 가로 스크롤 키보드 접근(axe). 서버 테스트 146개, e2e duel(실제 유튜브 이어 듣기 포함)·game·quiz·admin·rooms·login·a11y 통과
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,11 +7,16 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { Link, useNavigate, useParams, useSearchParams } from 'react-router';
|
||||
import {
|
||||
DEFAULT_QUIZ_SETTINGS,
|
||||
DUEL_FLOWS,
|
||||
DUEL_SECS,
|
||||
LISTEN_SECS,
|
||||
QUIZ_VISIBILITIES,
|
||||
listenLabel,
|
||||
parseViews,
|
||||
viewsLabel,
|
||||
type QuizDetail,
|
||||
type QuizItem,
|
||||
type QuizKind,
|
||||
type QuizSettings,
|
||||
type QuizSummary,
|
||||
type QuizVisibility,
|
||||
@@ -64,15 +69,18 @@ export function QuizzesPage() {
|
||||
</label>
|
||||
)}
|
||||
</div>
|
||||
<p className="muted">직접 만든 퀴즈예요. 방 설정에서 "제작된 퀴즈"를 고르면 이 퀴즈의 곡이 순서대로(또는 섞어서) 전부 나와요. 듣고맞추기에서만 쓸 수 있어요.</p>
|
||||
<p className="muted">
|
||||
직접 만든 퀴즈예요. 일반 퀴즈는 방 설정에서 "제작된 퀴즈"를 고르면 곡이 순서대로(또는 섞어서) 전부 나오고, 듣고맞추기에서만 쓸 수 있어요. 🆚 이지선다 퀴즈는 조회수가 든 파일로 만들고, 이지선다
|
||||
모드에서만 쓸 수 있어요.
|
||||
</p>
|
||||
{fromFile && (
|
||||
<QuizFileImport
|
||||
mode="create"
|
||||
onClose={() => setFromFile(false)}
|
||||
onCreate={async (quizName, items) => {
|
||||
onCreate={async (quizName, items, kind) => {
|
||||
try {
|
||||
const r = await apiCall<{ id: number }>('POST', '/api/admin/quizzes/file', { name: quizName, items });
|
||||
toast(`"${quizName}" 퀴즈를 ${items.length}곡으로 만들었어요.`);
|
||||
const r = await apiCall<{ id: number }>('POST', '/api/admin/quizzes/file', { name: quizName, items, kind });
|
||||
toast(`"${quizName}" ${kind === 'duel' ? '이지선다 ' : ''}퀴즈를 ${items.length}곡으로 만들었어요.`);
|
||||
nav(`/admin/quizzes/${r.id}`);
|
||||
} catch (e) {
|
||||
toast((e as Error).message, 'error');
|
||||
@@ -86,6 +94,7 @@ export function QuizzesPage() {
|
||||
<b className="nm">{q.name}</b>
|
||||
{q.description && <span className="muted small clamp2">{q.description}</span>}
|
||||
<span className="row small" style={{ gap: 6 }}>
|
||||
{q.kind === 'duel' && <span className="badge teal">🆚 이지선다</span>}
|
||||
<span className={`badge ${VIS_CLASS[q.visibility]}`}>{VIS_LABEL[q.visibility]}</span>
|
||||
<span className="muted">
|
||||
{q.songs}곡 · 플레이 {q.plays}번{all ? ` · ${q.ownerName}` : ''}
|
||||
@@ -123,7 +132,7 @@ export function QuizzesPage() {
|
||||
{!fromFile && (
|
||||
<button type="button" className="quiz-card add plus" onClick={() => setFromFile(true)}>
|
||||
<span aria-hidden>📄</span> 파일로 만들기
|
||||
<small className="muted">엑셀(.xlsx)·CSV</small>
|
||||
<small className="muted">엑셀(.xlsx)·CSV · 일반 / 이지선다</small>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
@@ -150,8 +159,8 @@ export interface DbInfo {
|
||||
}
|
||||
|
||||
/** A song picked in the editor (search, address, playlist): answers, hints and positions start empty. */
|
||||
type NewSong = Omit<QuizItem, 'titleAnswers' | 'artistAnswers' | 'hints' | 'fromFile' | 'auto' | 'startSec' | 'highlightSec'>;
|
||||
const fresh = (it: NewSong): QuizItem => ({ ...it, titleAnswers: [], artistAnswers: [], hints: [], fromFile: false, auto: true, startSec: null, highlightSec: null });
|
||||
type NewSong = Omit<QuizItem, 'titleAnswers' | 'artistAnswers' | 'hints' | 'fromFile' | 'auto' | 'startSec' | 'highlightSec' | 'views'>;
|
||||
const fresh = (it: NewSong): QuizItem => ({ ...it, titleAnswers: [], artistAnswers: [], hints: [], fromFile: false, auto: true, startSec: null, highlightSec: null, views: null });
|
||||
|
||||
let keySeq = 0;
|
||||
const newKey = () => `k${++keySeq}`;
|
||||
@@ -176,7 +185,7 @@ export function QuizEditor() {
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [leaveTo, setLeaveTo] = useState<string | null>(null);
|
||||
const [confirmDelete, setConfirmDelete] = useState(false);
|
||||
const [owner, setOwner] = useState<{ ownerName: string; plays: number } | null>(null);
|
||||
const [owner, setOwner] = useState<{ ownerName: string; plays: number; kind: QuizKind } | null>(null);
|
||||
const [importOpen, setImportOpen] = useState(false);
|
||||
const [fileOpen, setFileOpen] = useState(false);
|
||||
|
||||
@@ -187,7 +196,7 @@ export function QuizEditor() {
|
||||
setDraft(d);
|
||||
setSaved(JSON.stringify(payload(d)));
|
||||
setDb(r.db);
|
||||
setOwner({ ownerName: r.quiz.ownerName, plays: r.quiz.plays });
|
||||
setOwner({ ownerName: r.quiz.ownerName, plays: r.quiz.plays, kind: r.quiz.kind });
|
||||
})
|
||||
.catch((e: Error) => toast(e.message, 'error'));
|
||||
}, [id]);
|
||||
@@ -292,6 +301,7 @@ export function QuizEditor() {
|
||||
|
||||
if (!draft) return <p className="muted">불러오는 중…</p>;
|
||||
const set = (p: Partial<Draft>) => setDraft({ ...draft, ...p });
|
||||
const kind: QuizKind = owner?.kind ?? 'normal';
|
||||
const isNew = params.get('new') === '1' && draft.items.length === 0;
|
||||
|
||||
return (
|
||||
@@ -302,7 +312,7 @@ export function QuizEditor() {
|
||||
</Link>
|
||||
<h1 className="grow">{draft.name || '이름 없는 퀴즈'}</h1>
|
||||
{dirty ? <span className="badge warn" role="status">● 저장하지 않은 변경이 있어요</span> : <span className="muted small">저장됨</span>}
|
||||
<button type="button" className="btn" disabled={!draft.items.length} onClick={() => exportQuiz(draft.name, draft.items)} title="곡 목록을 다시 올릴 수 있는 엑셀 파일로 받아요">
|
||||
<button type="button" className="btn" disabled={!draft.items.length} onClick={() => exportQuiz(draft.name, draft.items, kind)} title="곡 목록을 다시 올릴 수 있는 엑셀 파일로 받아요">
|
||||
📥 엑셀로 내보내기
|
||||
</button>
|
||||
<button type="button" className="btn btn-primary" disabled={busy || !dirty} onClick={() => void save()} title="Ctrl+S">
|
||||
@@ -311,7 +321,8 @@ export function QuizEditor() {
|
||||
</div>
|
||||
{owner && (
|
||||
<p className="muted small" style={{ marginTop: -8 }}>
|
||||
만든 사람 {owner.ownerName} · {draft.items.length}곡 · 플레이 {owner.plays}번 · <span className={`badge ${VIS_CLASS[draft.visibility]}`}>{VIS_LABEL[draft.visibility]}</span>
|
||||
{kind === 'duel' && <span className="badge teal">🆚 이지선다</span>} 만든 사람 {owner.ownerName} · {draft.items.length}곡 · 플레이 {owner.plays}번 ·{' '}
|
||||
<span className={`badge ${VIS_CLASS[draft.visibility]}`}>{VIS_LABEL[draft.visibility]}</span>
|
||||
</p>
|
||||
)}
|
||||
<div className="seg" role="tablist" style={{ maxWidth: 360 }}>
|
||||
@@ -340,6 +351,7 @@ export function QuizEditor() {
|
||||
)}
|
||||
{tab === 'songs' ? (
|
||||
<SongsTab
|
||||
kind={kind}
|
||||
items={draft.items}
|
||||
db={db}
|
||||
settings={draft.settings}
|
||||
@@ -351,7 +363,7 @@ export function QuizEditor() {
|
||||
onHints={() => draft.settings.hint === 'none' && set({ settings: { ...draft.settings, hint: 'manual' } })}
|
||||
/>
|
||||
) : (
|
||||
<SettingsTab draft={draft} onChange={set} onDelete={() => setConfirmDelete(true)} />
|
||||
<SettingsTab kind={kind} draft={draft} onChange={set} onDelete={() => setConfirmDelete(true)} />
|
||||
)}
|
||||
{leaveTo && (
|
||||
<Sheet label="저장하지 않은 변경" onClose={() => setLeaveTo(null)}>
|
||||
@@ -444,6 +456,7 @@ interface VideoInfo {
|
||||
const looksLikeUrl = (s: string) => /^(https?:\/\/|www\.|youtu\.?be|m\.youtube|music\.youtube)/i.test(s.trim()) || /^[\w-]{11}$/.test(s.trim());
|
||||
|
||||
function SongsTab({
|
||||
kind,
|
||||
items,
|
||||
db,
|
||||
settings,
|
||||
@@ -454,6 +467,7 @@ function SongsTab({
|
||||
setFileOpen,
|
||||
onHints,
|
||||
}: {
|
||||
kind: QuizKind;
|
||||
items: DraftItem[];
|
||||
db: Record<number, DbInfo | null>;
|
||||
settings: QuizSettings;
|
||||
@@ -469,6 +483,7 @@ function SongsTab({
|
||||
const [dragKey, setDragKey] = useState<string | null>(null);
|
||||
const [overKey, setOverKey] = useState<string | null>(null);
|
||||
const selected = items.find((i) => i.key === sel) ?? null;
|
||||
const duel = kind === 'duel';
|
||||
const add = (it: NewSong) => {
|
||||
if (items.some((x) => x.videoId === it.videoId || (it.songId && x.songId === it.songId))) {
|
||||
toast('이미 목록에 있는 곡이에요.', 'error');
|
||||
@@ -497,6 +512,7 @@ function SongsTab({
|
||||
{fileOpen ? (
|
||||
<QuizFileImport
|
||||
mode="into"
|
||||
kind={kind}
|
||||
existing={items}
|
||||
onClose={() => setFileOpen(false)}
|
||||
onApply={(rows, replace) => {
|
||||
@@ -535,13 +551,18 @@ function SongsTab({
|
||||
<p className="muted">아직 곡이 없어요. 위에서 제목·가수로 찾거나 유튜브 주소를 붙여 넣어 추가해 주세요.</p>
|
||||
) : (
|
||||
<div className="table-wrap">
|
||||
{duel && items.some((i) => i.views === null) && (
|
||||
<p className="warn-text small" style={{ margin: '8px 10px' }}>
|
||||
조회수가 없는 곡 {items.filter((i) => i.views === null).length}곡은 게임에 나오지 않아요. 곡을 눌러 조회수를 넣어 주세요.
|
||||
</p>
|
||||
)}
|
||||
<table className="data-table quiz-songs">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style={{ width: 28 }} aria-label="순서 옮기기" />
|
||||
<th style={{ width: 44 }}>번호</th>
|
||||
<th>노래</th>
|
||||
<th>추가 정답</th>
|
||||
<th>{duel ? '조회수' : '추가 정답'}</th>
|
||||
<th>길이</th>
|
||||
<th>재생 위치</th>
|
||||
<th style={{ width: 120 }} />
|
||||
@@ -585,7 +606,13 @@ function SongsTab({
|
||||
</div>
|
||||
{it.hints.length > 0 && <div className="muted small">힌트: {it.hints.join(' → ')}</div>}
|
||||
</td>
|
||||
<td className="small">{[...it.titleAnswers, ...it.artistAnswers].join(', ') || <span className="muted">-</span>}</td>
|
||||
{duel ? (
|
||||
<td className="mono small" title={it.views !== null ? `${it.views.toLocaleString('ko-KR')}회` : undefined}>
|
||||
{it.views !== null ? `${viewsLabel(it.views)}회` : <span className="warn-text">없음</span>}
|
||||
</td>
|
||||
) : (
|
||||
<td className="small">{[...it.titleAnswers, ...it.artistAnswers].join(', ') || <span className="muted">-</span>}</td>
|
||||
)}
|
||||
<td className="mono small">{mmss(it.durationSec ?? (it.songId ? db[it.songId]?.durationSec : null))}</td>
|
||||
<td className="small">{it.auto ? <span className="muted">자동</span> : `처음 ${mmss(it.startSec ?? 0)} · 하이라이트 ${mmss(it.highlightSec)}`}</td>
|
||||
<td onClick={(e) => e.stopPropagation()}>
|
||||
@@ -611,6 +638,7 @@ function SongsTab({
|
||||
{selected && (
|
||||
<ItemPanel
|
||||
key={selected.key}
|
||||
duel={duel}
|
||||
item={selected}
|
||||
index={items.indexOf(selected)}
|
||||
total={items.length}
|
||||
@@ -1011,6 +1039,7 @@ function ChipsInput({ values, onChange, label, placeholder }: { values: string[]
|
||||
}
|
||||
|
||||
function ItemPanel({
|
||||
duel,
|
||||
item,
|
||||
index,
|
||||
total,
|
||||
@@ -1022,6 +1051,7 @@ function ItemPanel({
|
||||
onClose,
|
||||
isDuplicate,
|
||||
}: {
|
||||
duel: boolean;
|
||||
item: DraftItem;
|
||||
index: number;
|
||||
total: number;
|
||||
@@ -1037,6 +1067,8 @@ function ItemPanel({
|
||||
const [url, setUrl] = useState('');
|
||||
const [pos, setPos] = useState(String(index + 1));
|
||||
useEffect(() => setPos(String(index + 1)), [index]);
|
||||
const [viewsText, setViewsText] = useState(item.views === null ? '' : String(item.views));
|
||||
const viewsBad = parseViews(viewsText) === undefined;
|
||||
const changeVideo = async () => {
|
||||
try {
|
||||
const v = await apiCall<VideoInfo>('POST', '/api/admin/quizzes/pick/video', { url: url.trim() });
|
||||
@@ -1068,13 +1100,32 @@ function ItemPanel({
|
||||
onChange={onPatch}
|
||||
/>
|
||||
<label className="field">
|
||||
제목 (정답)
|
||||
{duel ? '제목 (카드에 보여요)' : '제목 (정답)'}
|
||||
<input className="input" value={item.title} maxLength={200} onChange={(e) => onPatch({ title: e.target.value })} />
|
||||
</label>
|
||||
<label className="field">
|
||||
{item.fromFile ? '설명 (정답과 같이 공개돼요)' : '가수'}
|
||||
{duel ? '가수' : item.fromFile ? '설명 (정답과 같이 공개돼요)' : '가수'}
|
||||
<input className="input" value={item.artist} maxLength={200} onChange={(e) => onPatch({ artist: e.target.value })} />
|
||||
</label>
|
||||
{duel && (
|
||||
<label className="field">
|
||||
조회수 (예: 1234567, 123만, 1.2억)
|
||||
<input
|
||||
className="input"
|
||||
value={viewsText}
|
||||
inputMode="numeric"
|
||||
onChange={(e) => {
|
||||
setViewsText(e.target.value);
|
||||
const v = parseViews(e.target.value);
|
||||
if (v !== undefined) onPatch({ views: v });
|
||||
}}
|
||||
aria-invalid={viewsBad}
|
||||
/>
|
||||
{viewsBad ? <span className="field-error small">조회수를 읽을 수 없어요.</span> : item.views !== null && <span className="muted small">{item.views.toLocaleString('ko-KR')}회</span>}
|
||||
</label>
|
||||
)}
|
||||
{!duel && (
|
||||
<>
|
||||
<div className="field">
|
||||
힌트 (적은 순서대로 하나씩 나오고, 마지막에 초성 힌트가 나와요)
|
||||
<ChipsInput values={item.hints} onChange={(hints) => onPatch({ hints: hints.slice(0, 5) })} label="힌트" placeholder="힌트 입력 후 Enter (예: 액션 RPG)" />
|
||||
@@ -1087,6 +1138,8 @@ function ItemPanel({
|
||||
가수 추가 정답
|
||||
<ChipsInput values={item.artistAnswers} onChange={(artistAnswers) => onPatch({ artistAnswers })} label="가수 추가 정답" placeholder="다른 표기 입력 후 Enter (예: IU)" />
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
{item.fromFile ? (
|
||||
<p className="muted small">파일에서 넣은 곡이에요. 적힌 값 그대로 쓰고, 서버 노래 DB 검토에는 올라가지 않아요.</p>
|
||||
) : item.songId ? (
|
||||
@@ -1144,7 +1197,8 @@ function ItemPanel({
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ 설정
|
||||
function SettingsTab({ draft, onChange, onDelete }: { draft: Draft; onChange: (p: Partial<Draft>) => void; onDelete: () => void }) {
|
||||
function SettingsTab({ kind, draft, onChange, onDelete }: { kind: QuizKind; draft: Draft; onChange: (p: Partial<Draft>) => void; onDelete: () => void }) {
|
||||
const duel = kind === 'duel';
|
||||
const s = draft.settings;
|
||||
const setS = (p: Partial<QuizSettings>) => onChange({ settings: { ...s, ...p } });
|
||||
const vis = useMemo(() => QUIZ_VISIBILITIES.find((v) => v.id === draft.visibility)!, [draft.visibility]);
|
||||
@@ -1169,6 +1223,16 @@ function SettingsTab({ draft, onChange, onDelete }: { draft: Draft; onChange: (p
|
||||
{vis.help}
|
||||
</p>
|
||||
</Section>
|
||||
{duel ? (
|
||||
<>
|
||||
<Section title="제한 시간" tip="카드를 고를 수 있는 시간. 그 안에는 몇 번이든 바꿀 수 있어요">
|
||||
<Seg label="제한 시간" value={s.duelSec} disabled={false} onChange={(duelSec) => setS({ duelSec })} options={DUEL_SECS.map((v) => ({ v, label: `${v}초` }))} />
|
||||
</Section>
|
||||
<Section title="진행 방식" tip="곡은 늘 무작위로 짝지어요">
|
||||
<Seg label="진행 방식" value={s.duelFlow} disabled={false} onChange={(duelFlow) => setS({ duelFlow })} options={DUEL_FLOWS.map((f) => ({ v: f.id, label: f.label }))} />
|
||||
</Section>
|
||||
</>
|
||||
) : (
|
||||
<Section title="문제 순서" tip="문제 수는 퀴즈에 든 곡 전부예요">
|
||||
<Seg
|
||||
label="문제 순서"
|
||||
@@ -1181,6 +1245,7 @@ function SettingsTab({ draft, onChange, onDelete }: { draft: Draft; onChange: (p
|
||||
]}
|
||||
/>
|
||||
</Section>
|
||||
)}
|
||||
<Section title="재생위치 기본" tip="곡마다 정한 '처음' 위치 또는 '하이라이트' 위치에서 틀어요">
|
||||
<Seg
|
||||
label="재생위치 기본"
|
||||
@@ -1193,10 +1258,12 @@ function SettingsTab({ draft, onChange, onDelete }: { draft: Draft; onChange: (p
|
||||
]}
|
||||
/>
|
||||
</Section>
|
||||
<Section title="듣고맞출시간">
|
||||
<Seg label="듣고맞출시간" value={s.listenSec} disabled={false} onChange={(listenSec) => setS({ listenSec })} options={LISTEN_SECS.map((v) => ({ v, label: listenLabel(v) }))} />
|
||||
</Section>
|
||||
<PlayRules c={s} ro={false} listening onPatch={(p) => setS(p as Partial<QuizSettings>)} />
|
||||
{!duel && (
|
||||
<Section title="듣고맞출시간">
|
||||
<Seg label="듣고맞출시간" value={s.listenSec} disabled={false} onChange={(listenSec) => setS({ listenSec })} options={LISTEN_SECS.map((v) => ({ v, label: listenLabel(v) }))} />
|
||||
</Section>
|
||||
)}
|
||||
<PlayRules c={s} ro={false} listening duel={duel} onPatch={(p) => setS(p as Partial<QuizSettings>)} />
|
||||
<section className="sec">
|
||||
<button type="button" className="btn btn-danger btn-sm" onClick={onDelete}>
|
||||
퀴즈 지우기
|
||||
|
||||
Reference in New Issue
Block a user