add Search to Library (#55)

* Implement bare bones library search

* Add nice interactions
This commit is contained in:
Sascha Hahne
2021-10-31 12:45:34 +01:00
committed by GitHub
parent 84ced87b5d
commit 9e65870fae
4 changed files with 78 additions and 7 deletions

View File

@@ -23,10 +23,15 @@ function unreadFilter(unread: NullAndUndefined<boolean>, { unreadCount }: IManga
}
}
function queryFilter(query: NullAndUndefined<string>, { title }: IMangaCard): boolean {
if (!query) return true;
return title.toLowerCase().includes(query.toLowerCase());
}
function filterManga(mangas: IMangaCard[]): IMangaCard[] {
const { unread } = useLibraryOptions();
const { unread, query } = useLibraryOptions();
return mangas
.filter((manga) => unreadFilter(unread, manga));
.filter((manga) => unreadFilter(unread, manga) && queryFilter(query, manga));
}
export default function LibraryMangaGrid(props: IMangaGridProps) {