Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/client/src/components/reviews/ReviewList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type SummarizeResponse = {
const ReviewList = ({ productId }: Props) => {
const [summaryRegenerated, setSummaryRegenerated] = useState(false);
const [generatingSummary, setGeneratingSummary] = useState(false);
const [summaryGenError, setSummaryGenError] = useState('');

const {
data: reviewData,
Expand All @@ -49,12 +50,16 @@ const ReviewList = ({ productId }: Props) => {

const generateSummary = async () => {
setGeneratingSummary(true);
setSummaryGenError('');
try {
const { data } = await axios.post<SummarizeResponse>(
`/api/products/${productId}/summaries`
);
setSummaryRegenerated(true);
return data;
} catch (error) {
console.error(error);
setSummaryGenError('Could not summarize the reviews. Try again.');
} finally {
setGeneratingSummary(false);
}
Expand Down Expand Up @@ -97,6 +102,9 @@ const ReviewList = ({ productId }: Props) => {
Summarize
</Button>
)}
{summaryGenError && (
<p className="text-red-500">{summaryGenError}</p>
)}
</div>
<div id="reviewlist" className="flex flex-col gap-5">
{reviewData?.reviews.map((review) => (
Expand Down