fix: add debug toggle as draggable mobile FAB button

PROBLEM:
- Debug logs only accessible via browser console (impractical on mobile)
- User (Salixfire) reporting parsing issues but can't debug on mobile device
- Need mobile-friendly debug mode for troubleshooting data display issues

SOLUTION:
Implemented debug toggle FAB button following exact pattern of existing mobile FABs:

Files Changed:
- src/core/state.js: Added debugFabPosition and debugMode to extensionSettings
- src/core/config.js: Added debugFabPosition to defaultSettings (reference)
- index.js: Created debug toggle button, imported setupDebugButtonDrag
- style.css: Added debug toggle CSS matching mobile FAB pattern (44px, grab cursor, theme colors)
- src/systems/ui/mobile.js: Added setupDebugButtonDrag() with drag-to-reposition
- src/systems/ui/debug.js: Removed button creation, added just-dragged check, updated visibility control

Implementation Details:
- Button created in index.js (not debug.js) following mobile FAB pattern
- CSS matches mobile toggle/refresh buttons (44px, theme colors, grab cursor, user-select: none)
- Drag support with touch/mouse handlers, 200ms/10px threshold
- Position saved to extensionSettings.debugFabPosition
- Just-dragged flag prevents accidental clicks after drag
- Mobile (≤1000px): slide from right with rpg-mobile-open/closing classes
- Desktop (>1000px): slide from bottom with rpg-debug-open class
- Event delegation for reliable click handling
- Default position: bottom 140px, left 20px (below other FABs)

Bug Fix:
- Initial implementation had debugFabPosition only in config.js
- extensionSettings uses state.js as source, not config.js
- Without debugFabPosition in state.js, button had no position and was invisible
- Now properly initialized in both files

The debug button is hidden by default (debugMode: false) and shown when user enables debug mode in RPG Companion settings. This allows Salixfire to view parser logs on mobile and troubleshoot the data display issues.
This commit is contained in:
Lucas 'Paperboy' Rose-Winters
2025-10-22 08:29:58 +11:00
parent 44240e6840
commit d4491a4705
6 changed files with 402 additions and 46 deletions
+11 -1
View File
@@ -99,7 +99,8 @@ import {
removeMobileTabs,
setupMobileKeyboardHandling,
setupContentEditableScrolling,
setupRefreshButtonDrag
setupRefreshButtonDrag,
setupDebugButtonDrag
} from './src/systems/ui/mobile.js';
import {
setupDesktopTabs,
@@ -221,6 +222,14 @@ async function initUI() {
`;
$('body').append(mobileRefreshHtml);
// Add debug toggle FAB button (same pattern as other mobile FABs)
const debugToggleHtml = `
<button id="rpg-debug-toggle" class="rpg-debug-toggle" title="Toggle Debug Logs">
<i class="fa-solid fa-bug"></i>
</button>
`;
$('body').append(debugToggleHtml);
// Cache UI elements using state setters
setPanelContainer($('#rpg-companion-panel'));
setUserStatsContainer($('#rpg-user-stats'));
@@ -464,6 +473,7 @@ async function initUI() {
setupMobileKeyboardHandling();
setupContentEditableScrolling();
setupRefreshButtonDrag();
setupDebugButtonDrag();
initInventoryEventListeners();
// Initialize debug UI if debug mode is enabled