api.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import type {
  2. FontFamily,
  3. LineHeight,
  4. OverallTheme,
  5. } from '../../../../../modules/source-editor/frontend/js/extensions/theme'
  6. import type {
  7. Keybindings,
  8. PdfViewer,
  9. ProjectCompiler,
  10. } from '../../../../../types/project-settings'
  11. import { postJSON } from '../../../infrastructure/fetch-json'
  12. export type UserSettings = {
  13. pdfViewer: PdfViewer
  14. autoComplete: boolean
  15. autoPairDelimiters: boolean
  16. syntaxValidation: boolean
  17. editorTheme: string
  18. overallTheme: OverallTheme
  19. mode: Keybindings
  20. fontSize: string
  21. fontFamily: FontFamily
  22. lineHeight: LineHeight
  23. }
  24. export type ProjectSettings = {
  25. compiler: ProjectCompiler
  26. imageName: string
  27. rootDocId: string
  28. spellCheckLanguage: string
  29. }
  30. type SaveUserSettings = Partial<
  31. UserSettings & {
  32. spellCheckLanguage: ProjectSettings['spellCheckLanguage']
  33. }
  34. >
  35. export function saveUserSettings(data: SaveUserSettings) {
  36. postJSON('/user/settings', {
  37. body: data,
  38. })
  39. }
  40. type SaveProjectSettings = {
  41. projectId: string
  42. } & Partial<ProjectSettings>
  43. export const saveProjectSettings = async ({
  44. projectId,
  45. ...data
  46. }: SaveProjectSettings) => {
  47. await postJSON<never>(`/project/${projectId}/settings`, {
  48. body: data,
  49. })
  50. }