From e8f762a9582b03d4c792961c33f46bd135240a62 Mon Sep 17 00:00:00 2001 From: cbum-dev Date: Fri, 10 Jan 2025 22:32:17 +0530 Subject: [PATCH 1/5] blog page fix --- pages/blog/index.page.tsx | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/pages/blog/index.page.tsx b/pages/blog/index.page.tsx index 67aaf5e74..41a773b98 100644 --- a/pages/blog/index.page.tsx +++ b/pages/blog/index.page.tsx @@ -92,36 +92,17 @@ export default function StaticMarkdownPage({ setCurrentFilterTag(filterTag); }, [filterTag]); - const handleClick = (event: { currentTarget: { value: any } }) => { - const clickedTag = event.currentTarget.value; - setParam('type', clickedTag); - + const handleClick = (event: React.MouseEvent) => { + event.preventDefault(); // Prevent default scrolling behavior + const clickedTag = event.currentTarget.value as blogCategories; if (clickedTag === 'All') { - setParam('type', null); - } else { - setCurrentFilterTag(clickedTag); - } - - // Check if the user is already on the "/blog" page - if (router.pathname === '/blog') { - if (router.query.type) { - // Remove the 'type' query parameter from the URL - setParam( - 'type', - router.query.type === clickedTag ? undefined : clickedTag, - ); - } + setCurrentFilterTag('All'); + history.replaceState(null, '', '/blog'); // Update the URL without causing a scroll + } else if (isValidCategory(clickedTag)) { setCurrentFilterTag(clickedTag); - } else { - // If not on the "/blog" page, navigate to the "/blog" page with the type tag as a query parameter - router.replace( - { pathname: '/blog', query: { type: clickedTag } }, - undefined, - { shallow: true }, - ); + history.replaceState(null, '', `/blog?type=${clickedTag}`); // Update URL } }; - const recentBlog = blogPosts.sort((a, b) => { const dateA = new Date(a.frontmatter.date).getTime(); const dateB = new Date(b.frontmatter.date).getTime(); From 0b4839b0d7e48d03b90daa8f39e4144dcd75d5f0 Mon Sep 17 00:00:00 2001 From: Priyanshu Kumar <110410015+cbum-dev@users.noreply.github.com> Date: Sun, 12 Jan 2025 14:27:12 -0500 Subject: [PATCH 2/5] Update index.page.tsx --- pages/blog/index.page.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pages/blog/index.page.tsx b/pages/blog/index.page.tsx index 41a773b98..b3d02cfd4 100644 --- a/pages/blog/index.page.tsx +++ b/pages/blog/index.page.tsx @@ -255,10 +255,18 @@ export default function StaticMarkdownPage({ onClick={(e) => { e.preventDefault(); e.stopPropagation(); - setParam('type', frontmatter.type); - }} + + if (frontmatter.type) { + setCurrentFilterTag(frontmatter.type); + history.replaceState( + null, + '', + `/blog?type=${frontmatter.type}`, + ); + } + }} > - {frontmatter.type} + {frontmatter.type || 'Unknown Type'}
From 191c3d4adc6dd413004646adb19f187bea97e978 Mon Sep 17 00:00:00 2001 From: Priyanshu Kumar <110410015+cbum-dev@users.noreply.github.com> Date: Sun, 12 Jan 2025 14:29:19 -0500 Subject: [PATCH 3/5] Update index.page.tsx --- pages/blog/index.page.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/pages/blog/index.page.tsx b/pages/blog/index.page.tsx index b3d02cfd4..d718ca1ac 100644 --- a/pages/blog/index.page.tsx +++ b/pages/blog/index.page.tsx @@ -75,7 +75,6 @@ export default function StaticMarkdownPage({ filterTag: any; }) { const router = useRouter(); - const setParam = useSetUrlParam(); const [currentFilterTag, setCurrentFilterTag] = useState( filterTag || 'All', ); From 4b5e5e4a6d75b447bc7b4c10b5969f342e206517 Mon Sep 17 00:00:00 2001 From: Priyanshu Kumar <110410015+cbum-dev@users.noreply.github.com> Date: Sun, 12 Jan 2025 14:31:21 -0500 Subject: [PATCH 4/5] Update index.page.tsx --- pages/blog/index.page.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/pages/blog/index.page.tsx b/pages/blog/index.page.tsx index d718ca1ac..a78673051 100644 --- a/pages/blog/index.page.tsx +++ b/pages/blog/index.page.tsx @@ -9,7 +9,6 @@ const PATH = 'pages/blog/posts'; import TextTruncate from 'react-text-truncate'; import generateRssFeed from './generateRssFeed'; import { useRouter } from 'next/router'; -import useSetUrlParam from '~/lib/useSetUrlParam'; import { SectionContext } from '~/context'; type Author = { From 375a5de8bf4c6a28cac4a210b44dc8268f675444 Mon Sep 17 00:00:00 2001 From: Priyanshu Kumar <110410015+cbum-dev@users.noreply.github.com> Date: Sun, 12 Jan 2025 14:46:00 -0500 Subject: [PATCH 5/5] Update index.page.tsx --- pages/blog/index.page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/blog/index.page.tsx b/pages/blog/index.page.tsx index a78673051..30dabd0a5 100644 --- a/pages/blog/index.page.tsx +++ b/pages/blog/index.page.tsx @@ -262,7 +262,7 @@ export default function StaticMarkdownPage({ `/blog?type=${frontmatter.type}`, ); } - }} + }} > {frontmatter.type || 'Unknown Type'}