1- import { IconSvg } from '@/components/ui/IconSvg' ;
2- import { Icon } from '@iconify-icon/react' ;
1+ import { Cross2Icon , FileIcon , FileTextIcon , GearIcon , ImageIcon , ModulzLogoIcon , RocketIcon } from '@radix-ui/react-icons' ;
32import React , { useCallback , useEffect , useState } from 'react' ;
43
54// Types
@@ -534,17 +533,45 @@ const SearchPage: React.FC = () => {
534533 return null ;
535534 }
536535
536+ const getCategoryIcon = ( key : string ) => {
537+ switch ( key ) {
538+ case 'tools' :
539+ return < GearIcon className = "hidden md:block w-4 h-4 mr-1 flex-shrink-0" /> ;
540+ case 'tldr' :
541+ return < FileIcon className = "hidden md:block w-4 h-4 mr-1 flex-shrink-0" /> ;
542+ case 'cheatsheets' :
543+ return < FileTextIcon className = "hidden md:block w-4 h-4 mr-1 flex-shrink-0" /> ;
544+ case 'png_icons' :
545+ case 'svg_icons' :
546+ return < ImageIcon className = "hidden md:block w-4 h-4 mr-1 flex-shrink-0" /> ;
547+ case 'emoji' :
548+ return < RocketIcon className = "hidden md:block w-4 h-4 mr-1 flex-shrink-0" /> ;
549+ case 'mcp' :
550+ return < ModulzLogoIcon className = "hidden md:block w-4 h-4 mr-1 flex-shrink-0" /> ;
551+ default :
552+ return null ;
553+ }
554+ } ;
555+
537556 const categories = [
538- { key : 'all' , icon : null , label : 'All' } ,
539- { key : 'tools' , icon : 'ph:wrench' , label : 'Tools' } ,
540- { key : 'tldr' , icon : 'ic:baseline-menu-book' , label : 'TLDR' } ,
541- { key : 'cheatsheets' , icon : 'pepicons-pencil:file' , label : 'Cheatsheets' } ,
542- { key : 'png_icons' , icon : 'ph:file-png' , label : 'PNG Icons' } ,
543- { key : 'svg_icons' , icon : 'ph:file-svg' , label : 'SVG Icons' } ,
544- { key : 'emoji' , icon : 'ic:outline-emoji-emotions' , label : 'Emojis' } ,
545- { key : 'mcp' , icon : 'ic:outline-settings-suggest' , label : 'MCP' } ,
557+ { key : 'all' , label : 'All' } ,
558+ { key : 'tools' , label : 'Tools' } ,
559+ { key : 'tldr' , label : 'TLDR' } ,
560+ { key : 'cheatsheets' , label : 'Cheatsheets' } ,
561+ { key : 'png_icons' , label : 'PNG Icons' } ,
562+ { key : 'svg_icons' , label : 'SVG Icons' } ,
563+ { key : 'emoji' , label : 'Emojis' } ,
564+ { key : 'mcp' , label : 'MCP' } ,
546565 ] ;
547566
567+ const formatCount = ( count : number | undefined ) : string => {
568+ if ( count === undefined ) return '' ;
569+ if ( count > 999 ) {
570+ return `${ Math . floor ( count / 1000 ) } k+` ;
571+ }
572+ return count . toString ( ) ;
573+ } ;
574+
548575 const getAllCount = ( ) => {
549576 if ( Object . keys ( availableCategories ) . length === 0 ) return undefined ;
550577 return Object . values ( availableCategories ) . reduce (
@@ -579,7 +606,7 @@ const SearchPage: React.FC = () => {
579606 Esc
580607 </ kbd >
581608 < span className = "text-sm" > Clear results</ span >
582- < IconSvg iconName = "round-close" className = "h-4 w-4" />
609+ < Cross2Icon className = "h-4 w-4" />
583610 </ button >
584611 </ div >
585612
@@ -588,16 +615,15 @@ const SearchPage: React.FC = () => {
588615 < button
589616 onClick = { ( ) => handleCategoryClick ( 'all' ) }
590617 onContextMenu = { ( e ) => handleCategoryRightClick ( e , 'all' ) }
591- className = { `text-xs lg:text-sm w-full flex items-center justify-center gap-1 px-2 h-9 rounded-md whitespace-nowrap transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 ${
592- activeCategory === 'all'
593- ? 'bg-primary text-primary-foreground hover:bg-primary/90 shadow-md shadow-blue-500/50'
594- : 'border border-input bg-background hover:bg-accent hover:text-accent-foreground'
595- } `}
618+ className = { `text-xs lg:text-sm w-full flex items-center justify-center gap-1 px-2 h-9 rounded-md whitespace-nowrap transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 ${ activeCategory === 'all'
619+ ? 'bg-primary text-primary-foreground hover:bg-primary/90 shadow-md shadow-blue-500/50'
620+ : 'border border-input bg-background hover:bg-accent hover:text-accent-foreground'
621+ } `}
596622 >
597623 All{ ' ' }
598624 { activeCategory === 'all' &&
599625 Object . keys ( availableCategories ) . length > 0 &&
600- `(${ getAllCount ( ) } )` }
626+ `(${ formatCount ( getAllCount ( ) ) } )` }
601627 </ button >
602628
603629 { categories
@@ -612,30 +638,23 @@ const SearchPage: React.FC = () => {
612638 ? availableCategories [ category . key ]
613639 : undefined ) ;
614640
615- if ( ! category . icon ) return null ;
616641
617642 const buttonContent = (
618643 < >
619- < Icon
620- icon = { category . icon }
621- width = "18"
622- height = "16"
623- className = "lg:w-4 lg:h-4 flex-shrink-0"
624- />
644+ { getCategoryIcon ( category . key ) }
625645 < span className = "truncate" > { category . label } </ span >
626646 { count !== undefined && (
627647 < span className = "flex-shrink-0 ml-0.5" >
628- ({ count . toLocaleString ( ) } )
648+ ({ formatCount ( count ) } )
629649 </ span >
630650 ) }
631651 </ >
632652 ) ;
633653
634- const buttonClassName = `text-xs lg:text-sm w-full flex items-center gap-1 px-2 h-9 rounded-md whitespace-nowrap transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 ${
635- isActive || selectedCategories . includes ( category . key )
636- ? 'bg-primary text-primary-foreground hover:bg-primary/90 shadow-md shadow-blue-500/50'
637- : 'border border-input bg-background hover:bg-accent hover:text-accent-foreground hover:shadow-md hover:shadow-gray-500/30 dark:hover:bg-slate-900 dark:hover:shadow-slate-900/50'
638- } `;
654+ const buttonClassName = `text-xs lg:text-sm w-full flex items-center gap-1 px-2 h-9 rounded-md whitespace-nowrap transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 ${ isActive || selectedCategories . includes ( category . key )
655+ ? 'bg-primary text-primary-foreground hover:bg-primary/90 shadow-md shadow-blue-500/50'
656+ : 'border border-input bg-background hover:bg-accent hover:text-accent-foreground hover:shadow-md hover:shadow-gray-500/30 dark:hover:bg-slate-900 dark:hover:shadow-slate-900/50'
657+ } `;
639658
640659 if ( isActive || selectedCategories . includes ( category . key ) ) {
641660 return (
@@ -754,4 +773,4 @@ const SearchPage: React.FC = () => {
754773 ) ;
755774} ;
756775
757- export default SearchPage ;
776+ export default SearchPage ;
0 commit comments