Fix squad reveal/select bug

This commit is contained in:
Catalin Constantin Mititiuc 2025-06-16 22:41:34 -07:00
parent 5eb60c0832
commit e6c4d7647c

View File

@ -293,14 +293,6 @@ function getRecord({ dataset: { allegiance: al, number: n, squad: s }}) {
return document.querySelector(selector); return document.querySelector(selector);
} }
function deselect() {
const selected = getSelected();
if (selected) {
selected.classList.remove('selected');
}
}
function clear() { function clear() {
document.querySelectorAll('#record-sheet > *').forEach(el => { document.querySelectorAll('#record-sheet > *').forEach(el => {
//el.querySelectorAll('.squad-number').forEach(sn => sn.remove()); //el.querySelectorAll('.squad-number').forEach(sn => sn.remove());
@ -338,13 +330,13 @@ function reveal(record) {
// transformation. ScrollTo seems to create enough delay. // transformation. ScrollTo seems to create enough delay.
toSquad.style.display = 'block'; toSquad.style.display = 'block';
records.scrollTo(0, 0); records.scrollTo(0, 0);
if (toSquad[`${direction}ElementSibling`] && toSquad !== target) { if (toSquad[`${direction}ElementSibling`] && toSquad !== target) {
showSquad(toSquad, target, direction); showSquad(toSquad, target, direction);
} else { } else {
toSquad.style.transform = 'translateX(0)'; toSquad.style.transform = 'translateX(0)';
toSquad.addEventListener('transitionend', e => { toSquad.addEventListener('transitionend', e => {
record.classList.add('selected');
record.scrollIntoView({ behavior: 'smooth' }); record.scrollIntoView({ behavior: 'smooth' });
}, { once: true }); }, { once: true });
} }
@ -359,6 +351,12 @@ function reveal(record) {
record.scrollIntoView({ behavior: 'smooth' }); record.scrollIntoView({ behavior: 'smooth' });
} }
function deselect() {
const selected = getSelected();
if (selected) selected.classList.remove('selected');
}
function select(data, opts) { function select(data, opts) {
const record = data && getRecord(data); const record = data && getRecord(data);
const isSelected = record?.classList.contains('selected'); const isSelected = record?.classList.contains('selected');
@ -367,8 +365,8 @@ function select(data, opts) {
if (isSelected || !data) return; if (isSelected || !data) return;
if (opts?.revealRecord) reveal(record);
record.classList.add('selected'); record.classList.add('selected');
if (opts?.revealRecord) reveal(record);
} }
function endMove() { function endMove() {
@ -379,9 +377,11 @@ function endMove() {
const index = [...list].findIndex(s => s === selected); const index = [...list].findIndex(s => s === selected);
const next = list.length > 1 ? list[(index + 1) % list.length] : null; const next = list.length > 1 ? list[(index + 1) % list.length] : null;
selected.classList.toggle('movement-ended'); selected.classList.toggle('movement-ended');
deselect();
if (next) Observable.notify('select', next, { revealCounter: true, revealRecord: true }); if (next)
Observable.notify('select', next, { revealCounter: true, revealRecord: true });
else
deselect();
} }
} }