From 41f960c60cf5353e7adc89ab372b254b25b496db Mon Sep 17 00:00:00 2001 From: Mike Sawka Date: Tue, 10 Dec 2024 16:33:55 -0800 Subject: [PATCH] fix for tabs out of order in tabbar (#1478) --- frontend/app/tab/tabbar.tsx | 68 +++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 17 deletions(-) diff --git a/frontend/app/tab/tabbar.tsx b/frontend/app/tab/tabbar.tsx index dcb774f20..d632b0fcb 100644 --- a/frontend/app/tab/tabbar.tsx +++ b/frontend/app/tab/tabbar.tsx @@ -99,6 +99,43 @@ const ConfigErrorIcon = ({ buttonRef }: { buttonRef: React.RefObject | null, b: Set | null): boolean { + if (a == null && b == null) { + return true; + } + if (a == null || b == null) { + return false; + } + if (a.size !== b.size) { + return false; + } + for (const item of a) { + if (!b.has(item)) { + return false; + } + } + return true; +} + const TabBar = memo(({ workspace }: TabBarProps) => { const [tabIds, setTabIds] = useState([]); const [pinnedTabIds, setPinnedTabIds] = useState>(new Set()); @@ -148,25 +185,22 @@ const TabBar = memo(({ workspace }: TabBarProps) => { }, [tabIds]); useEffect(() => { - if (workspace) { - // Compare current tabIds with new workspace.tabids - console.log("tabbar workspace", workspace); - const newTabIds = new Set([...(workspace.pinnedtabids ?? []), ...(workspace.tabids ?? [])]); - const newPinnedTabIds = workspace.pinnedtabids ?? []; + if (!workspace) { + return; + } + // Compare current tabIds with new workspace.tabids + console.log("tabbar workspace", workspace); - const areEqual = - tabIds.length === newTabIds.size && - tabIds.every((id) => newTabIds.has(id)) && - newPinnedTabIds.length === pinnedTabIds.size; + const newTabIdsArr = [...(workspace.pinnedtabids ?? []), ...(workspace.tabids ?? [])]; + const newPinnedTabSet = new Set(workspace.pinnedtabids ?? []); - if (!areEqual) { - const newPinnedTabIdSet = new Set(newPinnedTabIds); - console.log("newPinnedTabIds", newPinnedTabIds); - const newTabIdList = newPinnedTabIds.concat([...newTabIds].filter((id) => !newPinnedTabIdSet.has(id))); // Corrects for any duplicates between the two lists - console.log("newTabIdList", newTabIdList); - setTabIds(newTabIdList); - setPinnedTabIds(newPinnedTabIdSet); - } + const areEqual = strArrayIsEqual(tabIds, newTabIdsArr) && setIsEqual(pinnedTabIds, newPinnedTabSet); + + if (!areEqual) { + console.log("newPinnedTabIds", newPinnedTabSet); + console.log("newTabIdList", newTabIdsArr); + setTabIds(newTabIdsArr); + setPinnedTabIds(newPinnedTabSet); } }, [workspace, tabIds, pinnedTabIds]);