'use client'; import { useState } from 'react'; interface StoryRatingProps { rating: number; onRatingChange: (rating: number) => void; readonly?: boolean; size?: 'sm' | 'md' | 'lg'; } export default function StoryRating({ rating, onRatingChange, readonly = false, size = 'md' }: StoryRatingProps) { const [hoveredRating, setHoveredRating] = useState(0); const [updating, setUpdating] = useState(false); const sizeClasses = { sm: 'text-sm', md: 'text-lg', lg: 'text-2xl', }; const handleRatingClick = async (newRating: number) => { if (readonly || updating) return; try { setUpdating(true); await onRatingChange(newRating); } catch (error) { console.error('Failed to update rating:', error); } finally { setUpdating(false); } }; const displayRating = hoveredRating || rating; return (
{[1, 2, 3, 4, 5].map((star) => ( ))} {!readonly && ( {rating > 0 ? `(${rating}/5)` : 'Rate this story'} )} {updating && ( Saving... )}
); }