Skip to content

Commit cfcce52

Browse files
committed
Prevent query params from being lost on pot page
1 parent 085c0e1 commit cfcce52

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

src/common/api/indexer/hooks.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export const useAccountDonationsSent = ({
182182
* https://test-dev.potlock.io/api/schema/swagger-ui/#/v1/v1_pots_retrieve_2
183183
*/
184184
export const usePot = ({ potId, enabled = true }: ByPotId & ConditionalActivation) => {
185-
const queryResult = generatedClient.useV1PotsRetrieve2(potId ?? "noop", {
185+
const queryResult = generatedClient.useV1PotsRetrieve2(potId, {
186186
...INDEXER_CLIENT_CONFIG,
187187
swr: { enabled, refreshInterval: 3000 },
188188
});

src/common/wallet/components.tsx

+2-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { IS_CLIENT } from "@/common/constants";
77

88
import { useWalletUserAdapter } from "./adapters";
99
import { useWalletUserMetadataStore } from "./model";
10-
import { isAccountId, useRouteQuery } from "../lib";
10+
import { isAccountId } from "../lib";
1111

1212
type WalletProviderProps = {
1313
children: React.ReactNode;
@@ -16,10 +16,6 @@ type WalletProviderProps = {
1616
const WalletProvider: React.FC<WalletProviderProps> = ({ children }) => {
1717
const router = useRouter();
1818

19-
const { query, setSearchParams } = useRouteQuery();
20-
21-
console.log(query);
22-
2319
const trackedQueryParams = router.query as {
2420
/**
2521
* Backward compatibility for deprecated parameter name
@@ -86,8 +82,6 @@ const WalletProvider: React.FC<WalletProviderProps> = ({ children }) => {
8682
};
8783
}, [syncWalletState, isReady, handleChange]);
8884

89-
console.log(referrerAccountIdUrlParameter);
90-
9185
/**
9286
* Updating referrer account id, if detected
9387
*/
@@ -100,6 +94,7 @@ const WalletProvider: React.FC<WalletProviderProps> = ({ children }) => {
10094
referrerAccountIdUrlParameter !== accountId
10195
) {
10296
setReferrerAccountId(referrerAccountIdUrlParameter);
97+
// TODO: Cleanup the query parameter once it's recorded using useRouteQuery instead of useRouter
10398
}
10499
}, [
105100
accountId,

src/layout/pot/hooks/tab-navigation.ts

+22-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// TODO: Storage optimizations required
2+
13
import { useCallback, useEffect } from "react";
24

35
import { useRouter } from "next/router";
@@ -176,27 +178,40 @@ export const usePotLayoutTabNavigation = ({ potId }: ByPotId): PotLayoutTabNavig
176178

177179
// Get active tab with proper type safety
178180
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;
182186

183187
const navigateToTab = useCallback(
184188
(tag: PotLayoutTabTag) => {
185189
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;
186201

187-
if (targetTab && !targetTab.isHidden) {
188-
navigateToHref(targetTab.href);
202+
navigateToHref(targetHref);
189203
}
190204
},
191205

192-
[navigateToHref, tabRegistry],
206+
[navigateToHref, tabRegistry, currentPath],
193207
);
194208

195209
// Handle navigation to default tab
196210
useEffect(() => {
197211
const rootPath = `${rootPathnames.pot}/${potId}`;
212+
const currentPathBase = currentPath.split("?")[0];
198213

199-
if (potId !== undefined && (activeTab === null || currentPath === rootPath)) {
214+
if (potId !== undefined && (activeTab === null || currentPathBase === rootPath)) {
200215
navigateToTab(defaultTabTag);
201216
}
202217
}, [activeTab, currentPath, defaultTabTag, navigateToTab, potId]);

0 commit comments

Comments
 (0)