mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
ae5a08e680
GitOrigin-RevId: 04ed66dcdff7fa04e783fe4028505d981a39b37b
26 lines
841 B
TypeScript
26 lines
841 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 <T extends UserSettingsScope[keyof UserSettingsScope]>(
|
|
key: keyof UserSettingsScope,
|
|
newSetting: T
|
|
) => {
|
|
const currentSetting = userSettingsScope[key]
|
|
|
|
sendMB('setting-changed', {
|
|
changedSetting: key,
|
|
changedSettingVal: newSetting,
|
|
})
|
|
|
|
if (currentSetting !== newSetting) {
|
|
setUserSettingsScope({ ...userSettingsScope, [key]: newSetting })
|
|
saveUserSettings({ [key]: newSetting })
|
|
}
|
|
}
|
|
}
|