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 { 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 (
<>
<Button
onClick={handleOpen}
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 ? (
<Tv className="h-4 w-4" />
+15 -2
View File
@@ -34,6 +34,7 @@ import {
History,
Trash2,
ExternalLink,
Play,
} from "lucide-react";
import {
Tooltip,
@@ -339,7 +340,7 @@ export function EntryDetailsPage() {
<>
<span>•</span>
<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)}
>
<Eye className="h-3 w-3" />
@@ -443,8 +444,19 @@ export function EntryDetailsPage() {
{/* Sections */}
<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} />
<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 && (
<>
@@ -453,6 +465,7 @@ export function EntryDetailsPage() {
credits={credits}
entryId={e.id}
isTvSeries={e.is_tvseries}
maxItems={12}
/>
</>
)}