fix(artplayer-wrapper): allow toggling rating by clicking the same star

- Modify handleStarClick to cancel rating when clicking the current rating again
- Update local average rating based on toggle logic
- Add localAvgRating as dependency to useCallback hook to keep updated state
This commit is contained in:
tigeren 2025-09-21 11:48:22 +00:00
parent dd08765ab9
commit 8f652fdf08
2 changed files with 6 additions and 3 deletions

Binary file not shown.

View File

@ -402,10 +402,13 @@ export default function ArtPlayerWrapper({
// Handle individual star click for rating // Handle individual star click for rating
const handleStarClick = useCallback((rating: number) => { const handleStarClick = useCallback((rating: number) => {
if (onRate) { if (onRate) {
onRate(video.id, rating); const currentRating = Math.round(localAvgRating);
setLocalAvgRating(rating); // If clicking the same star as current rating, cancel the rating
const newRating = currentRating === rating ? 0 : rating;
onRate(video.id, newRating);
setLocalAvgRating(newRating);
} }
}, [onRate, video.id]); }, [onRate, video.id, localAvgRating]);
// Format time display // Format time display
const formatTime = (time: number) => { const formatTime = (time: number) => {