mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
38efea39f2
Move user settings to a context GitOrigin-RevId: 9a9d55dfee9f71cee323fe64d1442303ac7cfeb2
19 lines
612 B
TypeScript
19 lines
612 B
TypeScript
import { useUserSettingsContext } from '@/shared/context/user-settings-context'
|
|
import { saveUserSettings } from '../utils/api'
|
|
import { UserSettings } from '../../../../../types/user-settings'
|
|
|
|
export default function useSaveUserSettings() {
|
|
const { userSettings, setUserSettings } = useUserSettingsContext()
|
|
|
|
return (
|
|
key: keyof UserSettings,
|
|
newSetting: UserSettings[keyof UserSettings]
|
|
) => {
|
|
const currentSetting = userSettings[key]
|
|
|
|
if (currentSetting !== newSetting) {
|
|
setUserSettings({ ...userSettings, [key]: newSetting })
|
|
saveUserSettings(key, newSetting)
|
|
}
|
|
}
|
|
}
|