refactor function by simplifying function argument (from two arguments to a single object)

GitOrigin-RevId: e4244a07a4ca196afa226e3fac9de74d30f7d4ea
This commit is contained in:
M Fahru 2022-12-28 10:38:27 -07:00 committed by Copybot
parent 777beaadc3
commit af01ace5a0
4 changed files with 12 additions and 8 deletions

View file

@ -19,7 +19,7 @@ export default function useSetProjectWideSettings() {
(compiler: ProjectCompiler) => {
if (project?.compiler) {
setProject({ ...project, compiler })
saveProjectSettings(projectId, { compiler })
saveProjectSettings({ projectId, compiler })
}
},
[projectId, project, setProject]
@ -29,7 +29,7 @@ export default function useSetProjectWideSettings() {
(imageName: string) => {
if (project?.imageName) {
setProject({ ...project, imageName })
saveProjectSettings(projectId, { imageName })
saveProjectSettings({ projectId, imageName })
}
},
[projectId, project, setProject]

View file

@ -19,7 +19,7 @@ export default function useSetRootDocId() {
if (!disallowChange) {
try {
await saveProjectSettings(projectId, { rootDoc_id: rootDocId })
await saveProjectSettings({ projectId, rootDoc_id: rootDocId })
setRootDocIdScope(rootDocId)
} catch (err) {
// TODO: retry mechanism (max 10x before failed completely and rollback the old value)

View file

@ -23,7 +23,7 @@ export default function useSetSpellCheckLanguage() {
setSpellCheckLanguageScope(spellCheckLanguage)
// save to both project setting and user setting
saveProjectSettings(projectId, { spellCheckLanguage })
saveProjectSettings({ projectId, spellCheckLanguage })
saveUserSettings({ spellCheckLanguage })
}
},

View file

@ -52,10 +52,14 @@ type ProjectSettingsRequestBody = Partial<
}
>
export const saveProjectSettings = async (
projectId: string,
data: Partial<ProjectSettingsScope>
) => {
type SaveProjectSettings = {
projectId: string
} & Partial<ProjectSettingsScope>
export const saveProjectSettings = async ({
projectId,
...data
}: SaveProjectSettings) => {
let reqData: ProjectSettingsRequestBody = {}
if (data.rootDoc_id) {