overleaf/services/web/frontend/js/features/editor-left-menu/utils/api.ts
M Fahru 94ab78b427 Log error in a promise catch block
GitOrigin-RevId: 09756d52bd6351c55051a74f22f38c450af9a275
2023-01-11 09:09:51 +00:00

65 lines
1.4 KiB
TypeScript

import type {
FontFamily,
LineHeight,
OverallTheme,
} from '../../../../../modules/source-editor/frontend/js/extensions/theme'
import type {
Keybindings,
PdfViewer,
ProjectCompiler,
} from '../../../../../types/project-settings'
import { sendMB } from '../../../infrastructure/event-tracking'
import { postJSON } from '../../../infrastructure/fetch-json'
export type UserSettings = {
pdfViewer: PdfViewer
autoComplete: boolean
autoPairDelimiters: boolean
syntaxValidation: boolean
editorTheme: string
overallTheme: OverallTheme
mode: Keybindings
fontSize: string
fontFamily: FontFamily
lineHeight: LineHeight
}
export type ProjectSettings = {
compiler: ProjectCompiler
imageName: string
rootDocId: string
spellCheckLanguage: 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(console.error)
}
export const saveProjectSettings = async (
projectId: string,
data: Partial<ProjectSettings>
) => {
await postJSON<never>(`/project/${projectId}/settings`, {
body: {
...data,
},
})
}