mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
ae5a08e680
GitOrigin-RevId: 04ed66dcdff7fa04e783fe4028505d981a39b37b
31 lines
1.1 KiB
TypeScript
31 lines
1.1 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 { saveProjectSettings, saveUserSettings } from '../utils/api'
|
|
|
|
export default function useSetSpellCheckLanguage() {
|
|
const [spellCheckLanguageScope, setSpellCheckLanguageScope] =
|
|
useScopeValue<string>('project.spellCheckLanguage')
|
|
const { _id: projectId } = useProjectContext()
|
|
|
|
const setSpellCheckLanguage = useCallback(
|
|
(spellCheckLanguage: string) => {
|
|
if (spellCheckLanguageScope) {
|
|
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
|
|
}
|