@@ -26,26 +26,28 @@ interface AlbumListProps {
2626const AlbumList : FC < AlbumListProps > = ( { onClick} ) => {
2727 const { collection, album } = useParams ( ) ;
2828 const { data = [ ] , isFetching } = useGetAlbumsQuery ( { collection} , { skip : collection === undefined } ) ;
29- const [ searchTerm , setSearchTerm ] = useState < string > ( "" ) ;
29+ const [ searchTerm , setSearchTerm ] = useState < string [ ] > ( [ ] ) ;
3030
3131 const albums = useMemo ( ( ) => searchTerm . length < 1 ? data :
32- data . filter ( ( album ) => album . name . toLowerCase ( ) . includes ( searchTerm ) ) ,
33- [ searchTerm , data ] ) ;
32+ data . filter ( album => {
33+ const low = album . name . toLowerCase ( ) ;
34+ return searchTerm . reduce ( ( acc , term ) => acc && low . includes ( term ) , true ) ;
35+ } ) , [ searchTerm , data ] ) ;
3436
3537 const onSearch = ( event : React . ChangeEvent < HTMLInputElement > ) => {
36- setSearchTerm ( event . target . value . toLowerCase ( ) ) ;
38+ setSearchTerm ( event . target . value . toLowerCase ( ) . split ( / \s + / ) ) ;
3739 } ;
3840 const clearSearch = ( ) => {
39- setSearchTerm ( "" ) ;
41+ setSearchTerm ( [ ] ) ;
4042 } ;
4143
4244 const renderRow = ( { index, style } : ListChildComponentProps < AlbumType > ) => {
43- const a = albums [ index ] ;
45+ const current = albums [ index ] ;
4446 return (
45- < ListItem onClick = { onClick } style = { style } key = { a . name } disablePadding >
46- < ListItemButton component = { Link } to = { `/${ collection } /${ a . name } ` } selected = { a . name === album } >
47+ < ListItem onClick = { onClick } style = { style } key = { current . name } disablePadding >
48+ < ListItemButton component = { Link } to = { `/${ collection } /${ current . name } ` } selected = { current . name === album } >
4749 < ListItemText >
48- < Typography noWrap > { a . name } </ Typography >
50+ < Typography noWrap > { current . name } </ Typography >
4951 </ ListItemText >
5052 </ ListItemButton >
5153 </ ListItem >
@@ -78,7 +80,6 @@ const AlbumList: FC<AlbumListProps> = ({onClick}) => {
7880 return < >
7981 < TextField
8082 label = "Search albums"
81- value = { searchTerm }
8283 onChange = { onSearch }
8384 fullWidth
8485 variant = "filled"
0 commit comments