From d982bfda3c67552d2fc954c8967c329e757c6f26 Mon Sep 17 00:00:00 2001 From: Nathanael Liu Date: Fri, 3 May 2024 03:38:22 +0000 Subject: [PATCH] fix: restore classname for active tab in categories tab --- .../shared/category-tabs/category-link.tsx | 15 +++++---- .../shared/category-tabs/category-tabs.tsx | 31 ++++++++++++++++++- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/apps/masterbots.ai/components/shared/category-tabs/category-link.tsx b/apps/masterbots.ai/components/shared/category-tabs/category-link.tsx index 7c5bcb3e..51ccffca 100644 --- a/apps/masterbots.ai/components/shared/category-tabs/category-link.tsx +++ b/apps/masterbots.ai/components/shared/category-tabs/category-link.tsx @@ -5,15 +5,18 @@ import { toSlug } from '@/lib/url' export function CategoryLink({ category, - id + id, + activeTab }: { category: Category | 'all' id: string + activeTab: string }) { return ( - {/* {((activeTab === null && category === 'all') || - (category !== 'all' && activeTab === category.categoryId)) && ( + {((activeTab === 'all' && category === 'all') || + (category !== 'all' && activeTab === toSlug(category.name))) && ( - )} */} + )} {category === 'all' ? 'All' : category.name} ) diff --git a/apps/masterbots.ai/components/shared/category-tabs/category-tabs.tsx b/apps/masterbots.ai/components/shared/category-tabs/category-tabs.tsx index e7061afe..bd197af7 100644 --- a/apps/masterbots.ai/components/shared/category-tabs/category-tabs.tsx +++ b/apps/masterbots.ai/components/shared/category-tabs/category-tabs.tsx @@ -2,6 +2,8 @@ import type { Category } from '@repo/mb-genql' import { CategoryLink } from './category-link' +import { useEffect } from 'react' +import { toSlug } from '@/lib/url' export function CategoryTabs({ categories, @@ -10,11 +12,38 @@ export function CategoryTabs({ categories: Category[] initialCategory?: string }) { + useEffect(() => { + console.log('TopETH', initialCategory) + if (document) { + const element = document.getElementById( + `browse-category-tab__${ + initialCategory === 'all' + ? 'all' + : categories.filter(c => toSlug(c.name) === initialCategory)[0] + ?.categoryId + }` + ) + + if (element) { + element.scrollIntoView({ + behavior: 'smooth', + block: 'center', + inline: 'center' + }) + } + } + }, [initialCategory]) + return (
- + {categories.map((category, key) => (