mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-30 14:34:56 -05:00
7475237170
- Change api function argument (readability) - create a new wrapper hooks for saving the project to both server-side and angular scope - Implement the new save project settings hooks on project-wide settings update - On spell check language update function, add new comment to give more context about the decision GitOrigin-RevId: 93d558d1e1d4db265a943eeb4366842430900c43
28 lines
899 B
TypeScript
28 lines
899 B
TypeScript
import { type ProjectSettings, saveProjectSettings } from '../utils/api'
|
|
import { useProjectContext } from '../../../shared/context/project-context'
|
|
import useScopeValue from '../../../shared/hooks/use-scope-value'
|
|
|
|
export default function useSaveProjectSettings() {
|
|
// projectSettings value will be undefined on mount
|
|
const [projectSettings, setProjectSettings] = useScopeValue<
|
|
ProjectSettings | undefined
|
|
>('project', true)
|
|
const { _id: projectId } = useProjectContext()
|
|
|
|
return async (
|
|
key: keyof ProjectSettings,
|
|
newSetting: ProjectSettings[keyof ProjectSettings]
|
|
) => {
|
|
if (projectSettings) {
|
|
const currentSetting = projectSettings[key]
|
|
|
|
if (currentSetting !== newSetting) {
|
|
await saveProjectSettings(projectId, {
|
|
[key]: newSetting,
|
|
})
|
|
|
|
setProjectSettings({ ...projectSettings, [key]: newSetting })
|
|
}
|
|
}
|
|
}
|
|
}
|