Extract reveal record logic into a function

This commit is contained in:
Catalin Constantin Mititiuc 2024-08-07 11:03:14 -07:00
parent 0ff2d23093
commit 39c939ebaf

View File

@ -252,14 +252,7 @@ function clear() {
//document.querySelector('#defender-record .name').textContent = 'defender'; //document.querySelector('#defender-record .name').textContent = 'defender';
} }
function select(data) { function reveal(record) {
const record = data && getRecord(data);
const isSelected = record?.classList.contains('selected');
deselect();
if (isSelected || !data) return;
const currentSquadView = document.querySelector(`#record-sheet #${record.dataset.allegiance}-record .records-header .squad-number text`); const currentSquadView = document.querySelector(`#record-sheet #${record.dataset.allegiance}-record .records-header .squad-number text`);
const records = document.querySelector(`#record-sheet #${record.dataset.allegiance}-record .records`); const records = document.querySelector(`#record-sheet #${record.dataset.allegiance}-record .records`);
const target = records.querySelector(`.squad-${record.dataset.squad}`); const target = records.querySelector(`.squad-${record.dataset.squad}`);
@ -302,10 +295,20 @@ function select(data) {
if (currentSquad !== target) if (currentSquad !== target)
showSquad(currentSquad, target, direction); showSquad(currentSquad, target, direction);
else { else
record.classList.add('selected');
record.scrollIntoView({ behavior: 'smooth' }); record.scrollIntoView({ behavior: 'smooth' });
} }
function select(data) {
const record = data && getRecord(data);
const isSelected = record?.classList.contains('selected');
deselect();
if (isSelected || !data) return;
reveal(record);
record.classList.add('selected');
} }
function endMove() { function endMove() {