import { Loader2, Star } from 'lucide-react' import { useEffect, useState } from 'react' import { t } from '../../i18n' import { getSession } from '../../lib/cloud/auth' import { useBlocked } from '../../lib/cloud/moderation' import { titleReviews, type TitleReview, type TitleReviews as TitleReviewsData } from '../../lib/cloud/reviews' import { formatRating } from '../../lib/utils' import { useMedia } from '../../store' import ReportButton from '../moderation/ReportButton' import Avatar from './Avatar' import Reactions from './Reactions' import ReviewComments from './ReviewComments' import ReviewText from './ReviewText' import Sheet from './Sheet' /** Écran plein : tous les avis sur un même titre (amis / autres membres) avec réactions. */ export default function TitleReviews({ externalId, title, onClose, onOpenProfile }: { externalId: string; title: string; onClose: () => void; onOpenProfile: (username: string) => void }) { const [data, setData] = useState() const [error, setError] = useState(false) // Avis des comptes que j'ai bloqués : masqués const { isBlocked } = useBlocked() useEffect(() => { let alive = true titleReviews(externalId) .then((d) => alive && setData(d)) .catch(() => alive && setError(true)) return () => { alive = false } }, [externalId]) const friends = data?.friends.filter((r) => !isBlocked(r.user_id)) ?? [] const others = data?.others.filter((r) => !isBlocked(r.user_id)) ?? [] const bothEmpty = !!data && friends.length === 0 && others.length === 0 return (

{t('reviews.title')}

{data === undefined && !error ? (

{t('social.loading')}

) : !data || error || bothEmpty ? (

{t('reviews.none')}

) : (
)}
) } function ReviewColumn({ heading, empty, list, onOpenProfile }: { heading: string; empty: string; list: TitleReview[]; onOpenProfile: (username: string) => void }) { return (

{heading}

{list.length === 0 ? (

{empty}

) : (
{list.map((r) => ( ))}
)}
) } function ReviewCard({ r, onOpenProfile }: { r: TitleReview; onOpenProfile: (username: string) => void }) { const { settings } = useMedia() // Mon propre avis : ni signalement ni réaction (seuls les commentaires restent) const mine = r.user_id === getSession()?.user.id return (
{r.rating != null && ( {formatRating(r.rating, settings.ratingScale)} )} {!mine && }
{r.notes && }
) }