feat: add refresh button to mobile player card (#26)
This commit is contained in:
+10
-4
@@ -131,10 +131,16 @@ async function clearCache() {
|
||||
// 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.
|
||||
// because the server renders the truth. The mobile cards partial is included
|
||||
// inside ratings-table, so swapping #ratings-table re-renders both views at once.
|
||||
async function refreshPlayerData(pdgaNumber) {
|
||||
const icon = document.querySelector(`#row-${pdgaNumber} .cell-actions .refresh-icon`);
|
||||
if (icon) icon.classList.add('spinning');
|
||||
// The desktop row exists in the DOM even on mobile (hidden via CSS), so spin
|
||||
// both possible icons; only the one visible in the active viewport is seen.
|
||||
const icons = [
|
||||
document.querySelector(`#row-${pdgaNumber} .cell-actions .refresh-icon`),
|
||||
document.querySelector(`#m-card-${pdgaNumber} .m-refresh-icon`)
|
||||
].filter(Boolean);
|
||||
icons.forEach(icon => icon.classList.add('spinning'));
|
||||
try {
|
||||
await Promise.allSettled([
|
||||
fetch(`/api/refresh-player/${pdgaNumber}`, { method: 'POST' }),
|
||||
@@ -144,7 +150,7 @@ async function refreshPlayerData(pdgaNumber) {
|
||||
} catch (error) {
|
||||
console.error('Error refreshing player data:', error);
|
||||
} finally {
|
||||
if (icon) icon.classList.remove('spinning');
|
||||
icons.forEach(icon => icon.classList.remove('spinning'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user