Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blog page Tab Improvement. #1288

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 7 additions & 26 deletions pages/blog/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLButtonElement>) => {
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();
Expand Down
Loading