Skip to content

Commit

Permalink
Merge pull request #1301 from nearcatalog/feat/change-url
Browse files Browse the repository at this point in the history
Expose `setURLSearchParams` and `scrollTo` functions to Applications page (NEAR Catalog component)
  • Loading branch information
calebjacob authored Aug 29, 2024
2 parents b2d9170 + 32549fb commit b73641e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/pages/applications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ const ApplicationsPage: NextPageWithLayout = () => {
const { requestAuthentication } = useSignInRedirect();
const { signedAccountId } = useContext(NearContext);

const setURLSearchParams = (params: string | string[][] | Record<string, string> | URLSearchParams | undefined) => {
if (!params) return;
const searchParams = new URLSearchParams(params);
if (searchParams.toString().length > 0) {
window.history.pushState({}, '', '?' + searchParams.toString());
} else {
window.history.pushState({}, '', window.location.pathname);
}
};

const scrollTo = (options: ScrollToOptions | undefined) => {
window.scrollTo(options);
};

useEffect(() => {
const { requestAuth, createAccount } = router.query;
if (requestAuth && !signedAccountId) {
Expand All @@ -25,6 +39,10 @@ const ApplicationsPage: NextPageWithLayout = () => {
<ComponentWrapperPage
src={components.applicationsPage}
meta={{ title: 'NEAR | Applications', description: 'Featured applications built on NEAR' }}
componentProps={{
setURLSearchParams,
scrollTo,
}}
/>
);
};
Expand Down

0 comments on commit b73641e

Please sign in to comment.