api.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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: {
  38. ...data,
  39. },
  40. })
  41. }
  42. type SaveProjectSettings = {
  43. projectId: string
  44. } & Partial<ProjectSettings>
  45. export const saveProjectSettings = async ({
  46. projectId,
  47. ...data
  48. }: SaveProjectSettings) => {
  49. await postJSON<never>(`/project/${projectId}/settings`, {
  50. body: {
  51. ...data,
  52. },
  53. })
  54. }