@@ -14,6 +14,7 @@ import DialogTitle from '@mui/material/DialogTitle';
14
14
import IconButton from '@mui/material/IconButton' ;
15
15
import Tooltip from '@mui/material/Tooltip' ;
16
16
import Button from '@mui/material/Button' ;
17
+ import Stack from '@mui/material/Stack' ;
17
18
import * as flexsearch from 'flexsearch' ;
18
19
import SearchIcon from '@mui/icons-material/Search' ;
19
20
import FormControlLabel from '@mui/material/FormControlLabel' ;
@@ -478,11 +479,14 @@ function useLatest(value) {
478
479
return value ?? latest . current ;
479
480
}
480
481
482
+
481
483
export default function SearchIcons ( ) {
482
484
const [ keys , setKeys ] = React . useState ( null ) ;
483
485
const [ theme , setTheme ] = useQueryParameterState ( 'theme' , 'All' ) ;
484
486
const [ selectedIcon , setSelectedIcon ] = useQueryParameterState ( 'selected' , '' ) ;
485
487
const [ query , setQuery ] = useQueryParameterState ( 'query' , '' ) ;
488
+ const [ isPending , startUpdateSearchTransition ] = React . useTransition ( ) ;
489
+ const [ minIcons , setMinIcons ] = React . useState ( 49 ) ;
486
490
487
491
const handleOpenClick = React . useCallback (
488
492
( event ) => {
@@ -518,10 +522,10 @@ export default function SearchIcons() {
518
522
) ;
519
523
520
524
React . useEffect ( ( ) => {
521
- updateSearchResults ( query ) ;
522
- return ( ) => {
523
- updateSearchResults . clear ( ) ;
524
- } ;
525
+ startUpdateSearchTransition ( ( ) => updateSearchResults ( query ) ) ;
526
+ setMinIcons ( 49 ) ;
527
+
528
+ return ( ) => updateSearchResults . clear ( ) ;
525
529
} , [ query , updateSearchResults ] ) ;
526
530
527
531
const icons = React . useMemo (
@@ -532,6 +536,8 @@ export default function SearchIcons() {
532
536
[ theme , keys ] ,
533
537
) ;
534
538
539
+ const totalNumIcons = icons . length ;
540
+
535
541
const dialogSelectedIcon = useLatest (
536
542
selectedIcon ? allIconsMap [ selectedIcon ] : null ,
537
543
) ;
@@ -574,14 +580,36 @@ export default function SearchIcons() {
574
580
autoFocus
575
581
value = { query }
576
582
onChange = { ( event ) => setQuery ( event . target . value ) }
577
- placeholder = " Search icons…"
583
+ placeholder = { ` Search over ${ formatNumber ( totalNumIcons ) } available icons...` }
578
584
inputProps = { { 'aria-label' : 'search icons' } }
579
585
/>
580
586
</ Paper >
581
- < Typography sx = { { mb : 1 } } > { `${ formatNumber (
582
- icons . length ,
583
- ) } matching results`} </ Typography >
584
- < Icons icons = { icons } handleOpenClick = { handleOpenClick } />
587
+ { query . length > 0 && (
588
+ < Typography variant = "subtitle1" sx = { { mb : 1 } } >
589
+ { isPending
590
+ ? `loading...`
591
+ : `${ formatNumber ( totalNumIcons ) } matching results` }
592
+ </ Typography >
593
+ ) }
594
+ { ! isPending && (
595
+ < Stack spacing = { 4 } sx = { { height : '100%' } } >
596
+ < Icons
597
+ icons = { icons . slice ( 0 , minIcons ) }
598
+ handleOpenClick = { handleOpenClick }
599
+ />
600
+ { totalNumIcons > minIcons && (
601
+ < Button
602
+ size = "small"
603
+ color = "primary"
604
+ variant = "outlined"
605
+ sx = { { mt : 'auto' } }
606
+ onClick = { ( ) => setMinIcons ( ( m ) => ( m += 49 ) ) }
607
+ >
608
+ View more
609
+ </ Button >
610
+ ) }
611
+ </ Stack >
612
+ ) }
585
613
</ Grid >
586
614
< DialogDetails
587
615
open = { ! ! selectedIcon }
0 commit comments