fix: preserve manual checkbox state across filter toggles; sort on re-filter
Bug 1 (nezreka review): _applyAllFilters was restoring checkboxes from data-initially-checked (stamped once at render) rather than the user's last explicit choice, so manually unchecked albums would flip back to checked after any filter toggle. Fix: stamp data-user-checked via a new _onDiscogCardChange handler on every manual change, and restore from that attribute when it's present. Bug 2 (nezreka review): _resortGrid moved cards to the correct grid but left them in DOM order, so cards returning from the deselected section landed at the end regardless of active sort. Fix: re-apply sortDiscogGrid at the end of _resortGrid. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
3944f7900d
commit
060d7c2b1c
1 changed files with 10 additions and 2 deletions
|
|
@ -2521,7 +2521,7 @@ function _renderDiscogCard(release, index, completionData) {
|
|||
data-year="${year || '0'}" data-name="${albumName.toLowerCase().replace(/"/g, '"')}"
|
||||
data-variants="${_detectReleaseVariants(albumName).join(' ')}" data-initially-checked="${!isOwned}"
|
||||
style="animation-delay:${index * 0.03}s">
|
||||
<input type="checkbox" class="discog-card-cb" data-album-id="${release.id}" data-album-name="${_esc(albumName)}" data-tracks="${tracks}" ${checked ? 'checked' : ''} onchange="_updateDiscogFooterCount()">
|
||||
<input type="checkbox" class="discog-card-cb" data-album-id="${release.id}" data-album-name="${_esc(albumName)}" data-tracks="${tracks}" ${checked ? 'checked' : ''} onchange="_onDiscogCardChange(this)">
|
||||
<div class="discog-card-art">
|
||||
${img ? `<img src="${img}" alt="" loading="lazy">` : '<div class="discog-card-art-placeholder">🎵</div>'}
|
||||
${statusIcon ? `<span class="discog-card-status">${statusIcon}</span>` : ''}
|
||||
|
|
@ -2712,7 +2712,7 @@ function _applyAllFilters() {
|
|||
} else if (!shouldFilter && card.dataset.filterOff === 'true') {
|
||||
card.dataset.filterOff = '';
|
||||
card.classList.remove('discog-card--filtered');
|
||||
if (cb) cb.checked = card.dataset.initiallyChecked === 'true';
|
||||
if (cb) cb.checked = 'userChecked' in card.dataset ? card.dataset.userChecked === 'true' : card.dataset.initiallyChecked === 'true';
|
||||
}
|
||||
});
|
||||
_resortGrid();
|
||||
|
|
@ -2735,6 +2735,8 @@ function _resortGrid() {
|
|||
if (deselectedSection) deselectedSection.style.display = count > 0 ? '' : 'none';
|
||||
const countEl = document.getElementById('discog-deselected-count');
|
||||
if (countEl) countEl.textContent = count;
|
||||
const sortVal = document.querySelector('.discog-sort-select')?.value;
|
||||
if (sortVal) sortDiscogGrid(sortVal);
|
||||
}
|
||||
|
||||
function toggleDeselectedSection() {
|
||||
|
|
@ -2780,6 +2782,12 @@ function _updateSelectToggleBtn() {
|
|||
btn.textContent = allChecked ? 'Deselect All' : 'Select All';
|
||||
}
|
||||
|
||||
function _onDiscogCardChange(cb) {
|
||||
const card = cb.closest('.discog-card');
|
||||
if (card) card.dataset.userChecked = cb.checked;
|
||||
_updateDiscogFooterCount();
|
||||
}
|
||||
|
||||
function _updateDiscogFooterCount() {
|
||||
let releases = 0, tracks = 0;
|
||||
document.querySelectorAll('.discog-card-cb:checked').forEach(cb => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue