Notes par saison : note + avis par saison, note finale = moyenne arrondie
deploy / deploy (push) Successful in 43s
deploy / deploy (push) Successful in 43s
- Section « Mes saisons » dans la fiche d'une série (≥ 2 saisons) : une note et un avis (avec spoiler) par saison. - Quand la série est terminée, la note finale = moyenne des saisons notées, arrondie (étoiles et /10). - Les séries déjà notées sans notes de saison restent intactes. - Un +1 qui termine une saison ouvre la fiche sur cette saison à noter ; « Reprendre » passe à S02 É01. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YVo1qxKoBQCaMd7Ue8PGbe
This commit is contained in:
26 files changed
+540
-11
No files matched your search
@@ -0,0 +1,182 @@
|
||||
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, RatingScale, 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,
|
||||
scale,
|
||||
highlight,
|
||||
onChange,
|
||||
}: {
|
||||
item: MediaItem
|
||||
scale: RatingScale
|
||||
/** 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, scale)
|
||||
|
||||
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, scale)}</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)]}
|
||||
scale={scale}
|
||||
highlight={highlight === n}
|
||||
onChange={(patch) => set(n, patch)}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
</ul>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
function SeasonRow({
|
||||
n,
|
||||
size,
|
||||
seen,
|
||||
value,
|
||||
scale,
|
||||
highlight,
|
||||
onChange,
|
||||
}: {
|
||||
n: number
|
||||
size: number
|
||||
seen: number
|
||||
value?: SeasonRating
|
||||
scale: RatingScale
|
||||
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])
|
||||
|
||||
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 })} scale={scale} 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={() => setWriting(true)} 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-full 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={() => setWriting(true)} 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>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user