2022-12-23 18:06:19 -05:00
|
|
|
import {
|
|
|
|
FontFamily,
|
|
|
|
LineHeight,
|
|
|
|
OverallTheme,
|
|
|
|
} from '../../../../../modules/source-editor/frontend/js/extensions/theme'
|
2022-12-27 14:54:21 -05:00
|
|
|
import {
|
|
|
|
Keybindings,
|
|
|
|
PdfViewer,
|
|
|
|
ProjectCompiler,
|
|
|
|
} from '../../../../../types/project-settings'
|
2022-12-23 18:06:19 -05:00
|
|
|
import { postJSON } from '../../../infrastructure/fetch-json'
|
|
|
|
|
|
|
|
export type UserSettingsScope = {
|
|
|
|
pdfViewer: PdfViewer
|
|
|
|
autoComplete: boolean
|
|
|
|
autoPairDelimiters: boolean
|
|
|
|
syntaxValidation: boolean
|
|
|
|
editorTheme: string
|
|
|
|
overallTheme: OverallTheme
|
|
|
|
mode: Keybindings
|
|
|
|
fontSize: string
|
|
|
|
fontFamily: FontFamily
|
|
|
|
lineHeight: LineHeight
|
|
|
|
}
|
|
|
|
|
|
|
|
export function saveUserSettings(data: Partial<UserSettingsScope>) {
|
|
|
|
postJSON('/user/settings', {
|
2022-12-27 15:04:32 -05:00
|
|
|
body: {
|
|
|
|
_csrf: window.csrfToken,
|
|
|
|
...data,
|
|
|
|
},
|
2022-12-23 18:06:19 -05:00
|
|
|
})
|
|
|
|
}
|
2022-12-27 14:54:21 -05:00
|
|
|
|
|
|
|
export type ProjectSettingsScope = {
|
|
|
|
compiler: ProjectCompiler
|
|
|
|
imageName: string
|
|
|
|
rootDoc_id: string
|
|
|
|
spellCheckLanguage: string
|
|
|
|
}
|
|
|
|
|
2022-12-27 15:16:19 -05:00
|
|
|
// server asks for "rootDocId" but client has "rootDoc_id"
|
|
|
|
type ProjectSettingsRequestBody = Partial<
|
|
|
|
Omit<ProjectSettingsScope, 'rootDoc_id'> & {
|
|
|
|
rootDocId: string
|
|
|
|
}
|
|
|
|
>
|
|
|
|
|
2022-12-27 14:54:21 -05:00
|
|
|
export const saveProjectSettings = async (
|
|
|
|
projectId: string,
|
|
|
|
data: Partial<ProjectSettingsScope>
|
|
|
|
) => {
|
2022-12-27 15:16:19 -05:00
|
|
|
let reqData: ProjectSettingsRequestBody = {}
|
|
|
|
|
|
|
|
if (data.rootDoc_id) {
|
|
|
|
const val = data.rootDoc_id
|
|
|
|
delete data.rootDoc_id
|
|
|
|
reqData = {
|
|
|
|
...data,
|
|
|
|
rootDocId: val,
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
reqData = data
|
|
|
|
}
|
|
|
|
|
2022-12-27 14:54:21 -05:00
|
|
|
await postJSON<never>(`/project/${projectId}/settings`, {
|
2022-12-27 15:04:32 -05:00
|
|
|
body: {
|
|
|
|
_csrf: window.csrfToken,
|
2022-12-27 15:16:19 -05:00
|
|
|
...reqData,
|
2022-12-27 15:04:32 -05:00
|
|
|
},
|
2022-12-27 14:54:21 -05:00
|
|
|
})
|
|
|
|
}
|