mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-06-22 14:13:49 +08:00
fix(favorites): clear account data on logout
This commit is contained in:
+29
-3
@@ -35,7 +35,7 @@
|
||||
@open-favorites="openFavoriteManagement"
|
||||
@open-forum="openExternalUrl(FLARUM_BASE_URL)"
|
||||
@edit-profile="openExternalUrl(FLARUM_SETTINGS_URL)"
|
||||
@logout="logout"
|
||||
@logout="handleLogout"
|
||||
/>
|
||||
</aside>
|
||||
|
||||
@@ -1318,6 +1318,29 @@ const openLoginFromPrompt = () => {
|
||||
showLoginModal.value = true;
|
||||
};
|
||||
|
||||
const clearFavoriteState = () => {
|
||||
favoriteFolders.value = [];
|
||||
activeFavoriteFolderId.value = null;
|
||||
favoriteItems.value = [];
|
||||
showFavoriteSelector.value = false;
|
||||
favoriteTargetApp.value = null;
|
||||
favoriteLoading.value = false;
|
||||
favoriteError.value = "";
|
||||
};
|
||||
|
||||
const handleLogout = () => {
|
||||
logout();
|
||||
clearFavoriteState();
|
||||
showLoginModal.value = false;
|
||||
showLoginPrompt.value = false;
|
||||
isSidebarOpen.value = false;
|
||||
if (currentView.value === "favorites" || currentView.value === "account") {
|
||||
currentView.value = "default";
|
||||
activeTab.value = "home";
|
||||
selectedCategory.value = "all";
|
||||
}
|
||||
};
|
||||
|
||||
const handleFlarumLogin = async (payload: FlarumLoginPayload) => {
|
||||
loginLoading.value = true;
|
||||
loginError.value = "";
|
||||
@@ -1347,8 +1370,11 @@ const openUserManagement = () => {
|
||||
|
||||
const loadFavoriteFolders = async (): Promise<void> => {
|
||||
favoriteFolders.value = await listFavoriteFolders();
|
||||
if (!activeFavoriteFolderId.value && favoriteFolders.value.length > 0) {
|
||||
activeFavoriteFolderId.value = favoriteFolders.value[0].id;
|
||||
const activeFolderExists = favoriteFolders.value.some(
|
||||
(folder) => folder.id === activeFavoriteFolderId.value,
|
||||
);
|
||||
if (!activeFolderExists) {
|
||||
activeFavoriteFolderId.value = favoriteFolders.value[0]?.id ?? null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -163,7 +163,9 @@ describe("App account placeholders", () => {
|
||||
it("shows the favorites placeholder from the logged-in quick menu", async () => {
|
||||
render(App);
|
||||
|
||||
await fireEvent.click(await screen.findByRole("button", { name: /Momen/ }));
|
||||
await fireEvent.click(
|
||||
await screen.findByRole("button", { name: /^Momen$/ }),
|
||||
);
|
||||
await fireEvent.click(screen.getByText("我的收藏"));
|
||||
|
||||
expect(
|
||||
@@ -259,4 +261,34 @@ describe("App account placeholders", () => {
|
||||
pkgnameList: ["wps"],
|
||||
});
|
||||
});
|
||||
|
||||
it("clears favorite data and leaves protected favorites view after logout", async () => {
|
||||
render(App);
|
||||
|
||||
await fireEvent.click(await screen.findByRole("button", { name: /Momen/ }));
|
||||
await fireEvent.click(screen.getByText("我的收藏"));
|
||||
|
||||
expect(
|
||||
await screen.findByRole("heading", { name: "我的收藏" }),
|
||||
).toBeTruthy();
|
||||
expect(await screen.findByText("默认收藏夹 (1)")).toBeTruthy();
|
||||
expect(await screen.findByText("wps · office")).toBeTruthy();
|
||||
|
||||
await fireEvent.click(
|
||||
await screen.findByRole("button", { name: /^Momen$/ }),
|
||||
);
|
||||
if (!screen.queryByText("退出登录")) {
|
||||
await fireEvent.click(
|
||||
await screen.findByRole("button", { name: /^Momen$/ }),
|
||||
);
|
||||
}
|
||||
await fireEvent.click(screen.getByText("退出登录"));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByRole("button", { name: "登录 / 注册" })).toBeTruthy();
|
||||
});
|
||||
expect(screen.queryByText("默认收藏夹 (1)")).toBeNull();
|
||||
expect(screen.queryByText("wps · office")).toBeNull();
|
||||
expect(screen.queryByRole("heading", { name: "我的收藏" })).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user