Fix home page navigation and add TMDB cast page
Home page cards now check library store and link directly to EntryDetailsPage when the entry is already added. Created useTmdbEntryLink hook for shared library-check logic. Added TmdbCastsPage with filter/search/sort for TMDB preview cast & crew, and limited credits to 12 on TmdbPreviewPage.
This commit is contained in:
1 parent
6c2fd3837b
commit
8671184dc5
9 files changed
+540
-136
No files matched your search
@@ -1,26 +1,30 @@
|
||||
import { useParams, useNavigate } from 'react-router-dom';
|
||||
import { useEffect } from 'react';
|
||||
import { useTmdbPreview, useCreateEntry } from '@/hooks/useEntries';
|
||||
import { useLibraryStore } from '@/stores/useLibraryStore';
|
||||
import { useCommandPaletteStore } from '@/stores/useCommandPaletteStore';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { Star, Plus, Loader2, ExternalLink } from 'lucide-react';
|
||||
import { EntryDetailsSkeleton } from '@/components/skeletons/PageSkeletons';
|
||||
import { useParams, useNavigate } from "react-router-dom";
|
||||
import { useEffect } from "react";
|
||||
import { useTmdbPreview, useCreateEntry } from "@/hooks/useEntries";
|
||||
import { useLibraryStore } from "@/stores/useLibraryStore";
|
||||
import { useCommandPaletteStore } from "@/stores/useCommandPaletteStore";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { Star, Plus, Loader2, ExternalLink } from "lucide-react";
|
||||
import { EntryDetailsSkeleton } from "@/components/skeletons/PageSkeletons";
|
||||
import { CastList } from "@/components/entries/CastList";
|
||||
import { getYear, formatRuntime } from '@/lib/media-utils';
|
||||
import type { Credit } from '@/types';
|
||||
import { getYear, formatRuntime } from "@/lib/media-utils";
|
||||
import type { Credit } from "@/types";
|
||||
|
||||
const TMDB_IMG = 'https://image.tmdb.org/t/p';
|
||||
const TMDB_IMG = "https://image.tmdb.org/t/p";
|
||||
|
||||
export function TmdbPreviewPage() {
|
||||
const { type, tmdbId } = useParams<{ type: string; tmdbId: string }>();
|
||||
const navigate = useNavigate();
|
||||
const tmdbIdNum = parseInt(tmdbId!, 10);
|
||||
const mediaType = type as 'movie' | 'tv';
|
||||
const mediaType = type as "movie" | "tv";
|
||||
|
||||
const { data: preview, isLoading, isError } = useTmdbPreview(tmdbIdNum, mediaType);
|
||||
const {
|
||||
data: preview,
|
||||
isLoading,
|
||||
isError,
|
||||
} = useTmdbPreview(tmdbIdNum, mediaType);
|
||||
const createEntry = useCreateEntry();
|
||||
|
||||
// Check if already in library
|
||||
@@ -61,20 +65,27 @@ export function TmdbPreviewPage() {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center gap-4 py-20">
|
||||
<p className="text-muted-foreground">Could not load entry from TMDB.</p>
|
||||
<Button variant="outline" onClick={() => navigate(-1)}>Go back</Button>
|
||||
<Button variant="outline" onClick={() => navigate(-1)}>
|
||||
Go back
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const backdrop = preview.backdrop_path ? `${TMDB_IMG}/w1280${preview.backdrop_path}` : null;
|
||||
const backdrop = preview.backdrop_path
|
||||
? `${TMDB_IMG}/w1280${preview.backdrop_path}`
|
||||
: null;
|
||||
const poster = preview.poster_path
|
||||
? `${TMDB_IMG}/w500${preview.poster_path}`
|
||||
: '/images/default-poster.png';
|
||||
: "/images/default-poster.png";
|
||||
|
||||
const handleAddToLibrary = () => {
|
||||
createEntry.mutate(
|
||||
{ tmdb_id: preview.tmdb_id, is_tvserie: preview.is_tvseries },
|
||||
{ onSuccess: (newEntry) => navigate(`/entry/${newEntry.id}`, { replace: true }) }
|
||||
{
|
||||
onSuccess: (newEntry) =>
|
||||
navigate(`/entry/${newEntry.id}`, { replace: true }),
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
@@ -99,17 +110,23 @@ export function TmdbPreviewPage() {
|
||||
{/* Add to Library button — top right */}
|
||||
<div className="flex justify-end gap-2 -mt-10 relative z-10 mb-2">
|
||||
{libraryEntry ? (
|
||||
<Button variant="outline" onClick={() => navigate(`/entry/${libraryEntry.id}`)}>
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => navigate(`/entry/${libraryEntry.id}`)}
|
||||
>
|
||||
Already in Library — View
|
||||
</Button>
|
||||
) : (
|
||||
<Button onClick={handleAddToLibrary} disabled={createEntry.isPending}>
|
||||
<Button
|
||||
onClick={handleAddToLibrary}
|
||||
disabled={createEntry.isPending}
|
||||
>
|
||||
{createEntry.isPending ? (
|
||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||
) : (
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
)}
|
||||
{createEntry.isPending ? 'Adding...' : 'Add to Library'}
|
||||
{createEntry.isPending ? "Adding..." : "Add to Library"}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
@@ -127,7 +144,7 @@ export function TmdbPreviewPage() {
|
||||
<div className="flex items-center justify-center gap-3 mt-3">
|
||||
{preview.tmdb_id && (
|
||||
<a
|
||||
href={`https://www.themoviedb.org/${preview.is_tvseries ? 'tv' : 'movie'}/${preview.tmdb_id}`}
|
||||
href={`https://www.themoviedb.org/${preview.is_tvseries ? "tv" : "movie"}/${preview.tmdb_id}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors"
|
||||
@@ -154,12 +171,16 @@ export function TmdbPreviewPage() {
|
||||
<div className="flex-1 min-w-0 space-y-4">
|
||||
{/* Title */}
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold leading-tight">{preview.title}</h1>
|
||||
<h1 className="text-3xl font-bold leading-tight">
|
||||
{preview.title}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
{/* Meta */}
|
||||
<div className="flex flex-wrap items-center gap-2 text-sm text-muted-foreground">
|
||||
{preview.release_date && <span>{getYear(preview.release_date)}</span>}
|
||||
{preview.release_date && (
|
||||
<span>{getYear(preview.release_date)}</span>
|
||||
)}
|
||||
{preview.is_tvseries && preview.status && (
|
||||
<>
|
||||
<span>•</span>
|
||||
@@ -178,7 +199,8 @@ export function TmdbPreviewPage() {
|
||||
{preview.is_tvseries && preview.number_of_seasons != null && (
|
||||
<div className="flex items-center gap-2 text-sm">
|
||||
<Badge variant="secondary">
|
||||
{preview.number_of_seasons} {preview.number_of_seasons === 1 ? 'Season' : 'Seasons'}
|
||||
{preview.number_of_seasons}{" "}
|
||||
{preview.number_of_seasons === 1 ? "Season" : "Seasons"}
|
||||
</Badge>
|
||||
{preview.number_of_episodes != null && (
|
||||
<span className="text-muted-foreground">
|
||||
@@ -225,7 +247,11 @@ export function TmdbPreviewPage() {
|
||||
{preview.credits && preview.credits.length > 0 && (
|
||||
<>
|
||||
<Separator />
|
||||
<CastList credits={preview.credits as unknown as Credit[]} />
|
||||
<CastList
|
||||
credits={preview.credits as unknown as Credit[]}
|
||||
maxItems={12}
|
||||
allCastHref={`/entry/tmdb/${mediaType}/${tmdbIdNum}/cast`}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user