mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 06:03:45 +01:00
Bring main bibliography file to the top level settings GitOrigin-RevId: 4c4d4927067995d947c6d0656425760ce56f9435
52 lines
1.3 KiB
TypeScript
52 lines
1.3 KiB
TypeScript
import type { ProjectCompiler } from '../../../../../types/project-settings'
|
|
import { sendMB } from '../../../infrastructure/event-tracking'
|
|
import { postJSON } from '../../../infrastructure/fetch-json'
|
|
import { debugConsole } from '@/utils/debugging'
|
|
import { UserSettings } from '../../../../../types/user-settings'
|
|
|
|
export interface ProjectSettings {
|
|
compiler: ProjectCompiler
|
|
imageName: string
|
|
// Optional: a project that has never set png2pdf sends no value, which the
|
|
// compile context treats as "no preference, use the local default".
|
|
png2pdf?: boolean
|
|
rootDocId: string
|
|
spellCheckLanguage: string
|
|
name: string
|
|
mainBibliographyDocId?: string
|
|
referenceFormat?: 'bibtex' | 'biblatex'
|
|
}
|
|
|
|
type SaveUserSettings = Partial<
|
|
UserSettings & {
|
|
spellCheckLanguage: ProjectSettings['spellCheckLanguage']
|
|
}
|
|
>
|
|
|
|
export function saveUserSettings(
|
|
key: keyof SaveUserSettings,
|
|
value: SaveUserSettings[keyof SaveUserSettings]
|
|
) {
|
|
sendMB('setting-changed', {
|
|
changedSetting: key,
|
|
changedSettingVal: value,
|
|
})
|
|
|
|
postJSON('/user/settings', {
|
|
body: {
|
|
[key]: value,
|
|
},
|
|
}).catch(debugConsole.error)
|
|
}
|
|
|
|
export const saveProjectSettings = async (
|
|
projectId: string,
|
|
data: Partial<ProjectSettings>
|
|
) => {
|
|
await postJSON<never>(`/project/${projectId}/settings`, {
|
|
body: {
|
|
...data,
|
|
},
|
|
})
|
|
}
|