diff --git a/react_frontend/src/components/streaming/StreamingSection.tsx b/react_frontend/src/components/streaming/StreamingSection.tsx index f7ffe6a..d0ea9a4 100644 --- a/react_frontend/src/components/streaming/StreamingSection.tsx +++ b/react_frontend/src/components/streaming/StreamingSection.tsx @@ -1,12 +1,12 @@ -import { useCallback, useEffect, useMemo, useState } from 'react'; -import { useStreamingStore } from '@/stores/useStreamingStore'; -import { getEntryWatchProgress } from '@/lib/streaming'; -import { StreamingDialog } from './StreamingDialog'; -import { Button } from '@/components/ui/button'; -import { Play, Tv } from 'lucide-react'; -import { useCreateEntrySeen } from '@/hooks/useEntrySeen'; -import { useCreateEpisodeSeen } from '@/hooks/useEpisodeSeen'; -import type { Entry, Season } from '@/types'; +import { useCallback, useEffect, useMemo, useState } from "react"; +import { useStreamingStore } from "@/stores/useStreamingStore"; +import { getEntryWatchProgress } from "@/lib/streaming"; +import { StreamingDialog } from "./StreamingDialog"; +import { Button } from "@/components/ui/button"; +import { Play, Tv } from "lucide-react"; +import { useCreateEntrySeen } from "@/hooks/useEntrySeen"; +import { useCreateEpisodeSeen } from "@/hooks/useEpisodeSeen"; +import type { Entry, Season } from "@/types"; interface StreamingSectionProps { entry: Entry; @@ -47,7 +47,8 @@ export function StreamingSection({ entry, seasons }: StreamingSectionProps) { if (entry.episodeSeens && entry.episodeSeens.length > 0 && seasons) { const sorted = [...entry.episodeSeens].sort( - (a, b) => new Date(b.date_seen).getTime() - new Date(a.date_seen).getTime() + (a, b) => + new Date(b.date_seen).getTime() - new Date(a.date_seen).getTime(), ); const last = sorted[0]; for (const season of seasons) { @@ -55,36 +56,56 @@ export function StreamingSection({ entry, seasons }: StreamingSectionProps) { if (ep) { const nextEp = ep.episode_number + 1; if (season.episodes?.some((e) => e.episode_number === nextEp)) { - return { season: season.season_number, episode: nextEp, label: `Continue S${season.season_number}:E${nextEp}` }; + return { + season: season.season_number, + episode: nextEp, + label: `Continue S${season.season_number}:E${nextEp}`, + }; } - const nextSeason = seasons.find((s) => s.season_number === season.season_number + 1); + const nextSeason = seasons.find( + (s) => s.season_number === season.season_number + 1, + ); if (nextSeason?.episodes?.length) { - return { season: nextSeason.season_number, episode: 1, label: `Continue S${nextSeason.season_number}:E1` }; + return { + season: nextSeason.season_number, + episode: 1, + label: `Continue S${nextSeason.season_number}:E1`, + }; } - return { season: season.season_number, episode: ep.episode_number, label: `Rewatch S${season.season_number}:E${ep.episode_number}` }; + return { + season: season.season_number, + episode: ep.episode_number, + label: `Rewatch S${season.season_number}:E${ep.episode_number}`, + }; } } } - return { season: 1, episode: 1, label: 'Start Watching' }; + return { season: 1, episode: 1, label: "Start Watching" }; }, [entry, seasons, watchProgress]); - const initialSeason = entry.is_tvseries ? (continueWatchingInfo?.season ?? 1) : 1; - const initialEpisode = entry.is_tvseries ? (continueWatchingInfo?.episode ?? 1) : 1; + const initialSeason = entry.is_tvseries + ? (continueWatchingInfo?.season ?? 1) + : 1; + const initialEpisode = entry.is_tvseries + ? (continueWatchingInfo?.episode ?? 1) + : 1; const handleOpen = useCallback(() => { if (!entry.entryIds?.tmdb_id) return; const request = entry.is_tvseries ? { - type: 'tv' as const, + type: "tv" as const, tmdbId: entry.entryIds.tmdb_id, imdbId: entry.entryIds?.imdb_id || undefined, season: initialSeason, episode: initialEpisode, - startAt: watchProgress?.showProgress?.[`s${initialSeason}e${initialEpisode}`]?.watched, + startAt: + watchProgress?.showProgress?.[`s${initialSeason}e${initialEpisode}`] + ?.watched, } : { - type: 'movie' as const, + type: "movie" as const, tmdbId: entry.entryIds.tmdb_id, imdbId: entry.entryIds?.imdb_id || undefined, startAt: watchProgress?.watched, @@ -102,41 +123,43 @@ export function StreamingSection({ entry, seasons }: StreamingSectionProps) { (season?: number, episode?: number) => { if (entry.is_tvseries && season && episode && seasons) { const seasonData = seasons.find((s) => s.season_number === season); - const episodeData = seasonData?.episodes?.find((e) => e.episode_number === episode); + const episodeData = seasonData?.episodes?.find( + (e) => e.episode_number === episode, + ); if (episodeData) { createEpisodeSeen.mutate({ entry_id: entry.id, episode_id: episodeData.id, - date_seen: new Date().toISOString().split('T')[0], - accuracy: 'EXACT', + date_seen: new Date().toISOString().split("T")[0], + accuracy: "EXACT", season_id: seasonData!.id, }); } } else { createEntrySeen.mutate({ entry_id: entry.id, - date_seen: new Date().toISOString().split('T')[0], - accuracy: 'EXACT', + date_seen: new Date().toISOString().split("T")[0], + accuracy: "EXACT", }); } }, - [entry, seasons, createEntrySeen, createEpisodeSeen] + [entry, seasons, createEntrySeen, createEpisodeSeen], ); if (!entry.entryIds?.tmdb_id) return null; const buttonLabel = entry.is_tvseries - ? (continueWatchingInfo?.label ?? 'Start Watching') + ? (continueWatchingInfo?.label ?? "Start Watching") : watchProgress && watchProgress.watched > 60 - ? 'Continue Watching' - : 'Watch Now'; + ? "Continue Watching" + : "Watch Now"; return ( <>