|
| 1 | +// TODO: Storage optimizations required |
| 2 | + |
1 | 3 | import { useCallback, useEffect } from "react";
|
2 | 4 |
|
3 | 5 | import { useRouter } from "next/router";
|
@@ -176,27 +178,40 @@ export const usePotLayoutTabNavigation = ({ potId }: ByPotId): PotLayoutTabNavig
|
176 | 178 |
|
177 | 179 | // Get active tab with proper type safety
|
178 | 180 | const activeTab =
|
179 |
| - Object.values(tabRegistry).find( |
180 |
| - (tab): tab is PotLayoutTabOption => tab?.href === currentPath && !tab.isHidden, |
181 |
| - ) ?? null; |
| 181 | + Object.values(tabRegistry).find((tab): tab is PotLayoutTabOption => { |
| 182 | + // Compare without query parameters |
| 183 | + const currentPathBase = currentPath.split("?")[0]; |
| 184 | + return tab?.href === currentPathBase && !tab.isHidden; |
| 185 | + }) ?? null; |
182 | 186 |
|
183 | 187 | const navigateToTab = useCallback(
|
184 | 188 | (tag: PotLayoutTabTag) => {
|
185 | 189 | const targetTab = tabRegistry[tag];
|
| 190 | + const currentPathBase = currentPath.split("?")[0]; |
| 191 | + |
| 192 | + // Only navigate if tab exists, is not hidden, and we're not already on the correct tab |
| 193 | + if (targetTab && !targetTab.isHidden && currentPathBase !== targetTab.href) { |
| 194 | + // Extract query parameters from current URL |
| 195 | + const queryParams = currentPath.includes("?") |
| 196 | + ? currentPath.substring(currentPath.indexOf("?")) |
| 197 | + : ""; |
| 198 | + |
| 199 | + // Append query parameters to the target href |
| 200 | + const targetHref = targetTab.href + queryParams; |
186 | 201 |
|
187 |
| - if (targetTab && !targetTab.isHidden) { |
188 |
| - navigateToHref(targetTab.href); |
| 202 | + navigateToHref(targetHref); |
189 | 203 | }
|
190 | 204 | },
|
191 | 205 |
|
192 |
| - [navigateToHref, tabRegistry], |
| 206 | + [navigateToHref, tabRegistry, currentPath], |
193 | 207 | );
|
194 | 208 |
|
195 | 209 | // Handle navigation to default tab
|
196 | 210 | useEffect(() => {
|
197 | 211 | const rootPath = `${rootPathnames.pot}/${potId}`;
|
| 212 | + const currentPathBase = currentPath.split("?")[0]; |
198 | 213 |
|
199 |
| - if (potId !== undefined && (activeTab === null || currentPath === rootPath)) { |
| 214 | + if (potId !== undefined && (activeTab === null || currentPathBase === rootPath)) { |
200 | 215 | navigateToTab(defaultTabTag);
|
201 | 216 | }
|
202 | 217 | }, [activeTab, currentPath, defaultTabTag, navigateToTab, potId]);
|
|
0 commit comments