diff --git a/public/js/players.js b/public/js/players.js index 2aa59fd..78503b4 100644 --- a/public/js/players.js +++ b/public/js/players.js @@ -135,17 +135,21 @@ async function clearCache() { } } -// Refreshes both the current rating and the prediction in one click. -// The single refresh button in the actions cell is wired to this wrapper -// (design has only one icon; we used to have two separate refresh buttons). +// Refreshes both the current rating and the prediction in one click, then +// re-swaps the table so every derived value (deltas, pills, sparkline) reflects +// the new state. Cheaper than fine-grained DOM updates and guaranteed consistent +// because the server renders the truth. async function refreshPlayerData(pdgaNumber) { const icon = document.querySelector(`#row-${pdgaNumber} .cell-actions .refresh-icon`); if (icon) icon.classList.add('spinning'); try { await Promise.allSettled([ - refreshPlayer(pdgaNumber), - refreshRoundHistory(pdgaNumber) + fetch(`/api/refresh-player/${pdgaNumber}`, { method: 'POST' }), + 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 { if (icon) icon.classList.remove('spinning'); }