Skip to content

Commit

Permalink
fix(masterbots.ai): restore classname for active tab in categories tab (
Browse files Browse the repository at this point in the history
  • Loading branch information
TopETH authored May 3, 2024
1 parent 3af3a2d commit 0d622f6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ import { toSlug } from '@/lib/url'

export function CategoryLink({
category,
id
id,
activeTab
}: {
category: Category | 'all'
id: string
activeTab: string
}) {
return (
<Link
className={`${
category === 'all'
(activeTab === 'all' && category === 'all') ||
(category !== 'all' && activeTab === toSlug(category.name))
? 'dark:text-white'
: 'dark:hover:text-white dark:text-[#F4F4F580] text-zinc-500 hover:text-black'
} relative rounded-full px-3 py-1.5 text-sm font-medium outline-sky-400 transition focus-visible:outline-2`}
Expand All @@ -24,14 +27,14 @@ export function CategoryLink({
WebkitTapHighlightColor: 'transparent'
}}
>
{/* {((activeTab === null && category === 'all') ||
(category !== 'all' && activeTab === category.categoryId)) && (
{((activeTab === 'all' && category === 'all') ||
(category !== 'all' && activeTab === toSlug(category.name))) && (
<motion.span
className="absolute inset-0 z-10 bg-transparent border-b-2 border-[#388DE2]"
className="absolute inset-0 z-10 bg-transparent border-solid border-b-2 border-[#388DE2]"
layoutId="bubble"
transition={{ type: 'spring', bounce: 0.2, duration: 0.6 }}
/>
)} */}
)}
{category === 'all' ? 'All' : category.name}
</Link>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 (
<div className="w-full py-[10px] my-3 !overflow-x-auto overflow-y-hidden whitespace-nowrap scrollbar small-thumb justify-between flex">
<CategoryLink category="all" id="browse-category-tab__null" />
<CategoryLink
activeTab={initialCategory}
category="all"
id="browse-category-tab__all"
/>
{categories.map((category, key) => (
<CategoryLink
activeTab={initialCategory}
category={category}
id={`browse-category-tab__${category.categoryId}`}
key={key}
Expand Down

0 comments on commit 0d622f6

Please sign in to comment.