mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
654144dd40
GitOrigin-RevId: 77b9d8fd5cdcbc78f38fd42329b74cf592615638
22 lines
612 B
TypeScript
22 lines
612 B
TypeScript
import useScopeValue from '../../../shared/hooks/use-scope-value'
|
|
import { saveUserSettings } from '../utils/api'
|
|
import type { UserSettings } from '../utils/api'
|
|
|
|
export default function useSaveUserSettings() {
|
|
const [userSettings, setUserSettings] = useScopeValue<UserSettings>(
|
|
'settings',
|
|
true
|
|
)
|
|
|
|
return (
|
|
key: keyof UserSettings,
|
|
newSetting: UserSettings[keyof UserSettings]
|
|
) => {
|
|
const currentSetting = userSettings[key]
|
|
|
|
if (currentSetting !== newSetting) {
|
|
setUserSettings({ ...userSettings, [key]: newSetting })
|
|
saveUserSettings(key, newSetting)
|
|
}
|
|
}
|
|
}
|