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:
X4Lo committed 2026-06-18 13:37:39 +01:00
1 parent 6c2fd3837b
commit 8671184dc5
9 files changed
+540 -136

No files matched your search

@@ -1,28 +1,45 @@
import { Link } from 'react-router-dom';
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
import { ScrollArea, ScrollBar } from '@/components/ui/scroll-area';
import { getProfileUrl } from '@/lib/media-utils';
import { ChevronRight } from 'lucide-react';
import type { Credit } from '@/types';
import { Link } from "react-router-dom";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
import { getProfileUrl } from "@/lib/media-utils";
import { ChevronRight } from "lucide-react";
import type { Credit } from "@/types";
interface CastListProps {
credits: Credit[];
entryId?: number;
isTvSeries?: boolean;
/** Limit visible cast cards (default: show all) */
maxItems?: number;
/** Override link for "All Cast & Crew" — if unset, uses /entry/:entryId/cast */
allCastHref?: string;
}
export function CastList({ credits, entryId, isTvSeries }: CastListProps) {
const castCredits = credits.filter((c) => c.cast_type === 'cast');
export function CastList({
credits,
entryId,
isTvSeries,
maxItems,
allCastHref,
}: CastListProps) {
let castCredits = credits.filter((c) => c.cast_type === "cast");
const hasMore = maxItems != null && castCredits.length > maxItems;
if (hasMore) {
castCredits = castCredits.slice(0, maxItems);
}
if (castCredits.length === 0) return null;
const allCastLink =
allCastHref || (entryId != null ? `/entry/${entryId}/cast` : null);
return (
<div className="space-y-3">
<div className="flex items-center justify-between">
<h3 className="text-lg font-semibold">Cast</h3>
{entryId != null && (
{allCastLink && (
<Link
to={`/entry/${entryId}/cast`}
to={allCastLink}
className="inline-flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors"
>
All Cast &amp; Crew
@@ -42,7 +59,13 @@ export function CastList({ credits, entryId, isTvSeries }: CastListProps) {
);
}
function CastCard({ credit, isTvSeries }: { credit: Credit; isTvSeries?: boolean }) {
function CastCard({
credit,
isTvSeries,
}: {
credit: Credit;
isTvSeries?: boolean;
}) {
const profileUrl = credit.people?.profile_path
? getProfileUrl(credit.people.profile_path)
: undefined;
@@ -61,9 +84,9 @@ function CastCard({ credit, isTvSeries }: { credit: Credit; isTvSeries?: boolean
<AvatarImage src={profileUrl} alt={credit.people?.name} />
<AvatarFallback className="text-xs">
{credit.people?.name
?.split(' ')
?.split(" ")
.map((n) => n[0])
.join('')}
.join("")}
</AvatarFallback>
</Avatar>
<div>
@@ -73,11 +96,13 @@ function CastCard({ credit, isTvSeries }: { credit: Credit; isTvSeries?: boolean
<p className="text-[10px] text-muted-foreground leading-tight line-clamp-1">
{credit.character}
</p>
{isTvSeries && credit.episode_count != null && credit.episode_count > 0 && (
<p className="text-[10px] text-muted-foreground/70 leading-tight">
{credit.episode_count} ep.
</p>
)}
{isTvSeries &&
credit.episode_count != null &&
credit.episode_count > 0 && (
<p className="text-[10px] text-muted-foreground/70 leading-tight">
{credit.episode_count} ep.
</p>
)}
</div>
</Link>
);
@@ -1,6 +1,7 @@
import { Link } from 'react-router-dom';
import { Star } from 'lucide-react';
import type { TmdbEntry } from '@/types';
import { Link } from "react-router-dom";
import { Star } from "lucide-react";
import type { TmdbEntry } from "@/types";
import { useTmdbEntryLink } from "@/hooks/useTmdbEntryLink";
interface BackdropCardProps {
entry: TmdbEntry;
@@ -9,19 +10,26 @@ interface BackdropCardProps {
animDelay?: number;
}
export function BackdropCard({ entry, showRating, animClass, animDelay }: BackdropCardProps) {
const title = entry.title || entry.name || 'Untitled';
export function BackdropCard({
entry,
showRating,
animClass,
animDelay,
}: BackdropCardProps) {
const title = entry.title || entry.name || "Untitled";
const backdrop = entry.backdrop_path
? `https://image.tmdb.org/t/p/w780${entry.backdrop_path}`
: null;
const isTv = entry.media_type === 'tv' || !!entry.name;
const linkTo = `/entry/tmdb/${isTv ? 'tv' : 'movie'}/${entry.id}`;
const { linkTo } = useTmdbEntryLink(entry);
return (
<Link
to={linkTo}
className={`group relative block overflow-hidden rounded-xl bg-muted ${animClass ?? 'animate-page-enter'}`}
style={{ aspectRatio: '16/9', animationDelay: animDelay ? `${animDelay}ms` : undefined }}
className={`group relative block overflow-hidden rounded-xl bg-muted ${animClass ?? "animate-page-enter"}`}
style={{
aspectRatio: "16/9",
animationDelay: animDelay ? `${animDelay}ms` : undefined,
}}
>
{backdrop ? (
<img
@@ -51,18 +59,17 @@ interface BackdropScrollCardProps {
}
export function BackdropScrollCard({ entry }: BackdropScrollCardProps) {
const title = entry.title || entry.name || 'Untitled';
const title = entry.title || entry.name || "Untitled";
const backdrop = entry.backdrop_path
? `https://image.tmdb.org/t/p/w780${entry.backdrop_path}`
: null;
const isTv = entry.media_type === 'tv' || !!entry.name;
const linkTo = `/entry/tmdb/${isTv ? 'tv' : 'movie'}/${entry.id}`;
const { linkTo } = useTmdbEntryLink(entry);
return (
<Link
to={linkTo}
className="group relative block shrink-0 overflow-hidden rounded-xl bg-muted"
style={{ width: '260px', aspectRatio: '16/9' }}
style={{ width: "260px", aspectRatio: "16/9" }}
>
{backdrop ? (
<img
@@ -1,5 +1,6 @@
import { Link } from 'react-router-dom';
import type { TmdbEntry } from '@/types';
import { Link } from "react-router-dom";
import type { TmdbEntry } from "@/types";
import { useTmdbEntryLink } from "@/hooks/useTmdbEntryLink";
interface MiniPosterCardProps {
entry: TmdbEntry;
@@ -7,16 +8,18 @@ interface MiniPosterCardProps {
}
export function MiniPosterCard({ entry, hideTitle }: MiniPosterCardProps) {
const title = entry.title || entry.name || 'Untitled';
const title = entry.title || entry.name || "Untitled";
const poster = entry.poster_path
? `https://image.tmdb.org/t/p/w342${entry.poster_path}`
: null;
const isTv = entry.media_type === 'tv' || !!entry.name;
const linkTo = `/entry/tmdb/${isTv ? 'tv' : 'movie'}/${entry.id}`;
const { linkTo } = useTmdbEntryLink(entry);
return (
<Link to={linkTo} className="group space-y-2">
<div className="relative overflow-hidden rounded-lg bg-muted" style={{ aspectRatio: '2/3' }}>
<div
className="relative overflow-hidden rounded-lg bg-muted"
style={{ aspectRatio: "2/3" }}
>
{poster ? (
<img
src={poster}
@@ -1,6 +1,7 @@
import { Link } from 'react-router-dom';
import { Star } from 'lucide-react';
import type { TmdbEntry } from '@/types';
import { Link } from "react-router-dom";
import { Star } from "lucide-react";
import type { TmdbEntry } from "@/types";
import { useTmdbEntryLink } from "@/hooks/useTmdbEntryLink";
interface NumberedListItemProps {
entry: TmdbEntry;
@@ -8,12 +9,11 @@ interface NumberedListItemProps {
}
export function NumberedListItem({ entry, rank }: NumberedListItemProps) {
const title = entry.title || entry.name || 'Untitled';
const title = entry.title || entry.name || "Untitled";
const poster = entry.poster_path
? `https://image.tmdb.org/t/p/w92${entry.poster_path}`
: null;
const isTv = entry.media_type === 'tv' || !!entry.name;
const linkTo = `/entry/tmdb/${isTv ? 'tv' : 'movie'}/${entry.id}`;
const { linkTo } = useTmdbEntryLink(entry);
return (
<Link
@@ -24,7 +24,9 @@ export function NumberedListItem({ entry, rank }: NumberedListItemProps) {
{rank}
</span>
<div className="h-12 w-8 shrink-0 overflow-hidden rounded bg-muted">
{poster && <img src={poster} alt="" className="h-full w-full object-cover" />}
{poster && (
<img src={poster} alt="" className="h-full w-full object-cover" />
)}
</div>
<div className="min-w-0 flex-1">
<p className="truncate text-sm font-medium">{title}</p>
@@ -1,11 +1,12 @@
import { Link } from 'react-router-dom';
import type { TmdbEntry } from '@/types';
import { Link } from "react-router-dom";
import type { TmdbEntry } from "@/types";
import { useTmdbEntryLink } from "@/hooks/useTmdbEntryLink";
function formatRelativeTime(dateStr: string): string {
const now = new Date();
const release = new Date(dateStr);
const diffMs = release.getTime() - now.getTime();
if (diffMs <= 0) return 'Out now';
if (diffMs <= 0) return "Out now";
const totalMinutes = Math.floor(diffMs / 60000);
const totalHours = Math.floor(totalMinutes / 60);
const totalDays = Math.floor(totalHours / 24);
@@ -13,10 +14,11 @@ function formatRelativeTime(dateStr: string): string {
const remDays = totalDays % 30;
if (months > 0 && remDays > 0) return `in ${months}m ${remDays}d`;
if (months > 0) return `in ${months}m`;
if (totalDays > 0) return `in ${totalDays} day${totalDays !== 1 ? 's' : ''}`;
if (totalHours > 0) return `in ${totalHours} hour${totalHours !== 1 ? 's' : ''}`;
if (totalDays > 0) return `in ${totalDays} day${totalDays !== 1 ? "s" : ""}`;
if (totalHours > 0)
return `in ${totalHours} hour${totalHours !== 1 ? "s" : ""}`;
if (totalMinutes > 0) return `in ${totalMinutes} min`;
return 'Very soon';
return "Very soon";
}
interface UpcomingCardProps {
@@ -24,12 +26,11 @@ interface UpcomingCardProps {
}
export function UpcomingCard({ entry }: UpcomingCardProps) {
const title = entry.title || entry.name || 'Untitled';
const title = entry.title || entry.name || "Untitled";
const poster = entry.poster_path
? `https://image.tmdb.org/t/p/w185${entry.poster_path}`
: null;
const isTv = entry.media_type === 'tv' || !!entry.name;
const linkTo = `/entry/tmdb/${isTv ? 'tv' : 'movie'}/${entry.id}`;
const { linkTo } = useTmdbEntryLink(entry);
const releaseDate = entry.release_date || entry.first_air_date;
const relativeTime = releaseDate ? formatRelativeTime(releaseDate) : null;
@@ -37,9 +38,9 @@ export function UpcomingCard({ entry }: UpcomingCardProps) {
<Link
to={linkTo}
className="group relative shrink-0 overflow-hidden rounded-xl border border-border/50 bg-card transition-colors hover:border-border"
style={{ width: '110px' }}
style={{ width: "110px" }}
>
<div className="relative overflow-hidden" style={{ aspectRatio: '2/3' }}>
<div className="relative overflow-hidden" style={{ aspectRatio: "2/3" }}>
{poster ? (
<img
src={poster}
@@ -55,10 +56,10 @@ export function UpcomingCard({ entry }: UpcomingCardProps) {
{releaseDate && (
<div className="absolute bottom-0 left-0 right-0 bg-linear-to-t from-black/80 to-transparent px-2 py-2">
<p className="text-[9px] font-semibold leading-tight text-white/90">
{new Date(releaseDate).toLocaleDateString('en-US', {
month: 'short',
day: 'numeric',
year: 'numeric',
{new Date(releaseDate).toLocaleDateString("en-US", {
month: "short",
day: "numeric",
year: "numeric",
})}
</p>
</div>
@@ -0,0 +1,42 @@
import { useMemo } from 'react';
import { useLibraryStore } from '@/stores/useLibraryStore';
import type { TmdbEntry } from '@/types';
interface TmdbEntryLink {
/** The resolved link — either /entry/:id if in library, or /entry/tmdb/:type/:id */
linkTo: string;
/** Whether the entry is already in the user's library */
isInLibrary: boolean;
/** The library Entry ID if found, otherwise null */
libraryEntryId: number | null;
}
/**
* Resolves the correct navigation link for a TmdbEntry.
* If the entry is already in the library, links directly to EntryDetailsPage.
* Otherwise, links to the TmdbPreviewPage.
*/
export function useTmdbEntryLink(entry: TmdbEntry): TmdbEntryLink {
const libraryEntries = useLibraryStore((s) => s.entries);
return useMemo(() => {
const isTv = entry.media_type === 'tv' || !!entry.name;
const libraryEntry = Array.from(libraryEntries.values()).find(
(e) => e.entryIds?.tmdb_id === entry.id,
);
if (libraryEntry) {
return {
linkTo: `/entry/${libraryEntry.id}`,
isInLibrary: true,
libraryEntryId: libraryEntry.id,
};
}
return {
linkTo: `/entry/tmdb/${isTv ? 'tv' : 'movie'}/${entry.id}`,
isInLibrary: false,
libraryEntryId: null,
};
}, [entry.id, libraryEntries]);
}
+277
View File
@@ -0,0 +1,277 @@
import { useState, useMemo, useEffect, useRef } from "react";
import { useParams, Link } from "react-router-dom";
import { useTmdbPreview } from "@/hooks/useEntries";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import { Skeleton } from "@/components/ui/skeleton";
import { Input } from "@/components/ui/input";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import type { Credit } from "@/types";
type SortField = "name" | "gender" | "popularity";
type SortDir = "asc" | "desc";
type CastFilter = "all" | "cast" | "crew";
const PAGE_SIZE = 24;
const SORT_LABELS: Record<SortField, string> = {
name: "Name",
gender: "Gender",
popularity: "Popularity",
};
const FILTER_LABELS: Record<CastFilter, string> = {
all: "All",
cast: "Cast",
crew: "Crew",
};
function sortCredits(
credits: Credit[],
field: SortField,
dir: SortDir,
): Credit[] {
return [...credits].sort((a, b) => {
let cmp = 0;
switch (field) {
case "name":
cmp = (a.people?.name ?? "").localeCompare(b.people?.name ?? "");
break;
case "gender":
cmp = (a.people?.gender ?? 0) - (b.people?.gender ?? 0);
break;
case "popularity":
cmp = (b.people?.popularity ?? 0) - (a.people?.popularity ?? 0);
break;
}
return dir === "asc" ? cmp : -cmp;
});
}
export function TmdbCastsPage() {
const { type, tmdbId } = useParams<{ type: string; tmdbId: string }>();
const tmdbIdNum = parseInt(tmdbId!, 10);
const mediaType = type as "movie" | "tv";
const { data: preview, isLoading } = useTmdbPreview(tmdbIdNum, mediaType);
const allCredits = (preview?.credits ?? []) as unknown as Credit[];
const [sortField, setSortField] = useState<SortField>("popularity");
const [sortDir, setSortDir] = useState<SortDir>("asc");
const [filter, setFilter] = useState<CastFilter>("cast");
const [search, setSearch] = useState("");
const [visibleCount, setVisibleCount] = useState(PAGE_SIZE);
const filtered = useMemo(() => {
let result = allCredits;
if (filter === "cast")
result = result.filter((c) => c.cast_type === "cast");
else if (filter === "crew")
result = result.filter((c) => c.cast_type === "crew");
if (search.trim()) {
const q = search.trim().toLowerCase();
result = result.filter((c) => {
const name = c.people?.name?.toLowerCase() ?? "";
const role =
(c.cast_type === "cast"
? c.character
: c.job || c.department
)?.toLowerCase() ?? "";
return name.includes(q) || role.includes(q);
});
}
return result;
}, [allCredits, filter, search]);
const sorted = useMemo(
() => sortCredits(filtered, sortField, sortDir),
[filtered, sortField, sortDir],
);
useEffect(() => {
setVisibleCount(PAGE_SIZE);
}, [filter, sortField, sortDir, search]);
const visible = useMemo(
() => sorted.slice(0, visibleCount),
[sorted, visibleCount],
);
const hasMore = visibleCount < sorted.length;
const sentinelRef = useRef<HTMLDivElement | null>(null);
useEffect(() => {
if (!hasMore) return;
const node = sentinelRef.current;
if (!node) return;
const observer = new IntersectionObserver(
(entries) => {
if (entries.some((e) => e.isIntersecting)) {
setVisibleCount((c) => Math.min(c + PAGE_SIZE, sorted.length));
}
},
{ rootMargin: "400px 0px" },
);
observer.observe(node);
return () => observer.disconnect();
}, [hasMore, sorted.length]);
if (isLoading || !preview) {
return (
<div className="space-y-6 mx-auto max-w-4xl">
<Skeleton className="h-5 w-64" />
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5">
{Array.from({ length: 18 }).map((_, i) => (
<div key={i} className="flex flex-col items-center gap-2">
<Skeleton className="h-32 w-32 rounded-full" />
<Skeleton className="h-4 w-20" />
</div>
))}
</div>
</div>
);
}
const isTv = preview.is_tvseries;
return (
<div className="space-y-6 animate-page-enter mx-auto max-w-4xl">
{/* Breadcrumb */}
<div className="flex items-center gap-1.5 text-sm text-muted-foreground">
<Link
to={`/entry/tmdb/${mediaType}/${tmdbIdNum}`}
className="hover:text-foreground transition-colors truncate max-w-60"
>
{preview.title}
</Link>
<span>/</span>
<span className="text-foreground font-medium">Cast &amp; Crew</span>
</div>
{/* Controls */}
<div className="flex flex-wrap items-center gap-3">
<Input
placeholder="Search people…"
value={search}
onChange={(e) => setSearch(e.target.value)}
className="w-48"
/>
<span className="text-sm text-muted-foreground whitespace-nowrap">
{sorted.length} {sorted.length === 1 ? "credit" : "credits"}
</span>
<div className="flex items-center gap-3 ml-auto">
<Select
value={filter}
onValueChange={(v) => setFilter(v as CastFilter)}
>
<SelectTrigger className="w-32">
<SelectValue>{FILTER_LABELS[filter]}</SelectValue>
</SelectTrigger>
<SelectContent>
<SelectItem value="all">All</SelectItem>
<SelectItem value="cast">Cast</SelectItem>
<SelectItem value="crew">Crew</SelectItem>
</SelectContent>
</Select>
<Select
value={sortField}
onValueChange={(v) => setSortField(v as SortField)}
>
<SelectTrigger className="w-32">
<SelectValue>{SORT_LABELS[sortField]}</SelectValue>
</SelectTrigger>
<SelectContent>
<SelectItem value="name">Name</SelectItem>
<SelectItem value="popularity">Popularity</SelectItem>
<SelectItem value="gender">Gender</SelectItem>
</SelectContent>
</Select>
</div>
</div>
{/* Grid */}
{sorted.length === 0 ? (
<p className="text-center text-muted-foreground py-12">
No credits found.
</p>
) : (
<>
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5">
{visible.map((credit) => (
<TmdbCreditCard key={credit.id} credit={credit} isTv={isTv} />
))}
</div>
{hasMore && (
<div ref={sentinelRef} className="flex justify-center py-6">
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 w-full">
{Array.from({
length: Math.min(PAGE_SIZE, sorted.length - visibleCount),
}).map((_, i) => (
<div key={i} className="flex flex-col items-center gap-2 p-2">
<Skeleton className="h-32 w-32 rounded-full" />
<Skeleton className="h-3 w-16" />
</div>
))}
</div>
</div>
)}
</>
)}
</div>
);
}
function TmdbCreditCard({ credit, isTv }: { credit: Credit; isTv: boolean }) {
const profileUrl = credit.people?.profile_path
? `https://image.tmdb.org/t/p/w185${credit.people.profile_path}`
: undefined;
const personLink = credit.entry_id
? `/people/${credit.people_id}`
: `/people/tmdb/${credit.people?.tmdb_id ?? credit.people_id}`;
const roleLabel =
credit.cast_type === "cast"
? credit.character
: credit.job || credit.department;
return (
<Link
to={personLink}
className="group flex flex-col items-center gap-3 text-center p-3 rounded-lg hover:bg-accent/50 transition-colors"
>
<Avatar className="h-32 w-32 transition-transform group-hover:scale-105">
<AvatarImage src={profileUrl} alt={credit.people?.name} />
<AvatarFallback className="text-sm">
{credit.people?.name
?.split(" ")
.map((n) => n[0])
.join("")}
</AvatarFallback>
</Avatar>
<div className="min-w-0 w-full">
<p className="text-sm font-medium leading-tight line-clamp-2">
{credit.people?.name}
</p>
{roleLabel && (
<p className="text-xs text-muted-foreground leading-tight line-clamp-1 mt-0.5">
{roleLabel}
</p>
)}
{isTv && credit.episode_count != null && credit.episode_count > 0 && (
<p className="text-xs text-muted-foreground/70 leading-tight mt-0.5">
{credit.episode_count}{" "}
{credit.episode_count === 1 ? "episode" : "episodes"}
</p>
)}
</div>
</Link>
);
}
+53 -27
View File
@@ -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>
+71 -50
View File
@@ -1,6 +1,6 @@
import { createBrowserRouter, createHashRouter } from 'react-router-dom';
import { lazy, Suspense, type ReactNode } from 'react';
import { AppLayout } from '@/components/layout/AppLayout';
import { createBrowserRouter, createHashRouter } from "react-router-dom";
import { lazy, Suspense, type ReactNode } from "react";
import { AppLayout } from "@/components/layout/AppLayout";
import {
DashboardSkeleton,
HomeSkeleton,
@@ -16,81 +16,94 @@ import {
MediaSkeleton,
CalendarSkeleton,
SettingsSkeleton,
} from '@/components/skeletons/PageSkeletons';
} from "@/components/skeletons/PageSkeletons";
// Lazy-loaded pages
const HomePage = lazy(() =>
import('@/pages/HomePage').then((m) => ({ default: m.HomePage }))
import("@/pages/HomePage").then((m) => ({ default: m.HomePage })),
);
const DashboardPage = lazy(() =>
import('@/pages/DashboardPage').then((m) => ({ default: m.DashboardPage }))
import("@/pages/DashboardPage").then((m) => ({ default: m.DashboardPage })),
);
const LibraryPage = lazy(() =>
import('@/pages/LibraryPage').then((m) => ({ default: m.LibraryPage }))
import("@/pages/LibraryPage").then((m) => ({ default: m.LibraryPage })),
);
const WatchlistPage = lazy(() =>
import('@/pages/WatchlistPage').then((m) => ({ default: m.WatchlistPage }))
import("@/pages/WatchlistPage").then((m) => ({ default: m.WatchlistPage })),
);
const CollectionsPage = lazy(() =>
import('@/pages/CollectionsPage').then((m) => ({
import("@/pages/CollectionsPage").then((m) => ({
default: m.CollectionsPage,
}))
})),
);
const CollectionDetailsPage = lazy(() =>
import('@/pages/CollectionDetailsPage').then((m) => ({
import("@/pages/CollectionDetailsPage").then((m) => ({
default: m.CollectionDetailsPage,
}))
})),
);
const MediaPage = lazy(() =>
import('@/pages/MediaPage').then((m) => ({ default: m.MediaPage }))
import("@/pages/MediaPage").then((m) => ({ default: m.MediaPage })),
);
const CalendarPage = lazy(() =>
import('@/pages/CalendarPage').then((m) => ({ default: m.CalendarPage }))
import("@/pages/CalendarPage").then((m) => ({ default: m.CalendarPage })),
);
const EntryDetailsPage = lazy(() =>
import('@/pages/EntryDetailsPage').then((m) => ({
import("@/pages/EntryDetailsPage").then((m) => ({
default: m.EntryDetailsPage,
}))
})),
);
const TmdbPreviewPage = lazy(() =>
import('@/pages/TmdbPreviewPage').then((m) => ({
import("@/pages/TmdbPreviewPage").then((m) => ({
default: m.TmdbPreviewPage,
}))
})),
);
const TmdbCastsPage = lazy(() =>
import("@/pages/TmdbCastsPage").then((m) => ({
default: m.TmdbCastsPage,
})),
);
const SeasonPage = lazy(() =>
import('@/pages/SeasonPage').then((m) => ({ default: m.SeasonPage }))
import("@/pages/SeasonPage").then((m) => ({ default: m.SeasonPage })),
);
const EpisodePage = lazy(() =>
import('@/pages/EpisodePage').then((m) => ({ default: m.EpisodePage }))
import("@/pages/EpisodePage").then((m) => ({ default: m.EpisodePage })),
);
const EntryCastsPage = lazy(() =>
import('@/pages/EntryCastsPage').then((m) => ({
import("@/pages/EntryCastsPage").then((m) => ({
default: m.EntryCastsPage,
}))
})),
);
const PeoplePage = lazy(() =>
import('@/pages/PeoplePage').then((m) => ({ default: m.PeoplePage }))
import("@/pages/PeoplePage").then((m) => ({ default: m.PeoplePage })),
);
const PersonDetailsPage = lazy(() =>
import('@/pages/PersonDetailsPage').then((m) => ({
import("@/pages/PersonDetailsPage").then((m) => ({
default: m.PersonDetailsPage,
}))
})),
);
const SettingsPage = lazy(() =>
import('@/pages/SettingsPage').then((m) => ({ default: m.SettingsPage }))
import("@/pages/SettingsPage").then((m) => ({ default: m.SettingsPage })),
);
const DiscoverPage = lazy(() =>
import('@/pages/DiscoverPage').then((m) => ({ default: m.DiscoverPage }))
import("@/pages/DiscoverPage").then((m) => ({ default: m.DiscoverPage })),
);
const SearchPage = lazy(() =>
import('@/pages/SearchPage').then((m) => ({ default: m.SearchPage }))
import("@/pages/SearchPage").then((m) => ({ default: m.SearchPage })),
);
function SuspensePage({ children, fallback }: { children: ReactNode; fallback?: ReactNode }) {
return <Suspense fallback={fallback ?? <HomeSkeleton />}>{children}</Suspense>;
function SuspensePage({
children,
fallback,
}: {
children: ReactNode;
fallback?: ReactNode;
}) {
return (
<Suspense fallback={fallback ?? <HomeSkeleton />}>{children}</Suspense>
);
}
const isElectron = import.meta.env.VITE_ELECTRON === 'true';
const isElectron = import.meta.env.VITE_ELECTRON === "true";
const createRouter = isElectron ? createHashRouter : createBrowserRouter;
export const router = createRouter([
@@ -98,7 +111,7 @@ export const router = createRouter([
element: <AppLayout />,
children: [
{
path: '/',
path: "/",
element: (
<SuspensePage fallback={<HomeSkeleton />}>
<HomePage />
@@ -106,7 +119,7 @@ export const router = createRouter([
),
},
{
path: '/search',
path: "/search",
element: (
<SuspensePage fallback={<HomeSkeleton />}>
<SearchPage />
@@ -114,7 +127,7 @@ export const router = createRouter([
),
},
{
path: '/dashboard',
path: "/dashboard",
element: (
<SuspensePage fallback={<DashboardSkeleton />}>
<DashboardPage />
@@ -122,7 +135,7 @@ export const router = createRouter([
),
},
{
path: '/library',
path: "/library",
element: (
<SuspensePage fallback={<LibrarySkeleton />}>
<LibraryPage />
@@ -130,7 +143,7 @@ export const router = createRouter([
),
},
{
path: '/discover/:category',
path: "/discover/:category",
element: (
<SuspensePage fallback={<HomeSkeleton />}>
<DiscoverPage />
@@ -138,7 +151,7 @@ export const router = createRouter([
),
},
{
path: '/watchlist',
path: "/watchlist",
element: (
<SuspensePage fallback={<WatchlistSkeleton />}>
<WatchlistPage />
@@ -146,7 +159,7 @@ export const router = createRouter([
),
},
{
path: '/collections',
path: "/collections",
element: (
<SuspensePage fallback={<CollectionsSkeleton />}>
<CollectionsPage />
@@ -154,7 +167,7 @@ export const router = createRouter([
),
},
{
path: '/collections/:id',
path: "/collections/:id",
element: (
<SuspensePage fallback={<CollectionDetailsSkeleton />}>
<CollectionDetailsPage />
@@ -162,7 +175,7 @@ export const router = createRouter([
),
},
{
path: '/media',
path: "/media",
element: (
<SuspensePage fallback={<MediaSkeleton />}>
<MediaPage />
@@ -170,7 +183,7 @@ export const router = createRouter([
),
},
{
path: '/calendar',
path: "/calendar",
element: (
<SuspensePage fallback={<CalendarSkeleton />}>
<CalendarPage />
@@ -178,7 +191,15 @@ export const router = createRouter([
),
},
{
path: '/entry/tmdb/:type/:tmdbId',
path: "/entry/tmdb/:type/:tmdbId/cast",
element: (
<SuspensePage fallback={<PeopleSkeleton />}>
<TmdbCastsPage />
</SuspensePage>
),
},
{
path: "/entry/tmdb/:type/:tmdbId",
element: (
<SuspensePage fallback={<EntryDetailsSkeleton />}>
<TmdbPreviewPage />
@@ -186,7 +207,7 @@ export const router = createRouter([
),
},
{
path: '/entry/:id',
path: "/entry/:id",
element: (
<SuspensePage fallback={<EntryDetailsSkeleton />}>
<EntryDetailsPage />
@@ -194,7 +215,7 @@ export const router = createRouter([
),
},
{
path: '/entry/:id/cast',
path: "/entry/:id/cast",
element: (
<SuspensePage fallback={<PeopleSkeleton />}>
<EntryCastsPage />
@@ -202,7 +223,7 @@ export const router = createRouter([
),
},
{
path: '/entry/:entryId/season/:seasonId',
path: "/entry/:entryId/season/:seasonId",
element: (
<SuspensePage fallback={<SeasonSkeleton />}>
<SeasonPage />
@@ -210,7 +231,7 @@ export const router = createRouter([
),
},
{
path: '/entry/:entryId/season/:seasonId/episode/:episodeId',
path: "/entry/:entryId/season/:seasonId/episode/:episodeId",
element: (
<SuspensePage fallback={<EpisodeSkeleton />}>
<EpisodePage />
@@ -218,7 +239,7 @@ export const router = createRouter([
),
},
{
path: '/people',
path: "/people",
element: (
<SuspensePage fallback={<PeopleSkeleton />}>
<PeoplePage />
@@ -226,7 +247,7 @@ export const router = createRouter([
),
},
{
path: '/people/tmdb/:tmdbId',
path: "/people/tmdb/:tmdbId",
element: (
<SuspensePage fallback={<PersonDetailsSkeleton />}>
<PersonDetailsPage />
@@ -234,7 +255,7 @@ export const router = createRouter([
),
},
{
path: '/people/:id',
path: "/people/:id",
element: (
<SuspensePage fallback={<PersonDetailsSkeleton />}>
<PersonDetailsPage />
@@ -242,7 +263,7 @@ export const router = createRouter([
),
},
{
path: '/settings',
path: "/settings",
element: (
<SuspensePage fallback={<SettingsSkeleton />}>
<SettingsPage />