mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
4bf09e21de
GitOrigin-RevId: 11ef7ab4111c7b312b283283829e9b28a80c475c
20 lines
673 B
TypeScript
20 lines
673 B
TypeScript
import useScopeValue from '../../../shared/hooks/use-scope-value'
|
|
import { saveUserSettings } from '../utils/api'
|
|
import type { UserSettingsScope } from '../utils/api'
|
|
|
|
export default function useSaveUserSettings() {
|
|
const [userSettingsScope, setUserSettingsScope] =
|
|
useScopeValue<UserSettingsScope>('settings', true)
|
|
|
|
return <T extends UserSettingsScope[keyof UserSettingsScope]>(
|
|
key: keyof UserSettingsScope,
|
|
newSetting: T
|
|
) => {
|
|
const currentSetting = userSettingsScope[key]
|
|
|
|
if (currentSetting !== newSetting) {
|
|
setUserSettingsScope({ ...userSettingsScope, [key]: newSetting })
|
|
saveUserSettings({ [key]: newSetting })
|
|
}
|
|
}
|
|
}
|