Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

perf: add a button to save the settings in the actions area of the theme settings page #549

Merged
merged 4 commits into from
Apr 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/views/dashboard/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@
{{ item.title }}
</a>

<a herf="javascript:void(0)" v-else-if="item.status === 'DRAFT'" @click="handlePostPreview(item.id)">
<a
herf="javascript:void(0)"
v-else-if="item.status === 'DRAFT'"
@click="handlePostPreview(item.id)"
>
{{ item.title }}
</a>

Expand Down
34 changes: 33 additions & 1 deletion src/views/interface/ThemeSetting.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
<template>
<page-view :sub-title="theme.current.version || '-'" :title="theme.current.name || '-'" affix>
<template slot="extra">
<ReactiveButton
:errored="form.saveErrored"
:loading="form.saving"
erroredText="保存失败"
loadedText="保存成功"
icon="save"
text="保存设置"
type="primary"
@callback="handleSaveSettingsCallback"
@click="handleSaveSettings"
></ReactiveButton>
<a-dropdown>
<a-menu slot="overlay">
<a-menu-item key="1" @click="handleRemoteUpdate">
Expand Down Expand Up @@ -46,7 +57,7 @@
</template>

<a-spin :spinning="theme.loading">
<ThemeSettingForm :theme="theme.current" />
<ThemeSettingForm :theme="theme.current" ref="themeSettingForm" />
</a-spin>

<ThemeDeleteConfirmModal
Expand Down Expand Up @@ -91,6 +102,10 @@ export default {
},
localUpgradeModel: {
visible: false
},
form: {
saving: false,
saveErrored: false
}
}
},
Expand Down Expand Up @@ -159,6 +174,23 @@ export default {
}
}
})
},
async handleSaveSettings() {
try {
this.form.saving = true
await this.$refs.themeSettingForm.handleSaveSettings(false)
} catch {
this.form.saveErrored = true
} finally {
setTimeout(() => {
this.form.saving = false
}, 400)
}
},
handleSaveSettingsCallback() {
if (this.form.saveErrored) {
this.form.saveErrored = false
}
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/views/interface/components/ThemeSettingForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,16 @@ export default {
this.$log.error(error)
}
},
async handleSaveSettings() {
async handleSaveSettings(enableLoading = true) {
try {
this.form.saving = true
if (enableLoading) {
this.form.saving = true
}
await apiClient.theme.saveSettings(this.theme.id, this.form.settings)
} catch (error) {
this.$log.error(error)
this.form.saveErrored = true
throw new Error(error)
} finally {
setTimeout(() => {
this.form.saving = false
Expand Down