From dc67d0c1bb6c077b62c66b2d4f5fec03bb1283bb Mon Sep 17 00:00:00 2001 From: Robert Yan Date: Tue, 27 Aug 2024 00:04:26 +0800 Subject: [PATCH 1/7] feat: allow changing url from applications page --- src/pages/applications.tsx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/pages/applications.tsx b/src/pages/applications.tsx index 39e611180..3e59a7f25 100644 --- a/src/pages/applications.tsx +++ b/src/pages/applications.tsx @@ -15,6 +15,12 @@ const ApplicationsPage: NextPageWithLayout = () => { const authStore = useAuthStore(); const accountId = authStore.accountId; + const changeUrl = (newUrl: string) => { + if (window.location.pathname !== newUrl) { + window.history.pushState({}, '', newUrl); + } + } + useEffect(() => { const { requestAuth, createAccount } = router.query; if (requestAuth && !accountId) { @@ -26,6 +32,9 @@ const ApplicationsPage: NextPageWithLayout = () => { ); }; From 4c6eac079ad907274c1ef7a96b60ced22d92c2eb Mon Sep 17 00:00:00 2001 From: Robert Yan Date: Tue, 27 Aug 2024 11:18:25 +0800 Subject: [PATCH 2/7] feat: setURLSearchParams --- src/pages/applications.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/pages/applications.tsx b/src/pages/applications.tsx index 3e59a7f25..fb0825306 100644 --- a/src/pages/applications.tsx +++ b/src/pages/applications.tsx @@ -15,9 +15,13 @@ const ApplicationsPage: NextPageWithLayout = () => { const authStore = useAuthStore(); const accountId = authStore.accountId; - const changeUrl = (newUrl: string) => { - if (window.location.pathname !== newUrl) { - window.history.pushState({}, '', newUrl); + const setURLSearchParams = (params: string | string[][] | Record | URLSearchParams | undefined) => { + if (!params) return; + let searchParams = new URLSearchParams(params); + if (searchParams.toString().length > 0) { + window.history.pushState({}, '', "?" + searchParams.toString()); + } else { + window.history.pushState({}, '', window.location.pathname); } } @@ -33,7 +37,7 @@ const ApplicationsPage: NextPageWithLayout = () => { src={components.applicationsPage} meta={{ title: 'NEAR | Applications', description: 'Featured applications built on NEAR' }} componentProps={{ - changeUrl + setURLSearchParams }} /> ); From c3442e05211222715afdc745b1d1a94f4504328d Mon Sep 17 00:00:00 2001 From: Robert Yan Date: Tue, 27 Aug 2024 11:22:10 +0800 Subject: [PATCH 3/7] fix: set url search params --- src/pages/applications.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/applications.tsx b/src/pages/applications.tsx index fb0825306..77e17ee8c 100644 --- a/src/pages/applications.tsx +++ b/src/pages/applications.tsx @@ -17,7 +17,7 @@ const ApplicationsPage: NextPageWithLayout = () => { const setURLSearchParams = (params: string | string[][] | Record | URLSearchParams | undefined) => { if (!params) return; - let searchParams = new URLSearchParams(params); + const searchParams = new URLSearchParams(params); if (searchParams.toString().length > 0) { window.history.pushState({}, '', "?" + searchParams.toString()); } else { From da5a40df705944c5661451a7cef90518b0bc9b2f Mon Sep 17 00:00:00 2001 From: Robert Yan Date: Thu, 29 Aug 2024 16:16:28 +0800 Subject: [PATCH 4/7] feat: add scrollTo function --- src/pages/applications.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/applications.tsx b/src/pages/applications.tsx index 77e17ee8c..8b699213e 100644 --- a/src/pages/applications.tsx +++ b/src/pages/applications.tsx @@ -37,7 +37,8 @@ const ApplicationsPage: NextPageWithLayout = () => { src={components.applicationsPage} meta={{ title: 'NEAR | Applications', description: 'Featured applications built on NEAR' }} componentProps={{ - setURLSearchParams + setURLSearchParams, + scrollTo: window.scrollTo, }} /> ); From 2ca681f777f110dc0d96b0850d6d6b353471801e Mon Sep 17 00:00:00 2001 From: Robert Yan Date: Thu, 29 Aug 2024 16:22:43 +0800 Subject: [PATCH 5/7] fix: scrollTo --- src/pages/applications.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pages/applications.tsx b/src/pages/applications.tsx index 8b699213e..a3c0260f9 100644 --- a/src/pages/applications.tsx +++ b/src/pages/applications.tsx @@ -25,6 +25,8 @@ const ApplicationsPage: NextPageWithLayout = () => { } } + const scrollTo = window.scrollTo; + useEffect(() => { const { requestAuth, createAccount } = router.query; if (requestAuth && !accountId) { @@ -38,7 +40,7 @@ const ApplicationsPage: NextPageWithLayout = () => { meta={{ title: 'NEAR | Applications', description: 'Featured applications built on NEAR' }} componentProps={{ setURLSearchParams, - scrollTo: window.scrollTo, + scrollTo, }} /> ); From b28c6abdf431be393c79c7a5dffc76d0af5336d0 Mon Sep 17 00:00:00 2001 From: Robert Yan Date: Thu, 29 Aug 2024 16:26:16 +0800 Subject: [PATCH 6/7] fix: scrollTo --- src/pages/applications.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pages/applications.tsx b/src/pages/applications.tsx index a3c0260f9..52828922b 100644 --- a/src/pages/applications.tsx +++ b/src/pages/applications.tsx @@ -25,7 +25,9 @@ const ApplicationsPage: NextPageWithLayout = () => { } } - const scrollTo = window.scrollTo; + const scrollTo = (options: ScrollToOptions | undefined) => { + window.scrollTo(options); + } useEffect(() => { const { requestAuth, createAccount } = router.query; From 32549fbf833d818f3456d7d708290af05c7313e6 Mon Sep 17 00:00:00 2001 From: Robert Yan Date: Thu, 29 Aug 2024 20:35:43 +0800 Subject: [PATCH 7/7] fix: preiiter --- src/pages/applications.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/applications.tsx b/src/pages/applications.tsx index 52828922b..1c165df0e 100644 --- a/src/pages/applications.tsx +++ b/src/pages/applications.tsx @@ -19,15 +19,15 @@ const ApplicationsPage: NextPageWithLayout = () => { if (!params) return; const searchParams = new URLSearchParams(params); if (searchParams.toString().length > 0) { - window.history.pushState({}, '', "?" + searchParams.toString()); + 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;