overleaf/services/web/frontend/js/features/editor-left-menu/hooks/use-set-spell-check-language.tsx
M Fahru 56395d9a95 Save spellCheckLanguage to both project-wide and user-wide setting
GitOrigin-RevId: 059cc64d0fe2e955814a7192f82d4ff8ea4e2572
2023-01-11 09:07:16 +00:00

25 lines
938 B
TypeScript

import { useCallback } from 'react'
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) {
setSpellCheckLanguageScope(spellCheckLanguage)
// save to both project setting and user setting
saveProjectSettings(projectId, { spellCheckLanguage })
saveUserSettings({ spellCheckLanguage })
}
},
[projectId, setSpellCheckLanguageScope, spellCheckLanguageScope]
)
return setSpellCheckLanguage
}