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:
parent
dea283a9c3
commit
82fdf90289
1 changed files with 11 additions and 2 deletions
|
|
@ -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(() => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue