overleaf-cep/services/web/frontend/js/features/editor-left-menu/utils/api.ts
Tim Down 905cc5d45f Move project context out of scope value store (#26615)
* Refactor project context to not use scope store

* Fix Cypress tests for project context changes

* Fix frontend React Testing Library tests for project context changes

* Remove redundant code

* Fix some project types in tests

* Remove unused import and fix a type

* Throw an error if updating the project in the project context before joining the project

* Fix some review panel tests

* Remove unused imports

GitOrigin-RevId: 2f0c928b651f387aa980c29aef7d1ba0649790a7
2025-07-10 08:06:31 +00:00

46 lines
1.1 KiB
TypeScript

import type { ProjectCompiler } from '../../../../../types/project-settings'
import { sendMB } from '../../../infrastructure/event-tracking'
import { postJSON } from '../../../infrastructure/fetch-json'
import { debugConsole } from '@/utils/debugging'
import { UserSettings } from '../../../../../types/user-settings'
export interface ProjectSettings {
compiler: ProjectCompiler
imageName: string
rootDocId: string
spellCheckLanguage: string
name: string
}
type SaveUserSettings = Partial<
UserSettings & {
spellCheckLanguage: ProjectSettings['spellCheckLanguage']
}
>
export function saveUserSettings(
key: keyof SaveUserSettings,
value: SaveUserSettings[keyof SaveUserSettings]
) {
sendMB('setting-changed', {
changedSetting: key,
changedSettingVal: value,
})
postJSON('/user/settings', {
body: {
[key]: value,
},
}).catch(debugConsole.error)
}
export const saveProjectSettings = async (
projectId: string,
data: Partial<ProjectSettings>
) => {
await postJSON<never>(`/project/${projectId}/settings`, {
body: {
...data,
},
})
}