// Watchlist Scan History modal (#831 round 2).
//
// Every scan run is persisted server-side (watchlist_scan_runs) with its full
// track ledger — the tracks the run ADDED to the wishlist plus the found-but-
// skipped ones. This modal lists past runs (newest first) and expands each
// into its ledger. Note: this is what the watchlist PUT IN THE WISHLIST — the
// watchlist never downloads; downloaded tracks live in Download Origins.
let _wlhModalEl = null;
let _wlhRuns = [];
const _wlhEventsCache = new Map();
function openWatchlistHistoryModal() {
if (!_wlhModalEl) {
_wlhModalEl = document.createElement('div');
_wlhModalEl.className = 'modal-overlay origin-modal-overlay';
_wlhModalEl.innerHTML = `
Scan History
Every watchlist scan and the tracks it added to your wishlist.
`;
_wlhModalEl.addEventListener('click', (e) => {
if (e.target === _wlhModalEl) closeWatchlistHistoryModal();
});
document.body.appendChild(_wlhModalEl);
}
_wlhModalEl.classList.remove('hidden');
_wlhLoadRuns();
}
function closeWatchlistHistoryModal() {
if (_wlhModalEl) _wlhModalEl.classList.add('hidden');
}
async function _wlhLoadRuns() {
const body = document.getElementById('wlh-modal-body');
body.innerHTML = '
Loading…
';
try {
const resp = await fetch('/api/watchlist/scan/history?limit=50');
const data = await resp.json();
if (!data.success) throw new Error(data.error || 'Failed to load');
_wlhRuns = data.runs || [];
_wlhRenderRuns();
} catch (err) {
body.innerHTML = `
Couldn't load: ${escapeHtml(err.message)}
`;
}
}
function _wlhRenderRuns() {
const body = document.getElementById('wlh-modal-body');
if (!_wlhRuns.length) {
body.innerHTML = '
No scans recorded yet. Run a watchlist scan and it will appear here.