Add Watch Trailer button next to Start Watching, fix cursors

This commit is contained in:
X4Lo committed 2026-06-18 22:58:38 +01:00
1 parent 3c089ee110
commit 73bff72cec
2 files changed
+68 -32

No files matched your search

@@ -1,12 +1,12 @@
import { useCallback, useEffect, useMemo, useState } from 'react'; import { useCallback, useEffect, useMemo, useState } from "react";
import { useStreamingStore } from '@/stores/useStreamingStore'; import { useStreamingStore } from "@/stores/useStreamingStore";
import { getEntryWatchProgress } from '@/lib/streaming'; import { getEntryWatchProgress } from "@/lib/streaming";
import { StreamingDialog } from './StreamingDialog'; import { StreamingDialog } from "./StreamingDialog";
import { Button } from '@/components/ui/button'; import { Button } from "@/components/ui/button";
import { Play, Tv } from 'lucide-react'; import { Play, Tv } from "lucide-react";
import { useCreateEntrySeen } from '@/hooks/useEntrySeen'; import { useCreateEntrySeen } from "@/hooks/useEntrySeen";
import { useCreateEpisodeSeen } from '@/hooks/useEpisodeSeen'; import { useCreateEpisodeSeen } from "@/hooks/useEpisodeSeen";
import type { Entry, Season } from '@/types'; import type { Entry, Season } from "@/types";
interface StreamingSectionProps { interface StreamingSectionProps {
entry: Entry; entry: Entry;
@@ -47,7 +47,8 @@ export function StreamingSection({ entry, seasons }: StreamingSectionProps) {
if (entry.episodeSeens && entry.episodeSeens.length > 0 && seasons) { if (entry.episodeSeens && entry.episodeSeens.length > 0 && seasons) {
const sorted = [...entry.episodeSeens].sort( 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]; const last = sorted[0];
for (const season of seasons) { for (const season of seasons) {
@@ -55,36 +56,56 @@ export function StreamingSection({ entry, seasons }: StreamingSectionProps) {
if (ep) { if (ep) {
const nextEp = ep.episode_number + 1; const nextEp = ep.episode_number + 1;
if (season.episodes?.some((e) => e.episode_number === nextEp)) { 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) { 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]); }, [entry, seasons, watchProgress]);
const initialSeason = entry.is_tvseries ? (continueWatchingInfo?.season ?? 1) : 1; const initialSeason = entry.is_tvseries
const initialEpisode = entry.is_tvseries ? (continueWatchingInfo?.episode ?? 1) : 1; ? (continueWatchingInfo?.season ?? 1)
: 1;
const initialEpisode = entry.is_tvseries
? (continueWatchingInfo?.episode ?? 1)
: 1;
const handleOpen = useCallback(() => { const handleOpen = useCallback(() => {
if (!entry.entryIds?.tmdb_id) return; if (!entry.entryIds?.tmdb_id) return;
const request = entry.is_tvseries const request = entry.is_tvseries
? { ? {
type: 'tv' as const, type: "tv" as const,
tmdbId: entry.entryIds.tmdb_id, tmdbId: entry.entryIds.tmdb_id,
imdbId: entry.entryIds?.imdb_id || undefined, imdbId: entry.entryIds?.imdb_id || undefined,
season: initialSeason, season: initialSeason,
episode: initialEpisode, 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, tmdbId: entry.entryIds.tmdb_id,
imdbId: entry.entryIds?.imdb_id || undefined, imdbId: entry.entryIds?.imdb_id || undefined,
startAt: watchProgress?.watched, startAt: watchProgress?.watched,
@@ -102,41 +123,43 @@ export function StreamingSection({ entry, seasons }: StreamingSectionProps) {
(season?: number, episode?: number) => { (season?: number, episode?: number) => {
if (entry.is_tvseries && season && episode && seasons) { if (entry.is_tvseries && season && episode && seasons) {
const seasonData = seasons.find((s) => s.season_number === season); 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) { if (episodeData) {
createEpisodeSeen.mutate({ createEpisodeSeen.mutate({
entry_id: entry.id, entry_id: entry.id,
episode_id: episodeData.id, episode_id: episodeData.id,
date_seen: new Date().toISOString().split('T')[0], date_seen: new Date().toISOString().split("T")[0],
accuracy: 'EXACT', accuracy: "EXACT",
season_id: seasonData!.id, season_id: seasonData!.id,
}); });
} }
} else { } else {
createEntrySeen.mutate({ createEntrySeen.mutate({
entry_id: entry.id, entry_id: entry.id,
date_seen: new Date().toISOString().split('T')[0], date_seen: new Date().toISOString().split("T")[0],
accuracy: 'EXACT', accuracy: "EXACT",
}); });
} }
}, },
[entry, seasons, createEntrySeen, createEpisodeSeen] [entry, seasons, createEntrySeen, createEpisodeSeen],
); );
if (!entry.entryIds?.tmdb_id) return null; if (!entry.entryIds?.tmdb_id) return null;
const buttonLabel = entry.is_tvseries const buttonLabel = entry.is_tvseries
? (continueWatchingInfo?.label ?? 'Start Watching') ? (continueWatchingInfo?.label ?? "Start Watching")
: watchProgress && watchProgress.watched > 60 : watchProgress && watchProgress.watched > 60
? 'Continue Watching' ? "Continue Watching"
: 'Watch Now'; : "Watch Now";
return ( return (
<> <>
<Button <Button
onClick={handleOpen} onClick={handleOpen}
size="lg" size="lg"
className="w-full sm:w-auto gap-2 h-11 px-6 text-sm font-medium" className="w-full sm:w-auto gap-2 h-11 px-6 text-sm font-medium cursor-pointer"
> >
{entry.is_tvseries ? ( {entry.is_tvseries ? (
<Tv className="h-4 w-4" /> <Tv className="h-4 w-4" />
+15 -2
View File
@@ -34,6 +34,7 @@ import {
History, History,
Trash2, Trash2,
ExternalLink, ExternalLink,
Play,
} from "lucide-react"; } from "lucide-react";
import { import {
Tooltip, Tooltip,
@@ -339,7 +340,7 @@ export function EntryDetailsPage() {
<> <>
<span>•</span> <span>•</span>
<button <button
className="inline-flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors underline decoration-dotted" className="inline-flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors underline decoration-dotted cursor-pointer"
onClick={() => setShowSeenDialog(true)} onClick={() => setShowSeenDialog(true)}
> >
<Eye className="h-3 w-3" /> <Eye className="h-3 w-3" />
@@ -443,8 +444,19 @@ export function EntryDetailsPage() {
{/* Sections */} {/* Sections */}
<div className="mt-10 space-y-8"> <div className="mt-10 space-y-8">
{/* Streaming player */} {/* Streaming player + Trailer */}
<div className="flex flex-wrap items-center justify-center gap-2">
<StreamingSection entry={e} seasons={seasons} /> <StreamingSection entry={e} seasons={seasons} />
<a
href={`https://www.youtube.com/results?search_query=${encodeURIComponent(e.title + " official trailer")}`}
target="_blank"
rel="noopener noreferrer"
className="inline-flex items-center gap-2 h-11 px-6 text-sm font-medium rounded-md border border-input bg-background hover:bg-accent hover:text-accent-foreground transition-colors"
>
<Play className="h-4 w-4" />
Watch Trailer
</a>
</div>
{credits.length > 0 && ( {credits.length > 0 && (
<> <>
@@ -453,6 +465,7 @@ export function EntryDetailsPage() {
credits={credits} credits={credits}
entryId={e.id} entryId={e.id}
isTvSeries={e.is_tvseries} isTvSeries={e.is_tvseries}
maxItems={12}
/> />
</> </>
)} )}