Skip to content

Commit

Permalink
check if block counter out of sync before checking if history is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
kheina committed Jul 1, 2023
1 parent 3680c90 commit fbc6948
Showing 1 changed file with 31 additions and 33 deletions.
64 changes: 31 additions & 33 deletions src/pages/history/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,46 +30,44 @@ blockCounter.getCriticalPoint(refid)
e.innerText = commafy(users.length)
);

blockCounter.getCriticalPoint(refid)
.then(() => blockCounter.storage.get({ BlockCounter: 0 }))
.then(items => items.BlockCounter as number)
.then(count => {
if (users.length === count) {
return;
}

const blockCounterCurrentValue = document.getElementById("block-counter-current-value") as HTMLElement;
blockCounterCurrentValue.innerText = commafy(count);

const resetCounter = document.getElementById("reset-counter") as HTMLElement;
const a = resetCounter.firstElementChild as HTMLElement;
a.addEventListener("click", () => {
const refid = RefId();
blockCounter.getCriticalPoint(refid)
.then(() =>
blockCounter.storage.set({ BlockCounter: users.length })
).then(() => {
console.log(logstr, "reset block counter to", users.length);
resetCounter.style.display = "";
}).finally(() =>
blockCounter.releaseCriticalPoint(refid)
);
});

resetCounter.style.display = "block";
}).finally(() =>
blockCounter.releaseCriticalPoint(refid)
);

if (users.length === 0) {
queueDiv.textContent = "your block history is empty";
return;
}

queueDiv.innerHTML = "";

(() => {
blockCounter.getCriticalPoint(refid)
.then(() => blockCounter.storage.get({ BlockCounter: 0 }))
.then(items => items.BlockCounter as number)
.then((count) => {
if (users.length === count) {
return;
}

const blockCounterCurrentValue = document.getElementById("block-counter-current-value") as HTMLElement;
blockCounterCurrentValue.innerText = commafy(count);

const resetCounter = document.getElementById("reset-counter") as HTMLElement;
const a = resetCounter.firstElementChild as HTMLElement;
a.addEventListener("click", () => {
const refid = RefId();
blockCounter.getCriticalPoint(refid)
.then(() =>
blockCounter.storage.set({ BlockCounter: users.length })
).then(() => {
console.log(logstr, "reset block counter to", users.length);
resetCounter.style.display = "";
}).finally(() =>
blockCounter.releaseCriticalPoint(refid)
);
});

resetCounter.style.display = "block";
}).finally(() =>
blockCounter.releaseCriticalPoint(refid)
);
})();

const reasons: { [r: number]: number } = { };
users.reverse().forEach(item => {
if (!reasons.hasOwnProperty(item.reason)) {
Expand Down

0 comments on commit fbc6948

Please sign in to comment.