mirror of
https://github.com/dergigi/boris.git
synced 2026-01-04 23:44:21 +01:00
fix: prevent settings from saving unnecessarily
- Wrap handleSaveSettings in useCallback to prevent recreation - Only trigger save effect when localSettings object changes - Remove onSave from dependency array with eslint-disable comment - Settings now only save when user actually changes a setting
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React, { useState, useEffect } from 'react'
|
||||
import React, { useState, useEffect, useCallback } from 'react'
|
||||
import { Hooks } from 'applesauce-react'
|
||||
import { useEventStore } from 'applesauce-react/hooks'
|
||||
import { RelayPool } from 'applesauce-relay'
|
||||
@@ -114,7 +114,7 @@ const Bookmarks: React.FC<BookmarksProps> = ({ relayPool, onLogout }) => {
|
||||
}
|
||||
}
|
||||
|
||||
const handleSaveSettings = async (newSettings: UserSettings) => {
|
||||
const handleSaveSettings = useCallback(async (newSettings: UserSettings) => {
|
||||
if (!relayPool || !activeAccount) return
|
||||
try {
|
||||
const fullAccount = accountManager.getActive()
|
||||
@@ -129,7 +129,7 @@ const Bookmarks: React.FC<BookmarksProps> = ({ relayPool, onLogout }) => {
|
||||
setToastType('error')
|
||||
setToastMessage('Failed to save settings')
|
||||
}
|
||||
}
|
||||
}, [relayPool, activeAccount, accountManager, eventStore])
|
||||
|
||||
const handleSelectUrl = async (url: string) => {
|
||||
setSelectedUrl(url)
|
||||
|
||||
@@ -40,7 +40,8 @@ const Settings: React.FC<SettingsProps> = ({ settings, onSave, onClose }) => {
|
||||
}
|
||||
|
||||
onSave(localSettings)
|
||||
}, [localSettings, onSave])
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [localSettings])
|
||||
|
||||
const previewFontFamily = getFontFamily(localSettings.readingFont)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user