feat(frontend): show seen dates inline on episode cards and fix cast page
- Display all seen dates inline (comma-separated) on episode cards in SeasonPage; remove unused Tooltip imports - Propagate episode_count in normalizeCredit so TV series cast shows X ep. - Add entriesApi.getCredits(id) API method and useEntryCredits(id) hook - Load all credits in EntryCastsPage via useEntryCredits (no more 10-cast limit) - Replace full-list render with IntersectionObserver lazy loader (24 per chunk) - Fix Sort/Filter Select trigger to show human-readable label instead of raw key
This commit is contained in:
1 parent
22d111ef71
commit
5fa2556b43
4 files changed
+92
-17
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { api } from '@/lib/api';
|
||||
import { normalizeEntry } from '@/lib/normalizers';
|
||||
import type { Entry, TmdbPreview } from '@/types';
|
||||
import { normalizeEntry, normalizeCredit } from '@/lib/normalizers';
|
||||
import type { Entry, Credit, TmdbPreview } from '@/types';
|
||||
|
||||
export const entriesApi = {
|
||||
getAll: () =>
|
||||
@@ -42,6 +42,11 @@ export const entriesApi = {
|
||||
getSeasons: (id: number) =>
|
||||
api.get(`/entries/${id}/seasons`).then((r) => Array.isArray(r.data) ? r.data : []),
|
||||
|
||||
getCredits: (id: number) =>
|
||||
api
|
||||
.get<Credit[]>(`/entries/${id}/credits`)
|
||||
.then((r) => (Array.isArray(r.data) ? r.data.map(normalizeCredit) : [])),
|
||||
|
||||
syncSeries: () => api.get('/entries/sync-series').then((r) => r.data),
|
||||
|
||||
previewTmdb: (tmdbId: number, type: 'movie' | 'tv') =>
|
||||
|
||||
@@ -8,6 +8,7 @@ export const entryKeys = {
|
||||
all: ['entries'] as const,
|
||||
detail: (id: number) => ['entries', id] as const,
|
||||
seasons: (id: number) => ['entries', id, 'seasons'] as const,
|
||||
credits: (id: number) => ['entries', id, 'credits'] as const,
|
||||
tmdbPreview: (tmdbId: number, type: string) => ['entries', 'tmdb-preview', type, tmdbId] as const,
|
||||
};
|
||||
|
||||
@@ -41,6 +42,15 @@ export function useEntrySeasons(id: number) {
|
||||
});
|
||||
}
|
||||
|
||||
export function useEntryCredits(id: number) {
|
||||
return useQuery({
|
||||
queryKey: entryKeys.credits(id),
|
||||
queryFn: () => entriesApi.getCredits(id),
|
||||
enabled: !!id,
|
||||
staleTime: 5 * 60 * 1000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateEntry() {
|
||||
const queryClient = useQueryClient();
|
||||
const addEntry = useLibraryStore((s) => s.addEntry);
|
||||
|
||||
@@ -41,6 +41,7 @@ export function normalizeCredit(raw: any): Credit {
|
||||
department: raw.department,
|
||||
job: raw.job,
|
||||
order: raw.order,
|
||||
episode_count: raw.episode_count ?? null,
|
||||
people: people,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useState, useMemo } from 'react';
|
||||
import { useState, useMemo, useEffect, useRef } from 'react';
|
||||
import { useParams, Link } from 'react-router-dom';
|
||||
import { useEntry } from '@/hooks/useEntries';
|
||||
import { useEntry, useEntryCredits } from '@/hooks/useEntries';
|
||||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { Button } from '@/components/ui/button';
|
||||
@@ -19,6 +19,23 @@ type SortField = 'order' | 'popularity' | 'name' | 'birthday' | 'gender' | 'epis
|
||||
type SortDir = 'asc' | 'desc';
|
||||
type CastFilter = 'all' | 'cast' | 'crew';
|
||||
|
||||
const PAGE_SIZE = 24;
|
||||
|
||||
const SORT_LABELS: Record<SortField, string> = {
|
||||
order: 'Credit Order',
|
||||
popularity: 'Popularity',
|
||||
name: 'Name',
|
||||
birthday: 'Birthday',
|
||||
gender: 'Gender',
|
||||
episode_count: 'Episodes',
|
||||
};
|
||||
|
||||
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;
|
||||
@@ -53,21 +70,49 @@ export function EntryCastsPage() {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const entryId = parseInt(id!, 10);
|
||||
const { data: entry, isLoading } = useEntry(entryId);
|
||||
const { data: allCredits = [], isLoading: creditsLoading } = useEntryCredits(entryId);
|
||||
|
||||
const [sortField, setSortField] = useState<SortField>('order');
|
||||
const [sortDir, setSortDir] = useState<SortDir>('asc');
|
||||
const [filter, setFilter] = useState<CastFilter>('all');
|
||||
const [visibleCount, setVisibleCount] = useState(PAGE_SIZE);
|
||||
|
||||
const filtered = useMemo(() => {
|
||||
if (!entry?.credits) return [];
|
||||
if (filter === 'cast') return entry.credits.filter((c) => c.cast_type === 'cast');
|
||||
if (filter === 'crew') return entry.credits.filter((c) => c.cast_type === 'crew');
|
||||
return entry.credits;
|
||||
}, [entry?.credits, filter]);
|
||||
if (!allCredits) return [];
|
||||
if (filter === 'cast') return allCredits.filter((c) => c.cast_type === 'cast');
|
||||
if (filter === 'crew') return allCredits.filter((c) => c.cast_type === 'crew');
|
||||
return allCredits;
|
||||
}, [allCredits, filter]);
|
||||
|
||||
const sorted = useMemo(() => sortCredits(filtered, sortField, sortDir), [filtered, sortField, sortDir]);
|
||||
|
||||
if (isLoading || !entry) {
|
||||
// Reset visible window whenever filter/sort changes
|
||||
useEffect(() => {
|
||||
setVisibleCount(PAGE_SIZE);
|
||||
}, [filter, sortField, sortDir]);
|
||||
|
||||
const visible = useMemo(() => sorted.slice(0, visibleCount), [sorted, visibleCount]);
|
||||
const hasMore = visibleCount < sorted.length;
|
||||
|
||||
// IntersectionObserver-based lazy load on scroll
|
||||
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 || !entry || creditsLoading) {
|
||||
return (
|
||||
<div className="space-y-6 mx-auto max-w-4xl">
|
||||
<Skeleton className="h-5 w-64" />
|
||||
@@ -103,7 +148,7 @@ export function EntryCastsPage() {
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<Select value={filter} onValueChange={(v) => setFilter(v as CastFilter)}>
|
||||
<SelectTrigger className="w-32">
|
||||
<SelectValue />
|
||||
<SelectValue>{FILTER_LABELS[filter]}</SelectValue>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="all">All</SelectItem>
|
||||
@@ -114,7 +159,7 @@ export function EntryCastsPage() {
|
||||
|
||||
<Select value={sortField} onValueChange={(v) => setSortField(v as SortField)}>
|
||||
<SelectTrigger className="w-40">
|
||||
<SelectValue />
|
||||
<SelectValue>{SORT_LABELS[sortField]}</SelectValue>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="order">Credit Order</SelectItem>
|
||||
@@ -144,11 +189,25 @@ export function EntryCastsPage() {
|
||||
{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 xl:grid-cols-6">
|
||||
{sorted.map((credit) => (
|
||||
<CreditCard key={credit.id} credit={credit} isTv={isTv} />
|
||||
))}
|
||||
</div>
|
||||
<>
|
||||
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6">
|
||||
{visible.map((credit) => (
|
||||
<CreditCard 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 xl:grid-cols-6 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-20 w-20 rounded-full" />
|
||||
<Skeleton className="h-3 w-16" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user