관리자 편집 보호: 자동 매칭은 관리자가 정한 영상을 덮어쓰지 않음(쓰기 시점 조건·실제 갱신만 집계), 다시 가져와도 관리자가 정한 장르(빈 선택 포함) 유지, 안 바꾼 유튜브 주소는 보내지 않음 + 후보 확정 버튼, 회귀 테스트 3개·e2e
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -251,11 +251,14 @@ function SongEditor({ id, genres, onClose, onSaved }: { id: number; genres: Genr
|
||||
const [d, setD] = useState<Detail | null>(null);
|
||||
const [form, setForm] = useState({ title: '', artist: '', year: '', level: '', youtube: '', highlight: '', titleAliases: '', artistAliases: '', note: '', hidden: false, genres: [] as string[] });
|
||||
const [busy, setBusy] = useState(false);
|
||||
/** The address as loaded: `youtube` is only sent when the admin changed it (review 2026-10-18). */
|
||||
const [loadedYoutube, setLoadedYoutube] = useState('');
|
||||
const load = useCallback(() => {
|
||||
apiCall<Detail>('GET', `/api/admin/songs/${id}`)
|
||||
.then((x) => {
|
||||
setD(x);
|
||||
const lv = x.levels.find((l) => l.scope === 'all');
|
||||
setLoadedYoutube(x.song.youtube_id ? `https://youtu.be/${x.song.youtube_id}` : '');
|
||||
setForm({
|
||||
title: x.song.title,
|
||||
artist: x.song.artist,
|
||||
@@ -279,14 +282,13 @@ function SongEditor({ id, genres, onClose, onSaved }: { id: number; genres: Genr
|
||||
e.preventDefault();
|
||||
setBusy(true);
|
||||
try {
|
||||
const curYt = d.song.youtube_id ? `https://youtu.be/${d.song.youtube_id}` : '';
|
||||
await apiCall('PATCH', `/api/admin/songs/${id}`, {
|
||||
title: form.title,
|
||||
artist: form.artist,
|
||||
year: form.year ? Number(form.year) : null,
|
||||
level: form.level ? Number(form.level) : null,
|
||||
genres: form.genres,
|
||||
...(form.youtube.trim() !== curYt || d.song.youtube_status !== 'matched' ? { youtube: form.youtube.trim() || null } : {}),
|
||||
...(form.youtube.trim() !== loadedYoutube ? { youtube: form.youtube.trim() || null } : {}),
|
||||
highlightSec: form.highlight ? Number(form.highlight) : null,
|
||||
titleAliases: split(form.titleAliases),
|
||||
artistAliases: split(form.artistAliases),
|
||||
@@ -381,6 +383,28 @@ function SongEditor({ id, genres, onClose, onSaved }: { id: number; genres: Genr
|
||||
<span className={`badge ${YT_LABEL[d.song.youtube_status][1]}`}>{YT_LABEL[d.song.youtube_status][0]}</span>{' '}
|
||||
{d.song.youtube_channel && <span className="muted">{d.song.youtube_channel} · {d.song.youtube_title}</span>}
|
||||
</p>
|
||||
{d.song.youtube_status === 'candidate' && d.song.youtube_id && (
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-sm"
|
||||
disabled={busy}
|
||||
onClick={async () => {
|
||||
setBusy(true);
|
||||
try {
|
||||
await apiCall('PATCH', `/api/admin/songs/${id}`, { youtube: `https://youtu.be/${d.song.youtube_id}` });
|
||||
toast('이 영상으로 확정했어요.');
|
||||
load();
|
||||
onSaved();
|
||||
} catch (ex) {
|
||||
toast((ex as Error).message, 'error');
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}}
|
||||
>
|
||||
지금 후보 영상으로 확정
|
||||
</button>
|
||||
)}
|
||||
{videoId && (
|
||||
<div className="yt-preview">
|
||||
<iframe
|
||||
|
||||
Reference in New Issue
Block a user