overleaf/services/web/frontend/js/features/editor-left-menu/hooks/use-save-user-settings.tsx
Tim Down 38efea39f2 Merge pull request #15707 from overleaf/td-user-settings-context
Move user settings to a context

GitOrigin-RevId: 9a9d55dfee9f71cee323fe64d1442303ac7cfeb2
2023-11-22 09:04:39 +00:00

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)
}
}
}