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 { useEffect, useLayoutEffect, useRef, useState } from 'react'
|
||||||
import { locale, t } from '../i18n'
|
import { locale, t } from '../i18n'
|
||||||
import { getTmdbSeasonEpisodes, type EpisodeInfo } from '../lib/catalogApi'
|
import { getTmdbSeasonEpisodes, type EpisodeInfo } from '../lib/catalogApi'
|
||||||
@@ -9,6 +9,8 @@ import type { MediaInput } from '../types'
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
form: Pick<MediaInput, 'externalId' | 'episodesWatched' | 'episodesTotal' | 'seasons' | 'season'>
|
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) */
|
/** Nouveau nombre d'épisodes vus (et saison choisie) */
|
||||||
onChange: (episodesWatched: number, season?: number) => void
|
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).
|
* 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.
|
* 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 { settings } = useMedia()
|
||||||
const seasons = form.seasons
|
const seasons = form.seasons
|
||||||
const pos = seasonPosition(form)
|
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">
|
<div ref={listRef} className="max-h-[26rem] space-y-1 overflow-y-auto overscroll-contain pr-1">
|
||||||
{rows.map((e) => {
|
{rows.map((e) => {
|
||||||
const seen = e.number <= watchedHere
|
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 (
|
return (
|
||||||
<button
|
<button
|
||||||
key={e.number}
|
key={e.number}
|
||||||
type="button"
|
type="button"
|
||||||
data-ep={e.number}
|
data-ep={e.number}
|
||||||
onClick={() => toggle(e.number)}
|
onClick={() => toggle(e.number)}
|
||||||
|
disabled={locked}
|
||||||
aria-pressed={seen}
|
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">
|
<span className="relative aspect-video w-28 shrink-0 overflow-hidden rounded-lg border border-line bg-surface-2">
|
||||||
{e.still ? (
|
{e.still ? (
|
||||||
@@ -134,10 +140,10 @@ export default function EpisodeList({ form, onChange }: Props) {
|
|||||||
<span
|
<span
|
||||||
className={cx(
|
className={cx(
|
||||||
'grid size-7 shrink-0 place-items-center rounded-full border transition-colors',
|
'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>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,22 +2,29 @@ import { Check, Info, Plus } from 'lucide-react'
|
|||||||
import { useEffect, useRef, useState } from 'react'
|
import { useEffect, useRef, useState } from 'react'
|
||||||
import { t } from '../i18n'
|
import { t } from '../i18n'
|
||||||
import { TYPE_BY_VALUE } from '../lib/constants'
|
import { TYPE_BY_VALUE } from '../lib/constants'
|
||||||
|
import { canWatchMore, nextAirDate } from '../lib/airing'
|
||||||
import { episodeCap, seasonPosition } from '../lib/franchise'
|
import { episodeCap, seasonPosition } from '../lib/franchise'
|
||||||
import { genreLabel } from '../lib/genres'
|
import { genreLabel } from '../lib/genres'
|
||||||
import { cx } from '../lib/utils'
|
import { cx, formatDate } from '../lib/utils'
|
||||||
import { useMedia } from '../store'
|
import { useMedia } from '../store'
|
||||||
import type { MediaItem } from '../types'
|
import type { MediaItem } from '../types'
|
||||||
|
|
||||||
/** Où j'en suis : « S2 · É3 » (épisode suivant à voir) */
|
/** Où j'en suis : « S2 · É3 » (épisode suivant à voir) */
|
||||||
export function nextEpisodeLabel(item: MediaItem): string | undefined {
|
export function nextEpisodeLabel(item: MediaItem): string | undefined {
|
||||||
if (!TYPE_BY_VALUE[item.type].episodic) return undefined
|
if (!TYPE_BY_VALUE[item.type].episodic || !canWatchMore(item)) return undefined
|
||||||
const cap = episodeCap(item)
|
|
||||||
if (cap && item.episodesWatched >= cap) return undefined
|
|
||||||
const pos = seasonPosition({ ...item, episodesWatched: item.episodesWatched + 1, season: undefined })
|
const pos = seasonPosition({ ...item, episodesWatched: item.episodesWatched + 1, season: undefined })
|
||||||
const ep = t('episodes.short', { n: pos ? pos.episode : item.episodesWatched + 1 })
|
const ep = t('episodes.short', { n: pos ? pos.episode : item.episodesWatched + 1 })
|
||||||
return pos ? `${t('episodes.seasonShort', { n: pos.season })} · ${ep}` : ep
|
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). */
|
/** 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 }) {
|
export default function HomeHero({ items, onOpen }: { items: MediaItem[]; onOpen: (item: MediaItem) => void }) {
|
||||||
const { incrementEpisode } = useMedia()
|
const { incrementEpisode } = useMedia()
|
||||||
@@ -104,7 +111,7 @@ export default function HomeHero({ items, onOpen }: { items: MediaItem[]; onOpen
|
|||||||
</button>
|
</button>
|
||||||
) : episodic ? (
|
) : episodic ? (
|
||||||
<span className="btn btn-ghost px-5">
|
<span className="btn btn-ghost px-5">
|
||||||
<Check size={17} /> {t('hero.allSeen')}
|
<Check size={17} /> {waitingLabel(item)}
|
||||||
</span>
|
</span>
|
||||||
) : null}
|
) : null}
|
||||||
<button onClick={() => onOpen(item)} className="btn btn-ghost bg-bg/60 px-4">
|
<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>
|
</div>
|
||||||
<button onClick={() => onOpen(item)} className="mt-2 block w-full text-left">
|
<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 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>
|
</button>
|
||||||
</article>
|
</article>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { t } from '../i18n'
|
import { t } from '../i18n'
|
||||||
import { Heart, Plus } from 'lucide-react'
|
import { Heart, Plus } from 'lucide-react'
|
||||||
import { TYPE_BY_VALUE } from '../lib/constants'
|
import { TYPE_BY_VALUE } from '../lib/constants'
|
||||||
|
import { canWatchMore } from '../lib/airing'
|
||||||
import { episodeCap, seasonPosition } from '../lib/franchise'
|
import { episodeCap, seasonPosition } from '../lib/franchise'
|
||||||
import { useMedia } from '../store'
|
import { useMedia } from '../store'
|
||||||
import type { MediaItem } from '../types'
|
import type { MediaItem } from '../types'
|
||||||
@@ -40,7 +41,7 @@ export function MediaCard({ item, onOpen }: { item: MediaItem; onOpen: (item: Me
|
|||||||
const canIncrement =
|
const canIncrement =
|
||||||
TYPE_BY_VALUE[item.type].episodic &&
|
TYPE_BY_VALUE[item.type].episodic &&
|
||||||
item.status === 'en_cours' &&
|
item.status === 'en_cours' &&
|
||||||
(!episodeCap(item) || item.episodesWatched < episodeCap(item)!)
|
canWatchMore(item)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<article>
|
<article>
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ import { getTmdbCredits, getTmdbExtras } from '../lib/catalogApi'
|
|||||||
import { episodeCap, seasonPosition } from '../lib/franchise'
|
import { episodeCap, seasonPosition } from '../lib/franchise'
|
||||||
import { renderItemCard, slug } from '../lib/shareCard'
|
import { renderItemCard, slug } from '../lib/shareCard'
|
||||||
import { useScrollLock } from '../lib/scrollLock'
|
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 { useMedia } from '../store'
|
||||||
import type { MediaInput, MediaItem, RatingScale, WatchStatus } from '../types'
|
import type { MediaInput, MediaItem, RatingScale, WatchStatus } from '../types'
|
||||||
import { StatusDot } from './Badges'
|
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). */
|
/** 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 = (() => {
|
const primary: HeroAction = (() => {
|
||||||
if (typeInfo.episodic) {
|
if (typeInfo.episodic) {
|
||||||
const cap = episodeCap(form)
|
const cap = episodeCap(form)
|
||||||
if (cap && form.episodesWatched >= cap) return { label: t('hero.allSeen'), done: true }
|
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 nextPos = seasonPosition({ ...form, episodesWatched: form.episodesWatched + 1, season: undefined })
|
||||||
const ep = t('episodes.short', { n: nextPos ? nextPos.episode : form.episodesWatched + 1 })
|
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 })
|
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')}>
|
<Section title={t('form.episodes')}>
|
||||||
{/* Liste d'épisodes pour une fiche liée (TMDB / AniList) ; compteur + total modifiable pour une fiche manuelle */}
|
{/* Liste d'épisodes pour une fiche liée (TMDB / AniList) ; compteur + total modifiable pour une fiche manuelle */}
|
||||||
{form.seasons || (form.externalId && form.episodesTotal) ? (
|
{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="card space-y-5 p-4">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
|
|||||||
@@ -737,6 +737,8 @@ const dict: Translations = {
|
|||||||
'form.startShort': "Begonnen",
|
'form.startShort': "Begonnen",
|
||||||
'form.endShort': "Beendet",
|
'form.endShort': "Beendet",
|
||||||
'hero.allSeen': "Alles gesehen",
|
'hero.allSeen': "Alles gesehen",
|
||||||
|
'hero.nextOn': 'Nächste Folge am {date}',
|
||||||
|
'hero.upToDate': 'Auf dem neuesten Stand',
|
||||||
'hero.seenEp': "{ep} gesehen",
|
'hero.seenEp': "{ep} gesehen",
|
||||||
'hero.seen': "Gesehen",
|
'hero.seen': "Gesehen",
|
||||||
'hero.markSeen': "Als gesehen markieren",
|
'hero.markSeen': "Als gesehen markieren",
|
||||||
|
|||||||
@@ -737,6 +737,8 @@ const dict: Translations = {
|
|||||||
'form.startShort': "Started",
|
'form.startShort': "Started",
|
||||||
'form.endShort': "Finished",
|
'form.endShort': "Finished",
|
||||||
'hero.allSeen': "All watched",
|
'hero.allSeen': "All watched",
|
||||||
|
'hero.nextOn': 'Next episode on {date}',
|
||||||
|
'hero.upToDate': 'Up to date',
|
||||||
'hero.seenEp': "Watched {ep}",
|
'hero.seenEp': "Watched {ep}",
|
||||||
'hero.seen': "Watched",
|
'hero.seen': "Watched",
|
||||||
'hero.markSeen': "Mark as watched",
|
'hero.markSeen': "Mark as watched",
|
||||||
|
|||||||
@@ -737,6 +737,8 @@ const dict: Translations = {
|
|||||||
'form.startShort': "Empezado",
|
'form.startShort': "Empezado",
|
||||||
'form.endShort': "Terminado",
|
'form.endShort': "Terminado",
|
||||||
'hero.allSeen': "Todo visto",
|
'hero.allSeen': "Todo visto",
|
||||||
|
'hero.nextOn': 'Próximo episodio el {date}',
|
||||||
|
'hero.upToDate': 'Al día',
|
||||||
'hero.seenEp': "He visto {ep}",
|
'hero.seenEp': "He visto {ep}",
|
||||||
'hero.seen': "Visto",
|
'hero.seen': "Visto",
|
||||||
'hero.markSeen': "Marcar como visto",
|
'hero.markSeen': "Marcar como visto",
|
||||||
|
|||||||
@@ -739,6 +739,8 @@ const dict = {
|
|||||||
'form.startShort': "Commencé le",
|
'form.startShort': "Commencé le",
|
||||||
'form.endShort': "Fini le",
|
'form.endShort': "Fini le",
|
||||||
'hero.allSeen': "Tout vu",
|
'hero.allSeen': "Tout vu",
|
||||||
|
'hero.nextOn': 'Prochain épisode le {date}',
|
||||||
|
'hero.upToDate': 'À jour',
|
||||||
'hero.seenEp': "J'ai vu {ep}",
|
'hero.seenEp': "J'ai vu {ep}",
|
||||||
'hero.seen': "Vu",
|
'hero.seen': "Vu",
|
||||||
'hero.markSeen': "Marquer comme vu",
|
'hero.markSeen': "Marquer comme vu",
|
||||||
|
|||||||
@@ -737,6 +737,8 @@ const dict: Translations = {
|
|||||||
'form.startShort': "Iniziato",
|
'form.startShort': "Iniziato",
|
||||||
'form.endShort': "Finito",
|
'form.endShort': "Finito",
|
||||||
'hero.allSeen': "Tutto visto",
|
'hero.allSeen': "Tutto visto",
|
||||||
|
'hero.nextOn': 'Prossimo episodio il {date}',
|
||||||
|
'hero.upToDate': 'In pari',
|
||||||
'hero.seenEp': "Ho visto {ep}",
|
'hero.seenEp': "Ho visto {ep}",
|
||||||
'hero.seen': "Visto",
|
'hero.seen': "Visto",
|
||||||
'hero.markSeen': "Segna come visto",
|
'hero.markSeen': "Segna come visto",
|
||||||
|
|||||||
@@ -737,6 +737,8 @@ const dict: Translations = {
|
|||||||
'form.startShort': "開始日",
|
'form.startShort': "開始日",
|
||||||
'form.endShort': "完了日",
|
'form.endShort': "完了日",
|
||||||
'hero.allSeen': "すべて視聴済み",
|
'hero.allSeen': "すべて視聴済み",
|
||||||
|
'hero.nextOn': '次のエピソード:{date}',
|
||||||
|
'hero.upToDate': '最新話まで視聴済み',
|
||||||
'hero.seenEp': "{ep}を見た",
|
'hero.seenEp': "{ep}を見た",
|
||||||
'hero.seen': "視聴済み",
|
'hero.seen': "視聴済み",
|
||||||
'hero.markSeen': "視聴済みにする",
|
'hero.markSeen': "視聴済みにする",
|
||||||
|
|||||||
@@ -737,6 +737,8 @@ const dict: Translations = {
|
|||||||
'form.startShort': "시작일",
|
'form.startShort': "시작일",
|
||||||
'form.endShort': "완료일",
|
'form.endShort': "완료일",
|
||||||
'hero.allSeen': "모두 시청함",
|
'hero.allSeen': "모두 시청함",
|
||||||
|
'hero.nextOn': '다음 에피소드: {date}',
|
||||||
|
'hero.upToDate': '최신 화까지 봤어요',
|
||||||
'hero.seenEp': "{ep} 봤어요",
|
'hero.seenEp': "{ep} 봤어요",
|
||||||
'hero.seen': "봤어요",
|
'hero.seen': "봤어요",
|
||||||
'hero.markSeen': "본 것으로 표시",
|
'hero.markSeen': "본 것으로 표시",
|
||||||
|
|||||||
@@ -737,6 +737,8 @@ const dict: Translations = {
|
|||||||
'form.startShort': "Começou",
|
'form.startShort': "Começou",
|
||||||
'form.endShort': "Terminou",
|
'form.endShort': "Terminou",
|
||||||
'hero.allSeen': "Tudo visto",
|
'hero.allSeen': "Tudo visto",
|
||||||
|
'hero.nextOn': 'Próximo episódio em {date}',
|
||||||
|
'hero.upToDate': 'Em dia',
|
||||||
'hero.seenEp': "Vi {ep}",
|
'hero.seenEp': "Vi {ep}",
|
||||||
'hero.seen': "Visto",
|
'hero.seen': "Visto",
|
||||||
'hero.markSeen': "Marcar como visto",
|
'hero.markSeen': "Marcar como visto",
|
||||||
|
|||||||
@@ -737,6 +737,8 @@ const dict: Translations = {
|
|||||||
'form.startShort': "开始于",
|
'form.startShort': "开始于",
|
||||||
'form.endShort': "看完于",
|
'form.endShort': "看完于",
|
||||||
'hero.allSeen': "全部看完",
|
'hero.allSeen': "全部看完",
|
||||||
|
'hero.nextOn': '下一集:{date}',
|
||||||
|
'hero.upToDate': '已追平',
|
||||||
'hero.seenEp': "已看 {ep}",
|
'hero.seenEp': "已看 {ep}",
|
||||||
'hero.seen': "已看",
|
'hero.seen': "已看",
|
||||||
'hero.markSeen': "标记为已看",
|
'hero.markSeen': "标记为已看",
|
||||||
|
|||||||
+60
-5
@@ -1,3 +1,4 @@
|
|||||||
|
import { useEffect, useState } from 'react'
|
||||||
import { tmdbLanguage } from '../i18n'
|
import { tmdbLanguage } from '../i18n'
|
||||||
import type { MediaItem } from '../types'
|
import type { MediaItem } from '../types'
|
||||||
import { CLOUD_TMDB, isPlausibleTmdbKey } from './catalogApi'
|
import { CLOUD_TMDB, isPlausibleTmdbKey } from './catalogApi'
|
||||||
@@ -38,8 +39,24 @@ const SEASONS_SINCE = '2026-10-04T10:00:00.000Z'
|
|||||||
|
|
||||||
const n0 = (v: unknown, max = 100000) => (typeof v === 'number' && Number.isFinite(v) && v >= 0 ? Math.min(max, Math.round(v)) : 0)
|
const n0 = (v: unknown, max = 100000) => (typeof v === 'number' && Number.isFinite(v) && v >= 0 ? Math.min(max, Math.round(v)) : 0)
|
||||||
|
|
||||||
|
// Dernière lecture (le cache est relu par chaque carte : on évite de le réanalyser à chaque fois)
|
||||||
|
let memo: { raw: string | null; cache: AiringCache } | undefined
|
||||||
|
|
||||||
/** Relit le cache en ne gardant que des entrées bien formées. */
|
/** Relit le cache en ne gardant que des entrées bien formées. */
|
||||||
export function loadAiring(): AiringCache {
|
export function loadAiring(): AiringCache {
|
||||||
|
let text: string | null = null
|
||||||
|
try {
|
||||||
|
text = localStorage.getItem(KEY)
|
||||||
|
} catch {
|
||||||
|
/* stockage indisponible */
|
||||||
|
}
|
||||||
|
if (memo && memo.raw === text) return memo.cache
|
||||||
|
const cache = parseAiring()
|
||||||
|
memo = { raw: text, cache }
|
||||||
|
return cache
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseAiring(): AiringCache {
|
||||||
const raw = readStorage(KEY, {})
|
const raw = readStorage(KEY, {})
|
||||||
const out: AiringCache = {}
|
const out: AiringCache = {}
|
||||||
if (!isPlainObject(raw)) return out
|
if (!isPlainObject(raw)) return out
|
||||||
@@ -87,17 +104,55 @@ export function needsCheck(item: MediaItem, cache: AiringCache, force = false):
|
|||||||
return age > (info.ended ? RECHECK_ENDED_MS : RECHECK_MS)
|
return age > (info.ended ? RECHECK_ENDED_MS : RECHECK_MS)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AiringItem = Pick<MediaItem, 'id' | 'type' | 'externalId'>
|
||||||
|
|
||||||
|
const followed = (item: AiringItem) =>
|
||||||
|
TYPE_BY_VALUE[item.type]?.episodic && isSafeExternalId(item.externalId) && (item.externalId.startsWith('tmdb:tv:') || item.externalId.startsWith('anilist:'))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nombre d'épisodes déjà sortis (toutes saisons), ou undefined si on ne sait pas (fiche manuelle, pas encore vérifiée).
|
||||||
|
* Un épisode annoncé dont la date est passée compte comme sorti, même avant la prochaine vérification.
|
||||||
|
*/
|
||||||
|
export function airedCount(item: AiringItem, cache: AiringCache = loadAiring()): number | undefined {
|
||||||
|
const info = cache[item.id]
|
||||||
|
if (!info || !info.aired || !followed(item)) return undefined
|
||||||
|
return info.next && info.next.date <= localDay() ? info.aired + 1 : info.aired
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Date du prochain épisode s'il n'est pas encore sorti. */
|
||||||
|
export function nextAirDate(item: AiringItem, cache: AiringCache = loadAiring()): string | undefined {
|
||||||
|
const d = cache[item.id]?.next?.date
|
||||||
|
return d && d > localDay() ? d : undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Peut-on cocher un épisode de plus ? (non si le suivant n'est pas encore sorti) */
|
||||||
|
export function canWatchMore(item: MediaItem, cache: AiringCache = loadAiring()): boolean {
|
||||||
|
const cap = episodeCap(item)
|
||||||
|
if (cap && item.episodesWatched >= cap) return false
|
||||||
|
const aired = airedCount(item, cache)
|
||||||
|
return aired == null || item.episodesWatched < aired
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* À jour : j'ai vu tous les épisodes sortis et la série continue.
|
* À jour : j'ai vu tous les épisodes sortis et la série continue.
|
||||||
* La fiche quitte « Continuer », puis revient dès que le prochain épisode sort.
|
* La fiche quitte « Continuer », puis revient dès que le prochain épisode sort.
|
||||||
*/
|
*/
|
||||||
export function isCaughtUp(item: MediaItem, cache: AiringCache): boolean {
|
export function isCaughtUp(item: MediaItem, cache: AiringCache): boolean {
|
||||||
const info = cache[item.id]
|
const aired = airedCount(item, cache)
|
||||||
if (!info || !info.aired || !trackable([item]).length) return false
|
if (aired == null || !trackable([item]).length) return false
|
||||||
// Épisode annoncé dont la date est passée : il est sorti, même si on n'a pas encore revérifié
|
|
||||||
const aired = info.next && info.next.date <= localDay() ? info.aired + 1 : info.aired
|
|
||||||
const cap = episodeCap(item)
|
const cap = episodeCap(item)
|
||||||
return item.episodesWatched >= aired && !(cap && item.episodesWatched >= cap && info.ended)
|
return item.episodesWatched >= aired && !(cap && item.episodesWatched >= cap && cache[item.id]?.ended)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Cache des sorties, relu quand il change (pour l'affichage). */
|
||||||
|
export function useAiringCache(): AiringCache {
|
||||||
|
const [cache, setCache] = useState(loadAiring)
|
||||||
|
useEffect(() => {
|
||||||
|
const reload = () => setCache(loadAiring())
|
||||||
|
window.addEventListener(CACHE_EVENT, reload)
|
||||||
|
return () => window.removeEventListener(CACHE_EVENT, reload)
|
||||||
|
}, [])
|
||||||
|
return cache
|
||||||
}
|
}
|
||||||
|
|
||||||
// ───────── TMDB ─────────
|
// ───────── TMDB ─────────
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import { isPlainObject, LIMITS, readStorage } from './lib/security'
|
|||||||
import { mediaDB, requestPersistentStorage } from './lib/db'
|
import { mediaDB, requestPersistentStorage } from './lib/db'
|
||||||
import { todayISO, uid } from './lib/utils'
|
import { todayISO, uid } from './lib/utils'
|
||||||
import { episodeCap, seasonPosition } from './lib/franchise'
|
import { episodeCap, seasonPosition } from './lib/franchise'
|
||||||
|
import { airedCount } from './lib/airing'
|
||||||
|
|
||||||
// Clés propres à l'espace actif (compte connecté, ou appareil sans compte)
|
// Clés propres à l'espace actif (compte connecté, ou appareil sans compte)
|
||||||
const settingsKey = () => scopedKey('settings')
|
const settingsKey = () => scopedKey('settings')
|
||||||
@@ -255,6 +256,9 @@ export function MediaProvider({ children, cloudUser }: { children: ReactNode; cl
|
|||||||
let next = Math.max(0, item.episodesWatched + delta)
|
let next = Math.max(0, item.episodesWatched + delta)
|
||||||
const cap = episodeCap(item)
|
const cap = episodeCap(item)
|
||||||
if (cap) next = Math.min(next, cap)
|
if (cap) next = Math.min(next, cap)
|
||||||
|
// On ne peut pas cocher un épisode qui n'est pas encore sorti
|
||||||
|
const aired = airedCount(item)
|
||||||
|
if (delta > 0 && aired != null) next = Math.min(next, Math.max(aired, item.episodesWatched))
|
||||||
if (next === item.episodesWatched) return
|
if (next === item.episodesWatched) return
|
||||||
const patch: Partial<MediaInput> = { episodesWatched: next }
|
const patch: Partial<MediaInput> = { episodesWatched: next }
|
||||||
// Série en plusieurs saisons : la saison suit les épisodes vus
|
// Série en plusieurs saisons : la saison suit les épisodes vus
|
||||||
|
|||||||
Reference in new issue
Block a user