mirror of https://github.com/halo-dev/halo
fix: content cache was not cleaned up after the new post was saved (#4316)
#### What type of PR is this? /area console /kind bug /milestone 2.8.x #### What this PR does / why we need it: 修复新建文章发布或者保存之后,浏览器中的内容缓存没有清空的问题。 #### Which issue(s) this PR fixes: Fixes #4310 #### Special notes for your reviewer: 需要测试: 1. 新建一篇文章,测试未保存到服务器时,刷新浏览器,观察内容是否还存在。 2. 保存之后,再次新建文章,观察编辑器是否没有内容。 #### Does this PR introduce a user-facing change? ```release-note 修复新建文章发布或者保存之后,浏览器中的内容缓存没有清空的问题。 ```pull/4322/head
parent
54925efdd4
commit
4733008e16
|
@ -12,7 +12,7 @@ import { useI18n } from "vue-i18n";
|
||||||
interface useContentCacheReturn {
|
interface useContentCacheReturn {
|
||||||
handleResetCache: () => void;
|
handleResetCache: () => void;
|
||||||
handleSetContentCache: () => void;
|
handleSetContentCache: () => void;
|
||||||
handleClearCache: (name: string) => void;
|
handleClearCache: (name?: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useContentCache(
|
export function useContentCache(
|
||||||
|
@ -71,7 +71,7 @@ export function useContentCache(
|
||||||
}
|
}
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
const handleClearCache = (name: string) => {
|
const handleClearCache = (name?: string) => {
|
||||||
if (name) {
|
if (name) {
|
||||||
const index = content_caches.value.findIndex(
|
const index = content_caches.value.findIndex(
|
||||||
(c: ContentCache) => c.name === name
|
(c: ContentCache) => c.name === name
|
||||||
|
|
|
@ -150,6 +150,9 @@ const handleSave = async (options?: { mute?: boolean }) => {
|
||||||
});
|
});
|
||||||
formState.value.page = data;
|
formState.value.page = data;
|
||||||
routeQueryName.value = data.metadata.name;
|
routeQueryName.value = data.metadata.name;
|
||||||
|
|
||||||
|
// Clear new page content cache
|
||||||
|
handleClearCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options?.mute) {
|
if (!options?.mute) {
|
||||||
|
@ -195,6 +198,10 @@ const handlePublish = async () => {
|
||||||
await apiClient.singlePage.draftSinglePage({
|
await apiClient.singlePage.draftSinglePage({
|
||||||
singlePageRequest: formState.value,
|
singlePageRequest: formState.value,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Clear new page content cache
|
||||||
|
handleClearCache();
|
||||||
|
|
||||||
router.push({ name: "SinglePages" });
|
router.push({ name: "SinglePages" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -153,6 +153,9 @@ const handleSave = async (options?: { mute?: boolean }) => {
|
||||||
});
|
});
|
||||||
formState.value.post = data;
|
formState.value.post = data;
|
||||||
name.value = data.metadata.name;
|
name.value = data.metadata.name;
|
||||||
|
|
||||||
|
// Clear new post content cache
|
||||||
|
handleClearCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options?.mute) {
|
if (!options?.mute) {
|
||||||
|
@ -201,6 +204,9 @@ const handlePublish = async () => {
|
||||||
name: data.metadata.name,
|
name: data.metadata.name,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Clear new post content cache
|
||||||
|
handleClearCache();
|
||||||
|
|
||||||
router.push({ name: "Posts" });
|
router.push({ name: "Posts" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue