feat(streaming): add watch button to episode cards and episode details page

- Add play overlay on episode thumbnails in SeasonPage (click to stream directly)
- Add clickable watch overlay on episode still image in EpisodePage
- Fix StreamingDialog rendering via React portal (document.body) to prevent ancestor overflow/max-width clipping
- Fix EpisodePage JSX parse error (streaming dialog was outside root element)
- Fix watch buttons not working: use useEntry hook for full entry data with entryIds instead of library store (which lacks entryIds)
- Fix preventDefault called after guard check, causing link navigation when tmdb_id was missing
- Pass seasons via useEntrySeasons to StreamingDialog from both pages so episodes sidebar renders correctly
- Apply final UI polish: entry title in dialog top bar, season selector label, episode format "E1 Title", watched badge always-on, unreleased episodes greyed out
This commit is contained in:
Mohammed Abad committed 2026-05-25 04:25:45 +01:00
1 parent afc032ca1c
commit 022c9a271b
7 files changed
+708 -518

No files matched your search

+48 -6
View File
@@ -3,18 +3,22 @@ import { useParams, useNavigate, Link } from 'react-router-dom';
import { useQuery } from '@tanstack/react-query';
import { seasonsApi } from '@/api/seasons';
import { useSeason } from '@/hooks/useSeasons';
import { useEntry, useEntrySeasons } from '@/hooks/useEntries';
import { useLibraryStore } from '@/stores/useLibraryStore';
import {
useEpisodeSeenByEpisode,
useDeleteEpisodeSeen,
} from '@/hooks/useEpisodeSeen';import { Skeleton } from '@/components/ui/skeleton';
} from '@/hooks/useEpisodeSeen';
import { StreamingDialog } from '@/components/streaming/StreamingDialog';
import { useStreamingStore } from '@/stores/useStreamingStore';
import { Skeleton } from '@/components/ui/skeleton';
import { Button } from '@/components/ui/button';
import { Separator } from '@/components/ui/separator';
import { EpisodeWatchHistory } from '@/components/entries/EpisodeWatchHistory';
import { EpisodeSeenEditDialog } from '@/components/dialogs/EpisodeSeenEditDialog';
import { ConfirmDialog } from '@/components/dialogs/ConfirmDialog';
import { CastList } from '@/components/entries/CastList';
import { Eye, ChevronLeft, ChevronRight, Clock } from 'lucide-react';
import { Eye, ChevronLeft, ChevronRight, Clock, PlayCircle } from 'lucide-react';
import { getTmdbPosterUrl, formatDate, formatRuntime } from '@/lib/media-utils';
import type { Episode, EpisodeSeen } from '@/types';
@@ -32,9 +36,14 @@ export function EpisodePage() {
});
const { data: season } = useSeason(parseInt(seasonId!, 10));
const entryTitle = useLibraryStore((s) => s.entries.get(parseInt(entryId!, 10))?.title);
const { data: entry } = useEntry(parseInt(entryId!, 10));
const { data: entrySeasons } = useEntrySeasons(parseInt(entryId!, 10));
const entryTitle = entry?.title ?? useLibraryStore.getState().entries.get(parseInt(entryId!, 10))?.title;
const seasonNumber = season?.season_number;
const { initialize, play } = useStreamingStore();
const [streamingOpen, setStreamingOpen] = useState(false);
const epId = parseInt(episodeId!, 10);
const entryIdNum = parseInt(entryId!, 10);
const episode: Episode | undefined = episodes.find((ep: Episode) => ep.id === epId);
@@ -95,14 +104,34 @@ export function EpisodePage() {
</Button>
</div>
{/* High-quality thumbnail */}
{/* High-quality thumbnail — click to watch */}
{episode.still_path && (
<div className="overflow-hidden rounded-xl">
<div
className="relative overflow-hidden rounded-xl cursor-pointer group"
onClick={() => {
if (!entry?.entryIds?.tmdb_id || !seasonNumber) return;
initialize();
play({
type: 'tv',
tmdbId: entry.entryIds.tmdb_id,
imdbId: entry.entryIds?.imdb_id || undefined,
season: seasonNumber,
episode: episode.episode_number,
});
setStreamingOpen(true);
}}
>
<img
src={getTmdbPosterUrl(episode.still_path, 'w1280')}
alt={episode.name}
className="w-full max-h-96 object-cover"
className="w-full max-h-96 object-cover transition-[filter] group-hover:brightness-50"
/>
<div className="absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity">
<div className="flex items-center gap-2 bg-black/60 backdrop-blur-sm rounded-full px-5 py-2.5">
<PlayCircle className="h-6 w-6 text-white" />
<span className="text-white font-medium text-sm">Watch Episode</span>
</div>
</div>
</div>
)}
@@ -228,6 +257,19 @@ export function EpisodePage() {
}
}}
/>
{/* Streaming dialog */}
{entry && streamingOpen && (
<StreamingDialog
isOpen={streamingOpen}
onClose={() => {
setStreamingOpen(false);
useStreamingStore.getState().closePlayer();
}}
entry={entry}
seasons={entrySeasons}
/>
)}
</div>
);
}
+50 -7
View File
@@ -1,14 +1,16 @@
import { useState } from 'react';
import { useParams, Link } from 'react-router-dom';
import { useSeason, useSeasonEpisodes } from '@/hooks/useSeasons';
import { useEntry, useEntrySeasons } from '@/hooks/useEntries';
import { useLibraryStore } from '@/stores/useLibraryStore';
import { EpisodeSeenEditDialog } from '@/components/dialogs/EpisodeSeenEditDialog';
import { MarkSeasonWatchedDialog } from '@/components/dialogs/MarkSeasonWatchedDialog';
import { StreamingDialog } from '@/components/streaming/StreamingDialog';
import { useStreamingStore } from '@/stores/useStreamingStore';
import { Skeleton } from '@/components/ui/skeleton';
import { Progress } from '@/components/ui/progress';
import { Button } from '@/components/ui/button';
import { Eye, CheckCircle2, ListChecks } from 'lucide-react';
import { Eye, CheckCircle2, ListChecks, PlayCircle } from 'lucide-react';
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
import { getTmdbPosterUrl, getYear, formatDate } from '@/lib/media-utils';
import type { Episode, EpisodeSeen } from '@/types';
@@ -20,9 +22,26 @@ export function SeasonPage() {
}>();
const { data: season, isLoading } = useSeason(parseInt(seasonId!, 10));
const { data: episodes = [] } = useSeasonEpisodes(parseInt(seasonId!, 10));
const entryTitle = useLibraryStore((s) => s.entries.get(parseInt(entryId!, 10))?.title);
const { data: entry } = useEntry(parseInt(entryId!, 10));
const { data: entrySeasons } = useEntrySeasons(parseInt(entryId!, 10));
const entryTitle = entry?.title ?? useLibraryStore.getState().entries.get(parseInt(entryId!, 10))?.title;
const { initialize, play } = useStreamingStore();
const [dialogEpisode, setDialogEpisode] = useState<Episode | null>(null);
const [showMarkAllDialog, setShowMarkAllDialog] = useState(false);
const [streamingOpen, setStreamingOpen] = useState(false);
const handleWatchEpisode = (season: number, episodeNumber: number) => {
if (!entry?.entryIds?.tmdb_id) return;
initialize();
play({
type: 'tv',
tmdbId: entry.entryIds.tmdb_id,
imdbId: entry.entryIds?.imdb_id || undefined,
season,
episode: episodeNumber,
});
setStreamingOpen(true);
};
if (isLoading || !season) {
return (
@@ -126,20 +145,31 @@ export function SeasonPage() {
to={`/entry/${entryId}/season/${seasonId}/episode/${episode.id}`}
className="flex gap-3 rounded-lg border border-border p-2 transition-colors hover:bg-accent/50 sm:gap-4 sm:p-3"
>
{/* Thumbnail */}
<div className="h-14 w-24 shrink-0 overflow-hidden rounded bg-muted sm:h-16 sm:w-28">
{/* Thumbnail — click to watch */}
<div
className="relative h-14 w-24 shrink-0 overflow-hidden rounded bg-muted sm:h-16 sm:w-28 group/thumb cursor-pointer"
onClick={(ev) => {
ev.preventDefault();
ev.stopPropagation();
if (!entry?.entryIds?.tmdb_id) return;
handleWatchEpisode(season.season_number, episode.episode_number);
}}
>
{episode.still_path ? (
<img
src={getTmdbPosterUrl(episode.still_path, 'w300')}
alt={episode.name}
className="h-full w-full object-cover"
className="h-full w-full object-cover transition-[filter] group-hover/thumb:brightness-50"
loading="lazy"
/>
) : (
<div className="flex h-full w-full items-center justify-center text-xs text-muted-foreground">
<div className="flex h-full w-full items-center justify-center text-xs text-muted-foreground bg-muted group-hover/thumb:bg-muted/70 transition-colors">
No Image
</div>
)}
<div className="absolute inset-0 flex items-center justify-center opacity-0 group-hover/thumb:opacity-100 transition-opacity">
<PlayCircle className="h-7 w-7 text-white drop-shadow-lg" />
</div>
</div>
{/* Info */}
@@ -235,6 +265,19 @@ export function SeasonPage() {
seasonId={parseInt(seasonId!, 10)}
episodes={episodes}
/>
{/* Streaming dialog */}
{entry && streamingOpen && (
<StreamingDialog
isOpen={streamingOpen}
onClose={() => {
setStreamingOpen(false);
useStreamingStore.getState().closePlayer();
}}
entry={entry}
seasons={entrySeasons}
/>
)}
</div>
);
}