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
+16 -15
+16 -15
View File
@@ -309,11 +309,7 @@ export async function showSongInfo(s) {
document.getElementById('ie-track').value = full.track || '';
document.getElementById('ie-disc').value = full.discNumber || '';
document.getElementById('ie-totaltracks').value = full.albumSongCount || '';
const _rm2 = romajiLookup(full.id);
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 || '';
// sort tags are populated by the async chain in toggleInfoEdit — no need to reset here
}
}
} catch {}
@@ -356,22 +352,27 @@ export function toggleInfoEdit() {
document.getElementById('ie-disc').value = s.discNumber || '';
document.getElementById('ie-totaltracks').value = s.albumSongCount || '';
// Sort tags — pre-fill from romaji index, then overwrite with actual file tags if backend available
const _rm = romajiLookup(s.id);
document.getElementById('ie-titlesort').value = _rm?.titleRomaji || '';
document.getElementById('ie-artistsort').value = _rm?.artistRomaji || '';
document.getElementById('ie-albumartistsort').value = _rm?.artistRomaji || '';
document.getElementById('ie-albumsort').value = _rm?.albumRomaji || '';
if (S.cfg.backendUrl && s.id) {
const p = new URLSearchParams({ ndUrl: S.cfg.url, user: S.cfg.user, pass: S.cfg.pass, songId: s.id });
fetch(`${S.cfg.backendUrl}/api/song-sorttags?${p}`).then(r => r.ok ? r.json() : null).then(t => {
// Sort tags: fetch romaji index on demand (cached if already loaded), then overwrite with
// actual file tags from backend. This works regardless of the showRomaji toggle.
const _sId = s.id;
fetchRomajiIndex().catch(() => null).then(() => {
const rm = romajiLookup(_sId);
if (rm) {
document.getElementById('ie-titlesort').value = rm.titleRomaji || '';
document.getElementById('ie-artistsort').value = rm.artistRomaji || '';
document.getElementById('ie-albumartistsort').value = rm.artistRomaji || '';
document.getElementById('ie-albumsort').value = rm.albumRomaji || '';
}
if (!S.cfg.backendUrl || !_sId) return null;
const p = new URLSearchParams({ ndUrl: S.cfg.url, user: S.cfg.user, pass: S.cfg.pass, songId: _sId });
return fetch(`${S.cfg.backendUrl}/api/song-sorttags?${p}`).then(r => r.ok ? r.json() : null).catch(() => null);
}).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
const cv = coverUrl(s.coverArt, 200);