From 515fdf0baa782ec3117df49dbdd29a8b78da950d Mon Sep 17 00:00:00 2001 From: LuisMSuarez <140195810+LuisMSuarez@users.noreply.github.com> Date: Fri, 24 Oct 2025 10:33:05 -0700 Subject: [PATCH] Button and generation of review summary --- .../src/components/reviews/ReviewList.tsx | 48 +++++++++++++++---- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/packages/client/src/components/reviews/ReviewList.tsx b/packages/client/src/components/reviews/ReviewList.tsx index 749a91e..87d0fd2 100644 --- a/packages/client/src/components/reviews/ReviewList.tsx +++ b/packages/client/src/components/reviews/ReviewList.tsx @@ -1,7 +1,10 @@ import axios from 'axios'; import Skeleton from 'react-loading-skeleton'; import StarRating from './StarRating'; +import { HiSparkles } from 'react-icons/hi2'; import { useQuery } from '@tanstack/react-query'; +import { Button } from '../ui/button'; +import { useState } from 'react'; interface Props { productId: number; @@ -21,12 +24,13 @@ type GetReviewsResponse = { }; const ReviewList = ({ productId }: Props) => { + const [summaryRegenerated, setSummaryRegenerated] = useState(false); const { data: reviewData, isLoading, error, } = useQuery({ - queryKey: ['reviews', productId], + queryKey: ['reviews', productId, summaryRegenerated], queryFn: () => fetchReviews(), }); @@ -37,6 +41,14 @@ const ReviewList = ({ productId }: Props) => { return data; }; + const generateSummary = async () => { + const { data } = await axios.post( + `/api/products/${productId}/summaries` + ); + setSummaryRegenerated(true); + return data; + }; + if (isLoading) { return (
@@ -59,17 +71,33 @@ const ReviewList = ({ productId }: Props) => { ); } + if (!reviewData?.reviews.length) { + return null; + } + return ( -
- {reviewData?.reviews.map((review) => ( -
-
{review.author}
-
- +
+
+ {reviewData?.summary ? ( +

{reviewData.summary}

+ ) : ( + + )} +
+
+ {reviewData?.reviews.map((review) => ( +
+
{review.author}
+
+ +
+

{review.content}

-

{review.content}

-
- ))} + ))} +
); };