1 parent
e72e99a927
commit
4e270e616a
15 files changed
+120
-20
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { Check, Loader2 } from 'lucide-react'
|
||||
import { Check, Loader2, Lock } from 'lucide-react'
|
||||
import { useEffect, useLayoutEffect, useRef, useState } from 'react'
|
||||
import { locale, t } from '../i18n'
|
||||
import { getTmdbSeasonEpisodes, type EpisodeInfo } from '../lib/catalogApi'
|
||||
@@ -9,6 +9,8 @@ import type { MediaInput } from '../types'
|
||||
|
||||
interface Props {
|
||||
form: Pick<MediaInput, 'externalId' | 'episodesWatched' | 'episodesTotal' | 'seasons' | 'season'>
|
||||
/** Épisodes déjà sortis (toutes saisons), si on le sait : les suivants ne se cochent pas */
|
||||
aired?: number
|
||||
/** Nouveau nombre d'épisodes vus (et saison choisie) */
|
||||
onChange: (episodesWatched: number, season?: number) => void
|
||||
}
|
||||
@@ -19,7 +21,7 @@ const MAX_GENERIC = 500
|
||||
* Liste des épisodes, saison par saison (façon plateforme de streaming).
|
||||
* Toucher un épisode le marque comme vu, ainsi que tous ceux d'avant ; retoucher le dernier vu l'annule.
|
||||
*/
|
||||
export default function EpisodeList({ form, onChange }: Props) {
|
||||
export default function EpisodeList({ form, aired, onChange }: Props) {
|
||||
const { settings } = useMedia()
|
||||
const seasons = form.seasons
|
||||
const pos = seasonPosition(form)
|
||||
@@ -105,15 +107,19 @@ export default function EpisodeList({ form, onChange }: Props) {
|
||||
<div ref={listRef} className="max-h-[26rem] space-y-1 overflow-y-auto overscroll-contain pr-1">
|
||||
{rows.map((e) => {
|
||||
const seen = e.number <= watchedHere
|
||||
const upcoming = !!e.date && e.date > today
|
||||
// Pas encore sorti : date à venir (TMDB), ou au-delà des épisodes diffusés
|
||||
const upcoming = e.date ? e.date > today : aired != null && before + e.number > aired
|
||||
// Un épisode à venir ne se coche pas (mais on peut décocher une erreur passée)
|
||||
const locked = upcoming && !seen
|
||||
return (
|
||||
<button
|
||||
key={e.number}
|
||||
type="button"
|
||||
data-ep={e.number}
|
||||
onClick={() => toggle(e.number)}
|
||||
disabled={locked}
|
||||
aria-pressed={seen}
|
||||
className={cx('flex w-full items-center gap-3 rounded-xl p-1.5 text-left transition-colors active:bg-surface-2', upcoming && 'opacity-50')}
|
||||
className={cx('flex w-full items-center gap-3 rounded-xl p-1.5 text-left transition-colors', locked ? 'cursor-not-allowed' : 'active:bg-surface-2', upcoming && 'opacity-50')}
|
||||
>
|
||||
<span className="relative aspect-video w-28 shrink-0 overflow-hidden rounded-lg border border-line bg-surface-2">
|
||||
{e.still ? (
|
||||
@@ -134,10 +140,10 @@ export default function EpisodeList({ form, onChange }: Props) {
|
||||
<span
|
||||
className={cx(
|
||||
'grid size-7 shrink-0 place-items-center rounded-full border transition-colors',
|
||||
seen ? 'border-accent bg-accent-fill text-on-accent' : 'border-line-strong text-transparent',
|
||||
seen ? 'border-accent bg-accent-fill text-on-accent' : locked ? 'border-dashed border-line-strong text-ink-3' : 'border-line-strong text-transparent',
|
||||
)}
|
||||
>
|
||||
<Check size={14} strokeWidth={3} />
|
||||
{locked ? <Lock size={12} /> : <Check size={14} strokeWidth={3} />}
|
||||
</span>
|
||||
</button>
|
||||
)
|
||||
|
||||
@@ -2,22 +2,29 @@ import { Check, Info, Plus } from 'lucide-react'
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { t } from '../i18n'
|
||||
import { TYPE_BY_VALUE } from '../lib/constants'
|
||||
import { canWatchMore, nextAirDate } from '../lib/airing'
|
||||
import { episodeCap, seasonPosition } from '../lib/franchise'
|
||||
import { genreLabel } from '../lib/genres'
|
||||
import { cx } from '../lib/utils'
|
||||
import { cx, formatDate } from '../lib/utils'
|
||||
import { useMedia } from '../store'
|
||||
import type { MediaItem } from '../types'
|
||||
|
||||
/** Où j'en suis : « S2 · É3 » (épisode suivant à voir) */
|
||||
export function nextEpisodeLabel(item: MediaItem): string | undefined {
|
||||
if (!TYPE_BY_VALUE[item.type].episodic) return undefined
|
||||
const cap = episodeCap(item)
|
||||
if (cap && item.episodesWatched >= cap) return undefined
|
||||
if (!TYPE_BY_VALUE[item.type].episodic || !canWatchMore(item)) return undefined
|
||||
const pos = seasonPosition({ ...item, episodesWatched: item.episodesWatched + 1, season: undefined })
|
||||
const ep = t('episodes.short', { n: pos ? pos.episode : item.episodesWatched + 1 })
|
||||
return pos ? `${t('episodes.seasonShort', { n: pos.season })} · ${ep}` : ep
|
||||
}
|
||||
|
||||
/** Plus rien à cocher : « Tout vu », ou « Prochain épisode le … » si la suite n'est pas encore sortie. */
|
||||
export function waitingLabel(item: MediaItem): string {
|
||||
const cap = episodeCap(item)
|
||||
if (cap && item.episodesWatched >= cap) return t('hero.allSeen')
|
||||
const date = nextAirDate(item)
|
||||
return date ? t('hero.nextOn', { date: formatDate(date) }) : t('hero.upToDate')
|
||||
}
|
||||
|
||||
/** Grande bannière de l'accueil : défile entre les titres que je regarde en ce moment (ou le prochain à voir). */
|
||||
export default function HomeHero({ items, onOpen }: { items: MediaItem[]; onOpen: (item: MediaItem) => void }) {
|
||||
const { incrementEpisode } = useMedia()
|
||||
@@ -104,7 +111,7 @@ export default function HomeHero({ items, onOpen }: { items: MediaItem[]; onOpen
|
||||
</button>
|
||||
) : episodic ? (
|
||||
<span className="btn btn-ghost px-5">
|
||||
<Check size={17} /> {t('hero.allSeen')}
|
||||
<Check size={17} /> {waitingLabel(item)}
|
||||
</span>
|
||||
) : null}
|
||||
<button onClick={() => onOpen(item)} className="btn btn-ghost bg-bg/60 px-4">
|
||||
@@ -153,7 +160,7 @@ export function ContinueCard({ item, onOpen }: { item: MediaItem; onOpen: (item:
|
||||
</div>
|
||||
<button onClick={() => onOpen(item)} className="mt-2 block w-full text-left">
|
||||
<span className="block truncate text-sm font-semibold">{item.title}</span>
|
||||
<span className="block text-xs text-ink-3">{next ? t('homeHero.nextUp', { ep: next }) : t('hero.allSeen')}</span>
|
||||
<span className="block text-xs text-ink-3">{next ? t('homeHero.nextUp', { ep: next }) : waitingLabel(item)}</span>
|
||||
</button>
|
||||
</article>
|
||||
)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { t } from '../i18n'
|
||||
import { Heart, Plus } from 'lucide-react'
|
||||
import { TYPE_BY_VALUE } from '../lib/constants'
|
||||
import { canWatchMore } from '../lib/airing'
|
||||
import { episodeCap, seasonPosition } from '../lib/franchise'
|
||||
import { useMedia } from '../store'
|
||||
import type { MediaItem } from '../types'
|
||||
@@ -40,7 +41,7 @@ export function MediaCard({ item, onOpen }: { item: MediaItem; onOpen: (item: Me
|
||||
const canIncrement =
|
||||
TYPE_BY_VALUE[item.type].episodic &&
|
||||
item.status === 'en_cours' &&
|
||||
(!episodeCap(item) || item.episodesWatched < episodeCap(item)!)
|
||||
canWatchMore(item)
|
||||
|
||||
return (
|
||||
<article>
|
||||
|
||||
@@ -8,7 +8,8 @@ import { getTmdbCredits, getTmdbExtras } from '../lib/catalogApi'
|
||||
import { episodeCap, seasonPosition } from '../lib/franchise'
|
||||
import { renderItemCard, slug } from '../lib/shareCard'
|
||||
import { useScrollLock } from '../lib/scrollLock'
|
||||
import { cx, formatRating, todayISO } from '../lib/utils'
|
||||
import { cx, formatDate, formatRating, todayISO } from '../lib/utils'
|
||||
import { airedCount, nextAirDate, useAiringCache } from '../lib/airing'
|
||||
import { useMedia } from '../store'
|
||||
import type { MediaInput, MediaItem, RatingScale, WatchStatus } from '../types'
|
||||
import { StatusDot } from './Badges'
|
||||
@@ -203,10 +204,18 @@ export default function MediaForm({ item, onClose, onGoToSettings, onOpenItem }:
|
||||
}
|
||||
|
||||
/** Bouton principal de l'en-tête : épisode suivant (séries) ou « vu » (films). */
|
||||
// Épisodes déjà sortis (fiche suivie) : on ne coche pas un épisode à venir
|
||||
const airingCache = useAiringCache()
|
||||
const aired = item ? airedCount({ id: item.id, type: form.type, externalId: form.externalId }, airingCache) : undefined
|
||||
|
||||
const primary: HeroAction = (() => {
|
||||
if (typeInfo.episodic) {
|
||||
const cap = episodeCap(form)
|
||||
if (cap && form.episodesWatched >= cap) return { label: t('hero.allSeen'), done: true }
|
||||
if (aired != null && form.episodesWatched >= aired) {
|
||||
const date = item ? nextAirDate({ id: item.id, type: form.type, externalId: form.externalId }, airingCache) : undefined
|
||||
return { label: date ? t('hero.nextOn', { date: formatDate(date) }) : t('hero.upToDate'), done: true }
|
||||
}
|
||||
const nextPos = seasonPosition({ ...form, episodesWatched: form.episodesWatched + 1, season: undefined })
|
||||
const ep = t('episodes.short', { n: nextPos ? nextPos.episode : form.episodesWatched + 1 })
|
||||
const label = t('hero.seenEp', { ep: nextPos ? `${t('episodes.seasonShort', { n: nextPos.season })} · ${ep}` : ep })
|
||||
@@ -465,7 +474,7 @@ export default function MediaForm({ item, onClose, onGoToSettings, onOpenItem }:
|
||||
<Section title={t('form.episodes')}>
|
||||
{/* Liste d'épisodes pour une fiche liée (TMDB / AniList) ; compteur + total modifiable pour une fiche manuelle */}
|
||||
{form.seasons || (form.externalId && form.episodesTotal) ? (
|
||||
<EpisodeList form={form} onChange={(n, season) => setForm((f) => withEpisodes(f, n, season))} />
|
||||
<EpisodeList form={form} aired={aired} onChange={(n, season) => setForm((f) => withEpisodes(f, n, season))} />
|
||||
) : (
|
||||
<div className="card space-y-5 p-4">
|
||||
<div className="flex items-center justify-between">
|
||||
|
||||
Reference in new issue
Block a user