fix: load sort tags regardless of romaji toggle state

romajiLookup returned null when the index wasn't loaded (only loaded when
showRomaji is ON). Now fetchRomajiIndex is called on-demand in the edit modal
so sort tags pre-fill from the index works even when the toggle is OFF.
Actual file tags from /api/song-sorttags still overwrite as the final step.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
HoneyandClaude Sonnet 4.6 committed 2026-05-26 20:14:51 +02:00
1 parent 255ea1969c
commit c73665af58
1 file changed
+22 -21
+22 -21
View File
@@ -309,11 +309,7 @@ export async function showSongInfo(s) {
document.getElementById('ie-track').value = full.track || ''; document.getElementById('ie-track').value = full.track || '';
document.getElementById('ie-disc').value = full.discNumber || ''; document.getElementById('ie-disc').value = full.discNumber || '';
document.getElementById('ie-totaltracks').value = full.albumSongCount || ''; document.getElementById('ie-totaltracks').value = full.albumSongCount || '';
const _rm2 = romajiLookup(full.id); // sort tags are populated by the async chain in toggleInfoEdit — no need to reset here
document.getElementById('ie-titlesort').value = _rm2?.titleRomaji || '';
document.getElementById('ie-artistsort').value = _rm2?.artistRomaji || '';
document.getElementById('ie-albumartistsort').value = _rm2?.artistRomaji || '';
document.getElementById('ie-albumsort').value = _rm2?.albumRomaji || '';
} }
} }
} catch {} } catch {}
@@ -356,22 +352,27 @@ export function toggleInfoEdit() {
document.getElementById('ie-disc').value = s.discNumber || ''; document.getElementById('ie-disc').value = s.discNumber || '';
document.getElementById('ie-totaltracks').value = s.albumSongCount || ''; document.getElementById('ie-totaltracks').value = s.albumSongCount || '';
// Sort tags — pre-fill from romaji index, then overwrite with actual file tags if backend available // Sort tags: fetch romaji index on demand (cached if already loaded), then overwrite with
const _rm = romajiLookup(s.id); // actual file tags from backend. This works regardless of the showRomaji toggle.
document.getElementById('ie-titlesort').value = _rm?.titleRomaji || ''; const _sId = s.id;
document.getElementById('ie-artistsort').value = _rm?.artistRomaji || ''; fetchRomajiIndex().catch(() => null).then(() => {
document.getElementById('ie-albumartistsort').value = _rm?.artistRomaji || ''; const rm = romajiLookup(_sId);
document.getElementById('ie-albumsort').value = _rm?.albumRomaji || ''; if (rm) {
if (S.cfg.backendUrl && s.id) { document.getElementById('ie-titlesort').value = rm.titleRomaji || '';
const p = new URLSearchParams({ ndUrl: S.cfg.url, user: S.cfg.user, pass: S.cfg.pass, songId: s.id }); document.getElementById('ie-artistsort').value = rm.artistRomaji || '';
fetch(`${S.cfg.backendUrl}/api/song-sorttags?${p}`).then(r => r.ok ? r.json() : null).then(t => { document.getElementById('ie-albumartistsort').value = rm.artistRomaji || '';
if (!t) return; document.getElementById('ie-albumsort').value = rm.albumRomaji || '';
if (t.titleSort) document.getElementById('ie-titlesort').value = t.titleSort; }
if (t.artistSort) document.getElementById('ie-artistsort').value = t.artistSort; if (!S.cfg.backendUrl || !_sId) return null;
if (t.albumArtistSort) document.getElementById('ie-albumartistsort').value = t.albumArtistSort; const p = new URLSearchParams({ ndUrl: S.cfg.url, user: S.cfg.user, pass: S.cfg.pass, songId: _sId });
if (t.albumSort) document.getElementById('ie-albumsort').value = t.albumSort; return fetch(`${S.cfg.backendUrl}/api/song-sorttags?${p}`).then(r => r.ok ? r.json() : null).catch(() => null);
}).catch(() => {}); }).then(t => {
} if (!t) return;
if (t.titleSort) document.getElementById('ie-titlesort').value = t.titleSort;
if (t.artistSort) document.getElementById('ie-artistsort').value = t.artistSort;
if (t.albumArtistSort) document.getElementById('ie-albumartistsort').value = t.albumArtistSort;
if (t.albumSort) document.getElementById('ie-albumsort').value = t.albumSort;
}).catch(() => {});
// Art preview — use existing cover // Art preview — use existing cover
const cv = coverUrl(s.coverArt, 200); const cv = coverUrl(s.coverArt, 200);