Files
bobinoo/src/components/title/SeasonRatings.tsx
T
Claude ad211b8112 Notes en étoiles uniquement : plus d'échelle sur 10
- Réglage « Notation » retiré, ainsi que le curseur sur 10 et l'affichage « /10 »
  (fiche, cartes, Top 5, stats, filtres, carte de partage) : tout s'affiche sur 5 étoiles
- Les notes restent stockées comme avant (sur 10 en interne) : rien ne change pour les notes existantes
- Réglage ratingScale retiré des réglages synchronisés et des sauvegardes ; textes inutiles retirés (18 langues)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YVo1qxKoBQCaMd7Ue8PGbe
2026-11-27 16:22:07 +00:00

186 lines
6.5 KiB
TypeScript

import { Check, Pencil } from 'lucide-react'
import { useEffect, useRef, useState } from 'react'
import { t } from '../../i18n'
import { episodesBeforeSeason } from '../../lib/franchise'
import { seasonsAverage } from '../../lib/seasons'
import { cx, formatRating } from '../../lib/utils'
import type { MediaItem, SeasonRating } from '../../types'
import { RatingInput } from '../Rating'
/**
* « Mes saisons » : une note et un avis par saison.
* Une saison se note dès qu'on l'a commencée ; quand toute la série est vue, la note finale
* devient la moyenne des saisons notées (calculée dans le store).
*/
export default function SeasonRatings({
item,
highlight,
onChange,
}: {
item: MediaItem
/** Saison à mettre en avant (on vient de la finir) */
highlight?: number
onChange: (seasonRatings: MediaItem['seasonRatings']) => void
}) {
const seasons = item.seasons ?? []
const ratings: Record<string, SeasonRating> = item.seasonRatings ?? {}
const avg = seasonsAverage(ratings)
const set = (n: number, patch: Partial<SeasonRating>) => {
const key = String(n)
const next: Record<string, SeasonRating> = { ...ratings, [key]: { ...ratings[key], ...patch } }
const cur = next[key]
if (cur.rating == null && !cur.notes) delete next[key]
onChange(Object.keys(next).length ? next : undefined)
}
return (
<section className="mx-4 mt-6" aria-label={t('seasons.title')}>
<div className="mb-2 flex items-baseline justify-between gap-3">
<h3 className="eyebrow text-ink-2">{t('seasons.title')}</h3>
{avg != null && (
<span className="text-xs text-ink-3">
{t('seasons.average')} <span className="font-semibold text-ink">{formatRating(avg)}</span>
</span>
)}
</div>
<p className="mb-3 text-xs leading-relaxed text-ink-3">{t('seasons.hint')}</p>
<ul className="space-y-2">
{seasons.map((size, k) => {
const n = k + 1
const before = episodesBeforeSeason(seasons, n)
const seen = Math.max(0, Math.min(size, item.episodesWatched - before))
return (
<SeasonRow
key={n}
n={n}
size={size}
seen={seen}
value={ratings[String(n)]}
highlight={highlight === n}
onChange={(patch) => set(n, patch)}
/>
)
})}
</ul>
</section>
)
}
function SeasonRow({
n,
size,
seen,
value,
highlight,
onChange,
}: {
n: number
size: number
seen: number
value?: SeasonRating
highlight: boolean
onChange: (patch: Partial<SeasonRating>) => void
}) {
const started = seen > 0
const done = seen >= size
const [writing, setWriting] = useState(false)
const [draft, setDraft] = useState(value?.notes ?? '')
const [spoiler, setSpoiler] = useState(!!value?.spoiler)
const ref = useRef<HTMLLIElement>(null)
// Saison qu'on vient de finir : on l'amène à l'écran
useEffect(() => {
if (highlight) ref.current?.scrollIntoView({ behavior: 'smooth', block: 'center' })
}, [highlight])
// À l'ouverture de l'éditeur : on repart de l'avis enregistré (il a pu changer depuis, ex. synchro)
const openEditor = () => {
setDraft(value?.notes ?? '')
setSpoiler(!!value?.spoiler)
setWriting(true)
}
return (
<li ref={ref} id={`season-${n}`} className={cx('card p-3.5 transition-shadow', highlight && 'ring-2 ring-accent')}>
<div className="flex items-center justify-between gap-3">
<div className="min-w-0">
<p className="font-semibold">{t('seasons.season', { n })}</p>
<p className={cx('text-xs', done ? 'text-ink-2' : 'text-ink-3')}>
{done ? (
<span className="inline-flex items-center gap-1">
<Check size={12} className="text-accent" /> {t('seasons.seen')}
</span>
) : started ? (
t('seasons.progress', { seen, size })
) : (
t('seasons.notStarted')
)}
</p>
</div>
{highlight && !value?.rating && <span className="eyebrow shrink-0 text-accent">{t('seasons.rateNow')}</span>}
</div>
{started && (
<div className="mt-2.5">
<RatingInput value={value?.rating} onChange={(rating) => onChange({ rating })} size="sm" label={t('seasons.season', { n })} />
</div>
)}
{started &&
(writing ? (
<div className="mt-3">
<textarea
value={draft}
onChange={(e) => setDraft(e.target.value)}
maxLength={5000}
rows={4}
autoFocus
placeholder={t('seasons.reviewPh', { n })}
className="field resize-y text-sm"
/>
<label className="mt-2 flex items-center gap-2 text-xs text-ink-2">
<input type="checkbox" checked={spoiler} onChange={(e) => setSpoiler(e.target.checked)} className="accent-[var(--color-accent)]" />
{t('spoiler.checkbox')}
</label>
<div className="mt-2.5 flex justify-end gap-2">
<button
onClick={() => {
setDraft(value?.notes ?? '')
setWriting(false)
}}
className="btn btn-ghost px-4 py-2 text-sm"
>
{t('common.cancel')}
</button>
<button
onClick={() => {
const notes = draft.trim() || undefined
onChange({ notes, spoiler: notes && spoiler ? true : undefined })
setWriting(false)
}}
className="btn btn-primary px-4 py-2 text-sm"
>
{t('common.save')}
</button>
</div>
</div>
) : value?.notes ? (
<button onClick={openEditor} className="mt-3 block w-full text-start">
<span className="flex items-center gap-1.5 text-xs text-ink-3">
{t('form.review')}
{value.spoiler && <span className="rounded-md border border-accent/50 px-1.5 py-px text-[10px] text-accent">{t('spoiler.badge')}</span>}
<Pencil size={11} />
</span>
<p className="mt-1 line-clamp-4 whitespace-pre-line text-sm leading-relaxed">{value.notes}</p>
</button>
) : (
<button onClick={openEditor} className="mt-2.5 inline-flex items-center gap-1.5 text-xs font-medium text-ink-2">
<Pencil size={12} /> {t('seasons.writeReview')}
</button>
))}
</li>
)
}