From ea2231f6ba228431bbb655d32829e7db35ea76b3 Mon Sep 17 00:00:00 2001 From: Lucas 'Paperboy' Rose-Winters Date: Wed, 22 Oct 2025 10:47:09 +1100 Subject: [PATCH] fix: restore proper spinning animation for mobile refresh FAB Reverted HTML replacement approach and restored the cleaner CSS-based animation from commit 1855085. Previous (wrong) approach: - Replaced button HTML with spinner - Modified both desktop and mobile buttons in apiClient.js - Messy and inconsistent Restored (correct) approach: - Add/remove .spinning CSS class in click handler - CSS animates only the icon inside the button - Button itself stays unchanged - Much cleaner implementation Changes: - Reverted apiClient.js changes from commit 9a49433 - Added .spinning CSS class and @keyframes rpg-spin - Updated index.js click handler to bind both buttons - Uses addClass/removeClass for clean animation control - Includes drag detection to prevent accidental clicks Now the mobile FAB icon spins smoothly when refreshing! --- index.js | 26 ++++++++++++++++++++++++-- src/systems/generation/apiClient.js | 13 ++----------- style.css | 18 ++++++++++++++++++ 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 9c3f2de..b5ae314 100644 --- a/index.js +++ b/index.js @@ -328,12 +328,34 @@ async function initUI() { toggleAnimations(); }); - $('#rpg-manual-update').on('click', async function() { + // Bind to both desktop and mobile refresh buttons + $('#rpg-manual-update, #rpg-manual-update-mobile').on('click', async function() { + // Get mobile button reference + const $mobileBtn = $('#rpg-manual-update-mobile'); + + // Skip if we just finished dragging the mobile button + if ($mobileBtn.data('just-dragged')) { + console.log('[RPG Companion] Click blocked - just finished dragging refresh button'); + return; + } + if (!extensionSettings.enabled) { // console.log('[RPG Companion] Extension is disabled. Please enable it in the Extensions tab.'); return; } - await updateRPGData(renderUserStats, renderInfoBox, renderThoughts, renderInventory); + + // Remove focus to prevent sticky black state on mobile + $(this).blur(); + + // Add spinning animation to mobile button + $mobileBtn.addClass('spinning'); + + try { + await updateRPGData(renderUserStats, renderInfoBox, renderThoughts, renderInventory); + } finally { + // Remove spinning animation when done + $mobileBtn.removeClass('spinning'); + } }); // Reset FAB positions button diff --git a/src/systems/generation/apiClient.js b/src/systems/generation/apiClient.js index 1f72fa3..e30bec0 100644 --- a/src/systems/generation/apiClient.js +++ b/src/systems/generation/apiClient.js @@ -97,16 +97,11 @@ export async function updateRPGData(renderUserStats, renderInfoBox, renderThough try { setIsGenerating(true); - // Update desktop button to show "Updating..." state + // Update button to show "Updating..." state const $updateBtn = $('#rpg-manual-update'); const originalHtml = $updateBtn.html(); $updateBtn.html(' Updating...').prop('disabled', true); - // Update mobile FAB to show spinner (icon only) - const $updateBtnMobile = $('#rpg-manual-update-mobile'); - const originalHtmlMobile = $updateBtnMobile.html(); - $updateBtnMobile.html('').prop('disabled', true); - // Save current preset name before switching (if we're going to switch) if (extensionSettings.useSeparatePreset) { originalPresetName = await getCurrentPresetName(); @@ -224,14 +219,10 @@ export async function updateRPGData(renderUserStats, renderInfoBox, renderThough setIsGenerating(false); - // Restore desktop button to original state + // Restore button to original state const $updateBtn = $('#rpg-manual-update'); $updateBtn.html(' Refresh RPG Info').prop('disabled', false); - // Restore mobile FAB to original state (icon only) - const $updateBtnMobile = $('#rpg-manual-update-mobile'); - $updateBtnMobile.html('').prop('disabled', false); - // Reset the flag after tracker generation completes // This ensures the flag persists through both main generation AND tracker generation // console.log('[RPG Companion] 🔄 Tracker generation complete - resetting lastActionWasSwipe to false'); diff --git a/style.css b/style.css index 5b6bb8a..4499224 100644 --- a/style.css +++ b/style.css @@ -3344,6 +3344,24 @@ body:has(.rpg-panel.rpg-position-left) #sheld { transform: scale(0.95); } +/* Spinning animation when refreshing */ +.rpg-mobile-refresh.spinning i { + animation: rpg-spin 0.8s linear infinite; +} + +.rpg-mobile-refresh i { + pointer-events: none; +} + +@keyframes rpg-spin { + from { + transform: rotate(0deg); + } + to { + transform: rotate(360deg); + } +} + /* Mobile overlay backdrop */ .rpg-mobile-overlay { display: none;