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>
);
}