From 82fdf90289761bd0f8b67d45e9ec899edf661082 Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Fri, 11 Jul 2025 11:04:24 -0300 Subject: [PATCH] refactor: Improve HomePage state management and tab switching (#8989) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🐛 (index.tsx): Fix logic to switch between flow types based on other tab items presence 📝 (index.tsx): Update dependencies for useEffect hook to include all relevant variables for proper functionality * ♻️ (index.tsx): refactor dependencies of the useEffect hook to only include isEmptyFolder as it is the only dependency used within the hook. This improves code readability and maintainability. --- .../src/pages/MainPage/pages/homePage/index.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/frontend/src/pages/MainPage/pages/homePage/index.tsx b/src/frontend/src/pages/MainPage/pages/homePage/index.tsx index 41b0f887e..6d7966b12 100644 --- a/src/frontend/src/pages/MainPage/pages/homePage/index.tsx +++ b/src/frontend/src/pages/MainPage/pages/homePage/index.tsx @@ -111,7 +111,16 @@ const HomePage = ({ type }: { type: "flows" | "components" | "mcp" }) => { flow.is_component === (flowType === "components"), ) === undefined ) { - setFlowType(flowType === "flows" ? "components" : "flows"); + const otherTabHasItems = + flows?.find( + (flow) => + flow.folder_id === (folderId ?? myCollectionId) && + flow.is_component === (flowType === "flows"), + ) !== undefined; + + if (otherTabHasItems) { + setFlowType(flowType === "flows" ? "components" : "flows"); + } } }, [isEmptyFolder]); @@ -222,7 +231,7 @@ const HomePage = ({ type }: { type: "flows" | "components" | "mcp" }) => { setSelectedFlows((old) => old.filter((id) => data.flows.some((flow) => flow.id === id)), ); - }, [data.flows]); + }, [folderData?.flows?.items]); // Reset key states when navigating away useEffect(() => {