From 2fb59867c5c35dfea9276f676b61f93021b6947c Mon Sep 17 00:00:00 2001 From: Matias Benary Date: Thu, 27 Jun 2024 22:23:51 -0300 Subject: [PATCH 1/4] feat: the documentation can be navigated with the following links --- src/pages/documentation.tsx | 10 ------- src/pages/documentation/[...slug].tsx | 43 +++++++++++++++++++++++++++ src/pages/documentation/index.tsx | 43 +++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 10 deletions(-) delete mode 100644 src/pages/documentation.tsx create mode 100644 src/pages/documentation/[...slug].tsx create mode 100644 src/pages/documentation/index.tsx diff --git a/src/pages/documentation.tsx b/src/pages/documentation.tsx deleted file mode 100644 index 80b46c81c..000000000 --- a/src/pages/documentation.tsx +++ /dev/null @@ -1,10 +0,0 @@ -import { useDefaultLayout } from '@/hooks/useLayout'; -import type { NextPageWithLayout } from '@/utils/types'; - -const Documentation: NextPageWithLayout = () => { - return ; -}; - -Documentation.getLayout = useDefaultLayout; - -export default Documentation; diff --git a/src/pages/documentation/[...slug].tsx b/src/pages/documentation/[...slug].tsx new file mode 100644 index 000000000..afa63f37f --- /dev/null +++ b/src/pages/documentation/[...slug].tsx @@ -0,0 +1,43 @@ +import { useEffect, useRef } from 'react'; +import { useDefaultLayout } from '@/hooks/useLayout'; +import type { NextPageWithLayout } from '@/utils/types'; +import { useRouter } from 'next/router'; + +const Documentation: NextPageWithLayout = () => { + const router = useRouter(); + const { slug } = router.query; + const iframeRef = useRef(null); + const currentPath = Array.isArray(slug) ? `/${slug.join('/')}` : ''; + + const path = currentPath.replace(/\/documentation/g, ''); + + useEffect(() => { + const handleIframeMessage = (event: MessageEvent) => { + if (event.data.type === 'urlChange' && event.data.url && event.data.url !== path) { + const url = event.data.url.replace(/\/documentation/g, ''); + + const newUrl = `/documentation${url}`; + if (window.location.pathname !== newUrl) { + window.history.pushState({}, '', newUrl); + } + } + }; + + window.addEventListener('message', handleIframeMessage); + return () => { + window.removeEventListener('message', handleIframeMessage); + }; + }, [path]); + + return ( + + ); +}; + +Documentation.getLayout = useDefaultLayout; + +export default Documentation; diff --git a/src/pages/documentation/index.tsx b/src/pages/documentation/index.tsx new file mode 100644 index 000000000..afa63f37f --- /dev/null +++ b/src/pages/documentation/index.tsx @@ -0,0 +1,43 @@ +import { useEffect, useRef } from 'react'; +import { useDefaultLayout } from '@/hooks/useLayout'; +import type { NextPageWithLayout } from '@/utils/types'; +import { useRouter } from 'next/router'; + +const Documentation: NextPageWithLayout = () => { + const router = useRouter(); + const { slug } = router.query; + const iframeRef = useRef(null); + const currentPath = Array.isArray(slug) ? `/${slug.join('/')}` : ''; + + const path = currentPath.replace(/\/documentation/g, ''); + + useEffect(() => { + const handleIframeMessage = (event: MessageEvent) => { + if (event.data.type === 'urlChange' && event.data.url && event.data.url !== path) { + const url = event.data.url.replace(/\/documentation/g, ''); + + const newUrl = `/documentation${url}`; + if (window.location.pathname !== newUrl) { + window.history.pushState({}, '', newUrl); + } + } + }; + + window.addEventListener('message', handleIframeMessage); + return () => { + window.removeEventListener('message', handleIframeMessage); + }; + }, [path]); + + return ( + + ); +}; + +Documentation.getLayout = useDefaultLayout; + +export default Documentation; From c81f421c342cbf690f02711ccd91ddbf4a7881e5 Mon Sep 17 00:00:00 2001 From: Guille Date: Mon, 1 Jul 2024 20:39:43 +0200 Subject: [PATCH 2/4] Apply suggestions from code review --- src/pages/documentation/[...slug].tsx | 2 +- src/pages/documentation/index.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/documentation/[...slug].tsx b/src/pages/documentation/[...slug].tsx index afa63f37f..ccc1ddd55 100644 --- a/src/pages/documentation/[...slug].tsx +++ b/src/pages/documentation/[...slug].tsx @@ -33,7 +33,7 @@ const Documentation: NextPageWithLayout = () => { ); }; diff --git a/src/pages/documentation/index.tsx b/src/pages/documentation/index.tsx index afa63f37f..ccc1ddd55 100644 --- a/src/pages/documentation/index.tsx +++ b/src/pages/documentation/index.tsx @@ -33,7 +33,7 @@ const Documentation: NextPageWithLayout = () => { ); }; From 184ecffb0ae980b14cd374152b019ec2b948f398 Mon Sep 17 00:00:00 2001 From: gagdiez Date: Tue, 2 Jul 2024 16:52:28 +0200 Subject: [PATCH 3/4] fix: slug --- .../{[...slug].tsx => [[...slug]].tsx} | 0 src/pages/documentation/index.tsx | 43 ------------------- 2 files changed, 43 deletions(-) rename src/pages/documentation/{[...slug].tsx => [[...slug]].tsx} (100%) delete mode 100644 src/pages/documentation/index.tsx diff --git a/src/pages/documentation/[...slug].tsx b/src/pages/documentation/[[...slug]].tsx similarity index 100% rename from src/pages/documentation/[...slug].tsx rename to src/pages/documentation/[[...slug]].tsx diff --git a/src/pages/documentation/index.tsx b/src/pages/documentation/index.tsx deleted file mode 100644 index ccc1ddd55..000000000 --- a/src/pages/documentation/index.tsx +++ /dev/null @@ -1,43 +0,0 @@ -import { useEffect, useRef } from 'react'; -import { useDefaultLayout } from '@/hooks/useLayout'; -import type { NextPageWithLayout } from '@/utils/types'; -import { useRouter } from 'next/router'; - -const Documentation: NextPageWithLayout = () => { - const router = useRouter(); - const { slug } = router.query; - const iframeRef = useRef(null); - const currentPath = Array.isArray(slug) ? `/${slug.join('/')}` : ''; - - const path = currentPath.replace(/\/documentation/g, ''); - - useEffect(() => { - const handleIframeMessage = (event: MessageEvent) => { - if (event.data.type === 'urlChange' && event.data.url && event.data.url !== path) { - const url = event.data.url.replace(/\/documentation/g, ''); - - const newUrl = `/documentation${url}`; - if (window.location.pathname !== newUrl) { - window.history.pushState({}, '', newUrl); - } - } - }; - - window.addEventListener('message', handleIframeMessage); - return () => { - window.removeEventListener('message', handleIframeMessage); - }; - }, [path]); - - return ( - - ); -}; - -Documentation.getLayout = useDefaultLayout; - -export default Documentation; From 547a90208e7274efc01e5f4aedf0d00f11792f44 Mon Sep 17 00:00:00 2001 From: gagdiez Date: Tue, 2 Jul 2024 17:00:24 +0200 Subject: [PATCH 4/4] fix: remove unused code --- src/pages/documentation/[[...slug]].tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/pages/documentation/[[...slug]].tsx b/src/pages/documentation/[[...slug]].tsx index ccc1ddd55..613dff927 100644 --- a/src/pages/documentation/[[...slug]].tsx +++ b/src/pages/documentation/[[...slug]].tsx @@ -1,4 +1,4 @@ -import { useEffect, useRef } from 'react'; +import { useEffect } from 'react'; import { useDefaultLayout } from '@/hooks/useLayout'; import type { NextPageWithLayout } from '@/utils/types'; import { useRouter } from 'next/router'; @@ -6,7 +6,6 @@ import { useRouter } from 'next/router'; const Documentation: NextPageWithLayout = () => { const router = useRouter(); const { slug } = router.query; - const iframeRef = useRef(null); const currentPath = Array.isArray(slug) ? `/${slug.join('/')}` : ''; const path = currentPath.replace(/\/documentation/g, ''); @@ -31,7 +30,6 @@ const Documentation: NextPageWithLayout = () => { return (