diff --git a/packages/client/src/components/reviews/ReviewList.tsx b/packages/client/src/components/reviews/ReviewList.tsx index 8b9a79c..f0678b8 100644 --- a/packages/client/src/components/reviews/ReviewList.tsx +++ b/packages/client/src/components/reviews/ReviewList.tsx @@ -27,21 +27,12 @@ type SummarizeResponse = { }; const ReviewList = ({ productId }: Props) => { - const { - mutate: handleSummarize, - isPending: generatingSummary, - isSuccess: summaryRegenerated, - isError: summaryGenError, - } = useMutation({ + const reviewSummaryMutation = useMutation({ mutationFn: () => generateSummary(), }); - const { - data: reviewData, - isLoading, - error, - } = useQuery({ - queryKey: ['reviews', productId, summaryRegenerated], + const getReviewsQuery = useQuery({ + queryKey: ['reviews', productId, reviewSummaryMutation.isSuccess], queryFn: () => fetchReviews(), }); @@ -59,7 +50,7 @@ const ReviewList = ({ productId }: Props) => { return data; }; - if (isLoading) { + if (getReviewsQuery.isLoading) { return (
{[1, 2, 3].map((placeholder) => ( @@ -69,7 +60,7 @@ const ReviewList = ({ productId }: Props) => { ); } - if (error) { + if (getReviewsQuery.error) { return (

Could not fetch reviews, please try again. @@ -77,34 +68,36 @@ const ReviewList = ({ productId }: Props) => { ); } - if (!reviewData?.reviews.length) { + if (!getReviewsQuery.data?.reviews.length) { return null; } return (

- {reviewData?.summary ? ( -

{reviewData.summary}

- ) : generatingSummary ? ( + {getReviewsQuery.data?.summary ? ( +

{getReviewsQuery.data?.summary}

+ ) : reviewSummaryMutation.isPending ? (
) : ( )} - {summaryGenError && ( -

{summaryGenError}

+ {reviewSummaryMutation.isError && ( +

+ Could not generate review summary, please try again. +

)}
- {reviewData?.reviews.map((review) => ( + {getReviewsQuery.data?.reviews.map((review) => (
{review.author}