From fea2a242170c4aa741f2ca4a5341fe6eebd26c12 Mon Sep 17 00:00:00 2001 From: QuickMythril Date: Mon, 8 Apr 2024 11:43:17 -0400 Subject: [PATCH 1/2] Filter reviews by matching case --- src/pages/Store/StoreReviews/StoreReviews.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pages/Store/StoreReviews/StoreReviews.tsx b/src/pages/Store/StoreReviews/StoreReviews.tsx index 277895e..b220fcc 100644 --- a/src/pages/Store/StoreReviews/StoreReviews.tsx +++ b/src/pages/Store/StoreReviews/StoreReviews.tsx @@ -102,8 +102,11 @@ export const StoreReviews: FC = ({ const responseData = await response.json(); // Modify resource into data that is more easily used on the front end const structuredReviewData = responseData.map( - (review: any): StoreReview => { + (review: any): StoreReview | null => { const splitIdentifier = review.identifier.split("-"); + // Return null if idenfier is not an exact match, because search is not case sensitive + const prefixIdentifier = splitIdentifier.slice(0, splitIdentifier.length - 2).join("-"); + if (query !== prefixIdentifier) return null; return { id: review?.identifier, name: review?.name, @@ -114,7 +117,7 @@ export const StoreReviews: FC = ({ rating: Number(splitIdentifier[splitIdentifier.length - 1]) / 10 }; } - ); + ).filter((review: StoreReview | null) => review !== null); // Filter out null entries setHasFetched(true); // Filter out duplicates by checking if the review id already exists in storeReviews in global redux store From 6922efd9ff559feb59fdce43a53945f9ec678fc5 Mon Sep 17 00:00:00 2001 From: QuickMythril Date: Fri, 12 Apr 2024 14:56:35 -0400 Subject: [PATCH 2/2] Filter reviews when calculating average rating --- src/pages/Store/Store/Store.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pages/Store/Store/Store.tsx b/src/pages/Store/Store/Store.tsx index e9f9fee..8919a5d 100644 --- a/src/pages/Store/Store/Store.tsx +++ b/src/pages/Store/Store/Store.tsx @@ -505,9 +505,12 @@ export const Store = () => { // Modify resource into data that is more easily used on the front end const storeRatingsArray = responseData.map((review: any) => { const splitIdentifier = review.identifier.split("-"); + // Return null if idenfier is not an exact match, because search is not case sensitive + const prefixIdentifier = splitIdentifier.slice(0, splitIdentifier.length - 2).join("-"); + if (query !== prefixIdentifier) return null; const rating = Number(splitIdentifier[splitIdentifier.length - 1]) / 10; return rating; - }); + }).filter((rating: number | null) => rating !== null); // Filter out null entries // Calculate average rating of the store let averageRating =