2023-01-03 13:27:29 -05:00
|
|
|
import type {
|
2022-12-23 18:06:19 -05:00
|
|
|
FontFamily,
|
|
|
|
LineHeight,
|
|
|
|
OverallTheme,
|
|
|
|
} from '../../../../../modules/source-editor/frontend/js/extensions/theme'
|
2023-01-03 13:27:29 -05:00
|
|
|
import type {
|
2022-12-27 14:54:21 -05:00
|
|
|
Keybindings,
|
|
|
|
PdfViewer,
|
|
|
|
ProjectCompiler,
|
|
|
|
} from '../../../../../types/project-settings'
|
2023-01-06 09:29:03 -05:00
|
|
|
import { sendMB } from '../../../infrastructure/event-tracking'
|
2022-12-23 18:06:19 -05:00
|
|
|
import { postJSON } from '../../../infrastructure/fetch-json'
|
|
|
|
|
2023-01-04 07:17:50 -05:00
|
|
|
export type UserSettings = {
|
2022-12-23 18:06:19 -05:00
|
|
|
pdfViewer: PdfViewer
|
|
|
|
autoComplete: boolean
|
|
|
|
autoPairDelimiters: boolean
|
|
|
|
syntaxValidation: boolean
|
|
|
|
editorTheme: string
|
|
|
|
overallTheme: OverallTheme
|
|
|
|
mode: Keybindings
|
|
|
|
fontSize: string
|
|
|
|
fontFamily: FontFamily
|
|
|
|
lineHeight: LineHeight
|
|
|
|
}
|
|
|
|
|
2023-01-04 07:17:50 -05:00
|
|
|
export type ProjectSettings = {
|
2022-12-28 12:02:43 -05:00
|
|
|
compiler: ProjectCompiler
|
|
|
|
imageName: string
|
2023-01-03 17:33:31 -05:00
|
|
|
rootDocId: string
|
2022-12-28 12:02:43 -05:00
|
|
|
spellCheckLanguage: string
|
|
|
|
}
|
|
|
|
|
|
|
|
type SaveUserSettings = Partial<
|
2023-01-04 07:17:50 -05:00
|
|
|
UserSettings & {
|
|
|
|
spellCheckLanguage: ProjectSettings['spellCheckLanguage']
|
2022-12-28 12:02:43 -05:00
|
|
|
}
|
|
|
|
>
|
|
|
|
|
2023-01-06 09:29:03 -05:00
|
|
|
export function saveUserSettings(
|
|
|
|
key: keyof SaveUserSettings,
|
|
|
|
value: SaveUserSettings[keyof SaveUserSettings]
|
|
|
|
) {
|
|
|
|
sendMB('setting-changed', {
|
|
|
|
changedSetting: key,
|
|
|
|
changedSettingVal: value,
|
|
|
|
})
|
|
|
|
|
2022-12-23 18:06:19 -05:00
|
|
|
postJSON('/user/settings', {
|
2023-01-04 07:20:58 -05:00
|
|
|
body: {
|
2023-01-06 09:29:03 -05:00
|
|
|
[key]: value,
|
2023-01-04 07:20:58 -05:00
|
|
|
},
|
2022-12-23 18:06:19 -05:00
|
|
|
})
|
|
|
|
}
|
2022-12-27 14:54:21 -05:00
|
|
|
|
2023-01-06 20:45:37 -05:00
|
|
|
export const saveProjectSettings = async (
|
|
|
|
projectId: string,
|
|
|
|
data: Partial<ProjectSettings>
|
|
|
|
) => {
|
2022-12-27 14:54:21 -05:00
|
|
|
await postJSON<never>(`/project/${projectId}/settings`, {
|
2023-01-04 07:20:58 -05:00
|
|
|
body: {
|
|
|
|
...data,
|
|
|
|
},
|
2022-12-27 14:54:21 -05:00
|
|
|
})
|
|
|
|
}
|