import React, { ComponentProps } from 'react'; import { ScrollArea } from './ui/scroll-area'; import { cn } from '@/utils/style'; import { Badge } from './ui/badge'; import { useNavigate, useRouterState } from '@tanstack/react-router'; import { LuSearch } from 'react-icons/lu'; import { Input } from './ui/input'; import { useFuseSearch } from '@/hooks/useFuseSearch'; export interface CommonListItem { id: string; title: string; content: React.ReactNode; tags: string[]; href: string; } interface CommonListProps { hasSearch?: boolean; items: CommonListItem[]; } export const CommonList: React.FC = React.memo((props) => { const { location } = useRouterState(); const navigate = useNavigate(); const { searchText, setSearchText, searchResult } = useFuseSearch( props.items, { keys: [ { name: 'id', weight: 1, }, { name: 'title', weight: 0.7, }, { name: 'tags', weight: 0.3, }, ], } ); const finalList = searchResult ?? props.items; return (
{props.hasSearch && (
setSearchText(e.target.value)} />
)}
{finalList.map((item) => { const isSelected = item.href === location.pathname; return ( ); })}
); }); CommonList.displayName = 'CommonList'; /** * TODO */ function getBadgeVariantFromLabel( label: string ): ComponentProps['variant'] { if (['work'].includes(label.toLowerCase())) { return 'default'; } if (['personal'].includes(label.toLowerCase())) { return 'outline'; } return 'secondary'; }