2023-11-21 09:29:44 -05:00
|
|
|
import type { 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-09-27 05:45:49 -04:00
|
|
|
import { debugConsole } from '@/utils/debugging'
|
2023-11-21 09:29:44 -05:00
|
|
|
import { UserSettings } from '../../../../../types/user-settings'
|
2022-12-23 18:06:19 -05:00
|
|
|
|
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
|
2023-09-28 12:36:08 -04:00
|
|
|
name: string
|
2022-12-28 12:02:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
},
|
2023-09-27 05:45:49 -04:00
|
|
|
}).catch(debugConsole.error)
|
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
|
|
|
})
|
|
|
|
}
|