Skip to content

Commit

Permalink
FIX: filter in album list
Browse files Browse the repository at this point in the history
  • Loading branch information
rigon committed May 20, 2023
1 parent 78418d3 commit 687f157
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "photo-gallery",
"private": true,
"version": "1.3.0",
"version": "1.3.1",
"type": "module",
"scripts": {
"start": "vite",
Expand Down
12 changes: 8 additions & 4 deletions src/AlbumList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC, useState } from 'react';
import { FC, useMemo, useState } from 'react';
import { useParams, Link } from 'react-router-dom';
import { FixedSizeList, ListChildComponentProps } from 'react-window';
import AutoSizer from 'react-virtualized-auto-sizer';
Expand All @@ -25,11 +25,15 @@ interface AlbumListProps {

const AlbumList: FC<AlbumListProps> = ({onClick}) => {
const { collection, album } = useParams();
const { data: albums = [], isFetching } = useGetAlbumsQuery({collection}, {skip: collection === undefined});
const { data = [], isFetching } = useGetAlbumsQuery({collection}, {skip: collection === undefined});
const [ searchTerm, setSearchTerm ] = useState<string>("");

const albums = useMemo(() => searchTerm.length < 1 ? data :
data.filter((album) => album.name.toLowerCase().includes(searchTerm)),
[searchTerm, data]);

const onSearch = (event: React.ChangeEvent<HTMLInputElement>) => {
setSearchTerm(event.target.value);
setSearchTerm(event.target.value.toLowerCase());
};
const clearSearch = () => {
setSearchTerm("");
Expand Down Expand Up @@ -57,7 +61,7 @@ const AlbumList: FC<AlbumListProps> = ({onClick}) => {


const list = albums.length < 1 ?
<ListItem><em>Nothing to show</em></ListItem> :
<ListItem><ListItemText><em>Nothing to show</em></ListItemText></ListItem> :
<AutoSizer>
{({ height, width }) =>
<FixedSizeList
Expand Down

0 comments on commit 687f157

Please sign in to comment.