re-swap table after refresh for consistent in-place updates
Release Please / release-please (push) Failing after 44s
Release Please / docker (push) Has been skipped

This commit was merged in pull request #9.
This commit is contained in:
Samuel Enocsson
2026-05-21 16:11:32 +02:00
parent b6c674e4c7
commit 15adddc2f1
+9 -5
View File
@@ -135,17 +135,21 @@ async function clearCache() {
} }
} }
// Refreshes both the current rating and the prediction in one click. // Refreshes both the current rating and the prediction in one click, then
// The single refresh button in the actions cell is wired to this wrapper // re-swaps the table so every derived value (deltas, pills, sparkline) reflects
// (design has only one icon; we used to have two separate refresh buttons). // the new state. Cheaper than fine-grained DOM updates and guaranteed consistent
// because the server renders the truth.
async function refreshPlayerData(pdgaNumber) { async function refreshPlayerData(pdgaNumber) {
const icon = document.querySelector(`#row-${pdgaNumber} .cell-actions .refresh-icon`); const icon = document.querySelector(`#row-${pdgaNumber} .cell-actions .refresh-icon`);
if (icon) icon.classList.add('spinning'); if (icon) icon.classList.add('spinning');
try { try {
await Promise.allSettled([ await Promise.allSettled([
refreshPlayer(pdgaNumber), fetch(`/api/refresh-player/${pdgaNumber}`, { method: 'POST' }),
refreshRoundHistory(pdgaNumber) fetch(`/api/refresh-round-history/${pdgaNumber}`, { method: 'POST' })
]); ]);
htmx.ajax('GET', '/partials/ratings-table', { target: '#ratings-table', swap: 'innerHTML' });
} catch (error) {
console.error('Error refreshing player data:', error);
} finally { } finally {
if (icon) icon.classList.remove('spinning'); if (icon) icon.classList.remove('spinning');
} }