mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
12f5c845b4
GitOrigin-RevId: 7732b6782cd1e0130eb56f6b674c03548b8e8315
26 lines
828 B
TypeScript
26 lines
828 B
TypeScript
import useScopeValue from '../../../shared/hooks/use-scope-value'
|
|
import { sendMB } from '../../../infrastructure/event-tracking'
|
|
import { saveUserSettings } from '../utils/api'
|
|
import type { UserSettingsScope } from '../utils/api'
|
|
|
|
export default function useSaveUserSettings() {
|
|
const [userSettingsScope, setUserSettingsScope] =
|
|
useScopeValue<UserSettingsScope>('settings', true)
|
|
|
|
return (
|
|
key: keyof UserSettingsScope,
|
|
newSetting: UserSettingsScope[keyof UserSettingsScope]
|
|
) => {
|
|
const currentSetting = userSettingsScope[key]
|
|
|
|
sendMB('setting-changed', {
|
|
changedSetting: key,
|
|
changedSettingVal: newSetting,
|
|
})
|
|
|
|
if (currentSetting !== newSetting) {
|
|
setUserSettingsScope({ ...userSettingsScope, [key]: newSetting })
|
|
saveUserSettings({ [key]: newSetting })
|
|
}
|
|
}
|
|
}
|