mirror of
https://github.com/dergigi/boris.git
synced 2026-01-05 16:04:36 +01:00
fix: prevent sliders from jumping when resetting settings
- Added debouncing (300ms) to settings auto-save - Added flag to prevent external settings updates during local editing - External updates are blocked for 500ms after save completes - Fixes issue where rapid save/subscription cycle caused sliders to jump - Settings now update smoothly when resetting to defaults
This commit is contained in:
@@ -50,8 +50,15 @@ const Settings: React.FC<SettingsProps> = ({ settings, onSave, onClose }) => {
|
||||
return migrated
|
||||
})
|
||||
const isInitialMount = useRef(true)
|
||||
const saveTimeoutRef = useRef<number | null>(null)
|
||||
const isLocallyUpdating = useRef(false)
|
||||
|
||||
useEffect(() => {
|
||||
// Don't update from external settings if we're currently making local changes
|
||||
if (isLocallyUpdating.current) {
|
||||
return
|
||||
}
|
||||
|
||||
const migrated = { ...settings }
|
||||
const anySettings = migrated as Record<string, unknown>
|
||||
if ('zapSplitPercentage' in anySettings && !('zapSplitHighlighterWeight' in migrated)) {
|
||||
@@ -82,7 +89,30 @@ const Settings: React.FC<SettingsProps> = ({ settings, onSave, onClose }) => {
|
||||
isInitialMount.current = false
|
||||
return
|
||||
}
|
||||
onSave(localSettings)
|
||||
|
||||
// Mark that we're making local updates
|
||||
isLocallyUpdating.current = true
|
||||
|
||||
// Clear any pending save
|
||||
if (saveTimeoutRef.current) {
|
||||
clearTimeout(saveTimeoutRef.current)
|
||||
}
|
||||
|
||||
// Debounce the save to avoid rapid updates
|
||||
saveTimeoutRef.current = setTimeout(() => {
|
||||
onSave(localSettings).finally(() => {
|
||||
// Allow external updates again after a short delay
|
||||
setTimeout(() => {
|
||||
isLocallyUpdating.current = false
|
||||
}, 500)
|
||||
})
|
||||
}, 300)
|
||||
|
||||
return () => {
|
||||
if (saveTimeoutRef.current) {
|
||||
clearTimeout(saveTimeoutRef.current)
|
||||
}
|
||||
}
|
||||
}, [localSettings, onSave])
|
||||
|
||||
const handleResetToDefaults = () => {
|
||||
|
||||
Reference in New Issue
Block a user