Skip to content

Commit

Permalink
feat(Category Menu): go back to id for active category
Browse files Browse the repository at this point in the history
Makes it easier to use component in storybook
  • Loading branch information
jrhender committed Feb 10, 2024
1 parent ac34530 commit fff1254
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions app/components/CategoriesNav/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import './menu.css'

interface CategoriesNavProps {
/**
* Articles List
* Categories List
*/
categories: TagType[]
/**
* Selected article
* Id of selected category
*/
active: TagType
activeCategoryId: number
/**
* Callback function to handle click on article
* Callback function to handle click on category
*/
onClick?: (t: TagType) => void
/**
Expand All @@ -21,7 +21,12 @@ interface CategoriesNavProps {
onChange?: (search: string) => void
}

export const CategoriesNav = ({categories, active, onChange, onClick}: CategoriesNavProps) => {
export const CategoriesNav = ({
categories,
activeCategoryId,
onChange,
onClick,
}: CategoriesNavProps) => {
const handleClick = (newTag: TagType) => {
if (onClick) {
onClick(newTag)
Expand All @@ -40,7 +45,7 @@ export const CategoriesNav = ({categories, active, onChange, onClick}: Categorie
key={`category-${category.tagId}`}
className={[
'category-autoLayoutHorizontal',
active?.tagId == category.tagId ? ['active'].join(' ') : '',
activeCategoryId == category.tagId ? ['active'].join(' ') : '',
].join(' ')}
onClick={() => handleClick(category)}
>
Expand Down
2 changes: 1 addition & 1 deletion app/routes/tags.$tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default function App() {

// {title: "AI Safety", id: 1},
}
active={selectedTag}
activeCategoryId={selectedTag.tagId}
onClick={(selectedTag) => {
navigate(`../${selectedTag.name}`, {relative: 'path'})
}}
Expand Down

0 comments on commit fff1254

Please sign in to comment.