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-favorites="openFavoriteManagement"
|
||||||
@open-forum="openExternalUrl(FLARUM_BASE_URL)"
|
@open-forum="openExternalUrl(FLARUM_BASE_URL)"
|
||||||
@edit-profile="openExternalUrl(FLARUM_SETTINGS_URL)"
|
@edit-profile="openExternalUrl(FLARUM_SETTINGS_URL)"
|
||||||
@logout="logout"
|
@logout="handleLogout"
|
||||||
/>
|
/>
|
||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
@@ -1318,6 +1318,29 @@ const openLoginFromPrompt = () => {
|
|||||||
showLoginModal.value = true;
|
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) => {
|
const handleFlarumLogin = async (payload: FlarumLoginPayload) => {
|
||||||
loginLoading.value = true;
|
loginLoading.value = true;
|
||||||
loginError.value = "";
|
loginError.value = "";
|
||||||
@@ -1347,8 +1370,11 @@ const openUserManagement = () => {
|
|||||||
|
|
||||||
const loadFavoriteFolders = async (): Promise<void> => {
|
const loadFavoriteFolders = async (): Promise<void> => {
|
||||||
favoriteFolders.value = await listFavoriteFolders();
|
favoriteFolders.value = await listFavoriteFolders();
|
||||||
if (!activeFavoriteFolderId.value && favoriteFolders.value.length > 0) {
|
const activeFolderExists = favoriteFolders.value.some(
|
||||||
activeFavoriteFolderId.value = favoriteFolders.value[0].id;
|
(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 () => {
|
it("shows the favorites placeholder from the logged-in quick menu", async () => {
|
||||||
render(App);
|
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("我的收藏"));
|
await fireEvent.click(screen.getByText("我的收藏"));
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
@@ -259,4 +261,34 @@ describe("App account placeholders", () => {
|
|||||||
pkgnameList: ["wps"],
|
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