overleaf/services/web/frontend/js/features/editor-left-menu/utils/api.ts
Tim Down 7f37ba737c Move source editor out of module (#12457)
* Update Copybara options in preparation for open-sourcing the source editor

* Move files

* Update paths

* Remove source-editor module and checks for its existence

* Explicitly mention CM6 license in files that contain code adapted from CM6

GitOrigin-RevId: 89b7cc2b409db01ad103198ccbd1b126ab56349b
2023-04-13 08:40:56 +00:00

65 lines
1.4 KiB
TypeScript

import type {
FontFamily,
LineHeight,
OverallTheme,
} from '../../source-editor/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,
},
})
}