Skip to content

Commit 4e13a94

Browse files
spoons-and-mirrorsopencode
andcommitted
Show '-' in table while loading vote/download counts
- Display '-' immediately on page load while fetching API data - Replace with actual counts when API responds - Fall back to '0' on API error 🤖 Generated with [opencode](https://opencode.ai) Co-Authored-By: opencode <[email protected]>
1 parent f7bea7f commit 4e13a94

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

packages/openmodes/src/index.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,14 +676,22 @@ function setupEventListeners() {
676676

677677
// Load current vote/download data and update table
678678
async function updateTableCounts() {
679+
// First, set all counts to "-" while loading
680+
const rows = document.querySelectorAll('.mode-row');
681+
rows.forEach((row: Element) => {
682+
const votesCell = row.querySelector('.votes');
683+
const downloadsCell = row.querySelector('.downloads');
684+
if (votesCell) votesCell.textContent = '-';
685+
if (downloadsCell) downloadsCell.textContent = '-';
686+
});
687+
679688
try {
680689
const response = await fetch('/mode/index');
681690
if (!response.ok) return;
682691

683692
const modesIndex = await response.json();
684693

685694
// Update each table row with current counts
686-
const rows = document.querySelectorAll('.mode-row');
687695
rows.forEach((row: Element) => {
688696
const modeId = (row as HTMLElement).dataset.modeId;
689697
if (modeId && modesIndex[modeId]) {
@@ -700,6 +708,13 @@ async function updateTableCounts() {
700708
});
701709
} catch (error) {
702710
console.warn('Failed to update table counts:', error);
711+
// On error, revert to showing 0s
712+
rows.forEach((row: Element) => {
713+
const votesCell = row.querySelector('.votes');
714+
const downloadsCell = row.querySelector('.downloads');
715+
if (votesCell && votesCell.textContent === '-') votesCell.textContent = '0';
716+
if (downloadsCell && downloadsCell.textContent === '-') downloadsCell.textContent = '0';
717+
});
703718
}
704719
}
705720

0 commit comments

Comments
 (0)