mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
e3d0380e6f
GitOrigin-RevId: a6630bb284c456bfbe61901f7331cdd3c13c7f8b
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import { useCallback } from 'react'
|
|
import { sendMB } from '../../../infrastructure/event-tracking'
|
|
import { useProjectContext } from '../../../shared/context/project-context'
|
|
import useScopeValue from '../../../shared/hooks/use-scope-value'
|
|
import {
|
|
type ProjectSettingsScope,
|
|
saveProjectSettings,
|
|
saveUserSettings,
|
|
} from '../utils/api'
|
|
|
|
export default function useSetSpellCheckLanguage() {
|
|
const [spellCheckLanguageScope, setSpellCheckLanguageScope] = useScopeValue<
|
|
ProjectSettingsScope['spellCheckLanguage']
|
|
>('project.spellCheckLanguage')
|
|
const { _id: projectId } = useProjectContext()
|
|
|
|
const setSpellCheckLanguage = useCallback(
|
|
(spellCheckLanguage: ProjectSettingsScope['spellCheckLanguage']) => {
|
|
const allowUpdate =
|
|
spellCheckLanguage && spellCheckLanguage !== spellCheckLanguageScope
|
|
|
|
if (allowUpdate) {
|
|
sendMB('setting-changed', {
|
|
changedSetting: 'spellCheckLanguage',
|
|
changedSettingVal: spellCheckLanguage,
|
|
})
|
|
|
|
setSpellCheckLanguageScope(spellCheckLanguage)
|
|
|
|
// save to both project setting and user setting
|
|
saveProjectSettings({ projectId, spellCheckLanguage })
|
|
saveUserSettings({ spellCheckLanguage })
|
|
}
|
|
},
|
|
[projectId, setSpellCheckLanguageScope, spellCheckLanguageScope]
|
|
)
|
|
|
|
return setSpellCheckLanguage
|
|
}
|