2022-12-28 12:02:43 -05:00
|
|
|
import { useCallback } from 'react'
|
2022-12-28 12:33:12 -05:00
|
|
|
import { sendMB } from '../../../infrastructure/event-tracking'
|
2022-12-28 12:02:43 -05:00
|
|
|
import { useProjectContext } from '../../../shared/context/project-context'
|
|
|
|
import useScopeValue from '../../../shared/hooks/use-scope-value'
|
|
|
|
import { saveProjectSettings, saveUserSettings } from '../utils/api'
|
|
|
|
|
2023-01-03 12:04:34 -05:00
|
|
|
export default function useSetSpellCheckLanguage() {
|
2022-12-28 12:02:43 -05:00
|
|
|
const [spellCheckLanguageScope, setSpellCheckLanguageScope] =
|
|
|
|
useScopeValue<string>('project.spellCheckLanguage')
|
|
|
|
const { _id: projectId } = useProjectContext()
|
|
|
|
|
|
|
|
const setSpellCheckLanguage = useCallback(
|
|
|
|
(spellCheckLanguage: string) => {
|
2022-12-28 15:58:14 -05:00
|
|
|
const allowUpdate =
|
2023-01-03 12:04:34 -05:00
|
|
|
spellCheckLanguage && spellCheckLanguage !== spellCheckLanguageScope
|
2022-12-28 15:58:14 -05:00
|
|
|
|
|
|
|
if (allowUpdate) {
|
2022-12-28 12:33:12 -05:00
|
|
|
sendMB('setting-changed', {
|
|
|
|
changedSetting: 'spellCheckLanguage',
|
|
|
|
changedSettingVal: spellCheckLanguage,
|
|
|
|
})
|
|
|
|
|
2022-12-28 12:02:43 -05:00
|
|
|
setSpellCheckLanguageScope(spellCheckLanguage)
|
|
|
|
|
|
|
|
// save to both project setting and user setting
|
2022-12-28 12:38:27 -05:00
|
|
|
saveProjectSettings({ projectId, spellCheckLanguage })
|
2022-12-28 12:02:43 -05:00
|
|
|
saveUserSettings({ spellCheckLanguage })
|
|
|
|
}
|
|
|
|
},
|
2023-01-03 12:04:34 -05:00
|
|
|
[projectId, setSpellCheckLanguageScope, spellCheckLanguageScope]
|
2022-12-28 12:02:43 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
return setSpellCheckLanguage
|
|
|
|
}
|