3
0
mirror of https://github.com/Qortal/q-shop.git synced 2025-01-30 14:52:20 +00:00

Merge pull request #2 from QuickMythril/id-fix

Filter reviews by matching case
This commit is contained in:
Qortal Dev 2024-04-17 08:03:50 -06:00 committed by GitHub
commit 7e650c49d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 3 deletions

View File

@ -505,9 +505,12 @@ export const Store = () => {
// Modify resource into data that is more easily used on the front end // Modify resource into data that is more easily used on the front end
const storeRatingsArray = responseData.map((review: any) => { const storeRatingsArray = responseData.map((review: any) => {
const splitIdentifier = review.identifier.split("-"); 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; const rating = Number(splitIdentifier[splitIdentifier.length - 1]) / 10;
return rating; return rating;
}); }).filter((rating: number | null) => rating !== null); // Filter out null entries
// Calculate average rating of the store // Calculate average rating of the store
let averageRating = let averageRating =

View File

@ -102,8 +102,11 @@ export const StoreReviews: FC<StoreReviewsProps> = ({
const responseData = await response.json(); const responseData = await response.json();
// Modify resource into data that is more easily used on the front end // Modify resource into data that is more easily used on the front end
const structuredReviewData = responseData.map( const structuredReviewData = responseData.map(
(review: any): StoreReview => { (review: any): StoreReview | null => {
const splitIdentifier = review.identifier.split("-"); 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 { return {
id: review?.identifier, id: review?.identifier,
name: review?.name, name: review?.name,
@ -114,7 +117,7 @@ export const StoreReviews: FC<StoreReviewsProps> = ({
rating: Number(splitIdentifier[splitIdentifier.length - 1]) / 10 rating: Number(splitIdentifier[splitIdentifier.length - 1]) / 10
}; };
} }
); ).filter((review: StoreReview | null) => review !== null); // Filter out null entries
setHasFetched(true); setHasFetched(true);
// Filter out duplicates by checking if the review id already exists in storeReviews in global redux store // Filter out duplicates by checking if the review id already exists in storeReviews in global redux store