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>