mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
38efea39f2
Move user settings to a context GitOrigin-RevId: 9a9d55dfee9f71cee323fe64d1442303ac7cfeb2
46 lines
1.1 KiB
TypeScript
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 type 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,
|
|
},
|
|
})
|
|
}
|