refactor: Improve HomePage state management and tab switching (#8989)

* 🐛 (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.
This commit is contained in:
Cristhian Zanforlin Lousa 2025-07-11 11:04:24 -03:00 committed by GitHub
commit 82fdf90289
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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(() => {