mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
b2cf833e9d
GitOrigin-RevId: b8eea8c8113a977f6cbe07649e1338eea8281841
40 lines
1.3 KiB
TypeScript
40 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 ProjectSettings,
|
|
saveProjectSettings,
|
|
saveUserSettings,
|
|
} from '../utils/api'
|
|
|
|
export default function useSetSpellCheckLanguage() {
|
|
const [spellCheckLanguage, setSpellCheckLanguage] = useScopeValue<
|
|
ProjectSettings['spellCheckLanguage']
|
|
>('project.spellCheckLanguage')
|
|
const { _id: projectId } = useProjectContext()
|
|
|
|
return useCallback(
|
|
(newSpellCheckLanguage: ProjectSettings['spellCheckLanguage']) => {
|
|
const allowUpdate =
|
|
newSpellCheckLanguage && newSpellCheckLanguage !== spellCheckLanguage
|
|
|
|
if (allowUpdate) {
|
|
sendMB('setting-changed', {
|
|
changedSetting: 'spellCheckLanguage',
|
|
changedSettingVal: newSpellCheckLanguage,
|
|
})
|
|
|
|
setSpellCheckLanguage(newSpellCheckLanguage)
|
|
|
|
// save to both project setting and user setting
|
|
saveProjectSettings({
|
|
projectId,
|
|
spellCheckLanguage: newSpellCheckLanguage,
|
|
})
|
|
saveUserSettings({ spellCheckLanguage: newSpellCheckLanguage })
|
|
}
|
|
},
|
|
[projectId, setSpellCheckLanguage, spellCheckLanguage]
|
|
)
|
|
}
|