Skip to content

Commit

Permalink
fix: fix the error when saving settings for posts in the uc (halo-dev…
Browse files Browse the repository at this point in the history
…#5370)

#### What type of PR is this?

/kind bug
/area ui

#### What this PR does / why we need it:

在个人中心的文章功能中,点击设置时并不会重新获取最新的 Post 数据,进而导致点击保存时的 `version` 并非最新版本而报错。
此 PR 将在个人中心的文章页面点击设置时,额外增加一次获取最新的 Post 数据的请求,用于解决此问题。

#### How to test it?

1. 进入个人中心
2. 点击文章菜单
3. 点击右上角创建按钮
4. 在编辑器中随便输入内容
5. 点击保存
6. 修改文章的设置后点击保存。
7. 关闭设置框,再次打开设置框,然后点击保存。
8. 查看是否会出现无法保存的问题。

#### Which issue(s) this PR fixes:

Fixes halo-dev#5344 

#### Does this PR introduce a user-facing change?
```release-note
解决个人中心文章设置时报错的问题
```
  • Loading branch information
LIlGG authored Feb 20, 2024
1 parent 45d8391 commit 27c98ae
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions ui/uc-src/modules/contents/posts/PostEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,7 @@ const name = useRouteQuery<string | undefined>("name");
onMounted(async () => {
if (name.value) {
const { data: post } = await apiClient.uc.post.getMyPost({
name: name.value,
});
formState.value = post;
await getLatestPost();
await handleFetchContent();
handleResetCache();
return;
Expand Down Expand Up @@ -189,6 +184,17 @@ useAutoSaveContent(currentCache, toRef(content.value, "raw"), async () => {
}
});
async function getLatestPost() {
if (!name.value) {
return;
}
const { data: latestPost } = await apiClient.uc.post.getMyPost({
name: name.value,
});
formState.value = latestPost;
}
/**
* Fetch content from the head snapshot.
*/
Expand Down Expand Up @@ -372,8 +378,9 @@ const { mutateAsync: handlePublish, isLoading: isPublishing } = useMutation({
// Post setting
const postSettingEditModal = ref(false);
function handleOpenPostSettingEditModal() {
async function handleOpenPostSettingEditModal() {
handleSave({ mute: true });
await getLatestPost();
postSettingEditModal.value = true;
}
Expand Down

0 comments on commit 27c98ae

Please sign in to comment.