import { Check, Loader2, MessagesSquare, Plus, Star } from 'lucide-react' import { useEffect, useState } from 'react' import { t } from '../../i18n' import { genreLabel } from '../../lib/genres' import { useBackToClose } from '../../lib/backNav' import { useScrollLock } from '../../lib/scrollLock' import { titleReviews, type TitleReview } from '../../lib/cloud/reviews' import { useSocial } from './SocialProvider' import { cx, formatDate, formatRating, normalizeText } from '../../lib/utils' import { GuestError, useMedia } from '../../store' import { useToast } from '../Toast' import type { MediaInput, MediaItem } from '../../types' import { StatusPill, TypeBadge } from '../Badges' import Poster from '../Poster' import ReportButton from '../moderation/ReportButton' import Avatar from './Avatar' import Reactions from './Reactions' import ReviewComments from './ReviewComments' import ReviewText from './ReviewText' import { useEscape } from '../../lib/escape' export interface PeekOwner { username: string displayName: string avatarUrl?: string } /** Aperçu d'un titre de quelqu'un d'autre : sa note, son avis public, et ajout à ma liste « À voir ». */ export default function ItemPeek({ item, owner, onClose }: { item: MediaItem; owner?: PeekOwner; onClose: () => void }) { const { items, add } = useMedia() const social = useSocial() const [busy, setBusy] = useState(false) const [added, setAdded] = useState(false) const toast = useToast() // Avis d'un autre membre : on récupère les réactions pour pouvoir réagir ici même const [review, setReview] = useState() const canReact = !!owner && owner.username !== social.me?.username && !!item.notes && !!item.externalId useEffect(() => { if (!canReact) return let alive = true titleReviews(item.externalId!) .then((d) => { if (!alive) return const all = [...d.friends, ...d.others] setReview(all.find((r) => r.user.username === owner!.username)) }) .catch(() => {}) return () => { alive = false } }, [canReact, item.externalId, owner]) const owned = items.some( (i) => (item.externalId && i.externalId === item.externalId) || normalizeText(i.title) === normalizeText(item.title), ) useScrollLock() useBackToClose(onClose) useEscape(onClose) const addToWatchlist = async () => { setBusy(true) try { const input: MediaInput = { title: item.title, originalTitle: item.originalTitle, type: item.type, subtype: item.subtype, year: item.year, status: 'a_voir', criteria: {}, episodesWatched: 0, episodesTotal: item.episodesTotal, seasons: item.seasons, episodeDuration: item.episodeDuration, duration: item.duration, genres: item.genres, platform: item.platform, poster: item.poster, backdrop: item.backdrop, overview: item.overview, externalId: item.externalId, countries: item.countries, publicRating: item.publicRating, } await add(input) setAdded(true) } catch (e) { // Mode découverte : l'invitation à créer un compte est déjà affichée if (!(e instanceof GuestError)) toast.show((e as Error).message) } finally { setBusy(false) } } return (
e.stopPropagation()} >

{item.title}

{item.originalTitle &&

{item.originalTitle}

}
{item.year && {item.year}}
{item.genres.length > 0 &&

{item.genres.slice(0, 3).map(genreLabel).join(' · ')}

}
{owner && (
{owner.displayName} {item.rating != null && ( {formatRating(item.rating)} )} {canReact && review && }
{item.endDate && item.status === 'termine' && {formatDate(item.endDate)}} {item.favorite && ♥ {t('form.favorite')}}
{item.notes && } {canReact && review && (
)}
)} {item.externalId && ( )} {item.overview &&

{item.overview}

}
) }