[web] qns/quiz: fix user sign in on quiz scroll mode reset the scroll position (#1676)

This commit is contained in:
Nitesh Seram 2025-09-09 09:16:17 +05:30 committed by GitHub
parent 8a00c2d714
commit 4eb373f16c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 8 deletions

View File

@ -1,4 +1,4 @@
import { usePathname, useRouter } from 'next/navigation';
import { usePathname } from 'next/navigation';
import { useCallback, useEffect, useRef } from 'react';
import url from 'url';
@ -13,7 +13,6 @@ export default function useQueryParamAction<T extends string>(
) {
const hasRunRef = useRef(false);
const pathname = usePathname();
const { replace } = useRouter();
const clearActionQueryParams = useCallback(() => {
const searchParams = new URLSearchParams(window.location.search);
@ -21,13 +20,18 @@ export default function useQueryParamAction<T extends string>(
[queryParamActionKey, ...(params ?? [])].forEach((key) => {
searchParams.delete(key);
});
replace(
url.format({
pathname,
query: Object.fromEntries(searchParams),
}),
history.replaceState(
null,
'',
url
.format({
hash: window.location.hash,
pathname,
query: Object.fromEntries(searchParams),
})
.toString(),
);
}, [params, pathname, replace]);
}, [params, pathname]);
useEffect(() => {
if (hasRunRef.current) {
@ -71,6 +75,7 @@ export default function useQueryParamAction<T extends string>(
}
return url.format({
hash: window.location.hash,
pathname: urlObj.pathname,
search: urlObj.search,
});