From 87f45ebfcb2d15b5d4212647a93cf346e7805568 Mon Sep 17 00:00:00 2001 From: Dillon Fagan Date: Tue, 29 Aug 2023 22:48:52 -0400 Subject: [PATCH] Filter things by spanish name if not null --- src/lib/utils/filters.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib/utils/filters.ts b/src/lib/utils/filters.ts index f67c824..7e660bc 100644 --- a/src/lib/utils/filters.ts +++ b/src/lib/utils/filters.ts @@ -6,10 +6,16 @@ export const filter = (things, { keyword, onlyWishList, category }) => { if (category && category.toLowerCase() !== "all") filtered = filtered.filter(thing => thing.categories.includes(category)); + if (keyword.length > 0) - filtered = filtered.filter(thing => thing.name.toLowerCase().includes(keyword.toLowerCase())); + filtered = filtered.filter(thing => { + return thing.name.toLowerCase().includes(keyword.toLowerCase()) + || (thing.spanishName && thing.spanishName?.toLowerCase().includes(keyword.toLowerCase())); + }); + if (onlyWishList) filtered = filtered.filter(thing => thing.stock < 1); + if (!onlyWishList) filtered = filtered.filter(thing => thing.stock !== 0);