2023-11-21 09:29:44 -05:00
|
|
|
import { useUserSettingsContext } from '@/shared/context/user-settings-context'
|
2022-12-23 18:43:26 -05:00
|
|
|
import { saveUserSettings } from '../utils/api'
|
2023-11-21 09:29:44 -05:00
|
|
|
import { UserSettings } from '../../../../../types/user-settings'
|
2022-12-23 18:43:26 -05:00
|
|
|
|
|
|
|
export default function useSaveUserSettings() {
|
2023-11-21 09:29:44 -05:00
|
|
|
const { userSettings, setUserSettings } = useUserSettingsContext()
|
2022-12-23 18:43:26 -05:00
|
|
|
|
2023-01-03 12:41:47 -05:00
|
|
|
return (
|
2023-01-04 07:17:50 -05:00
|
|
|
key: keyof UserSettings,
|
|
|
|
newSetting: UserSettings[keyof UserSettings]
|
2022-12-28 11:38:19 -05:00
|
|
|
) => {
|
2023-01-04 07:17:50 -05:00
|
|
|
const currentSetting = userSettings[key]
|
2022-12-23 18:43:26 -05:00
|
|
|
|
|
|
|
if (currentSetting !== newSetting) {
|
2023-01-04 07:17:50 -05:00
|
|
|
setUserSettings({ ...userSettings, [key]: newSetting })
|
2023-01-06 09:29:03 -05:00
|
|
|
saveUserSettings(key, newSetting)
|
2022-12-23 18:43:26 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|