Files
Showy/react_frontend/src/components/entries/EntryCard.tsx
T
Mohammed Abad 9a8ee181e5 Complete frontend refactoring: UI enhancements, pagination, filtering, search architecture, and data management improvements
# Phase 1: Feature Implementation
- Add "Create new..." option in `AddEntryToCollectionDialog` for inline collection creation with auto-select
- Implement lazy loading pagination with IntersectionObserver for Watchlist, Collections, and Media pages
- Add reusable useDebounce hook (300-400ms) and apply to all search inputs across pages
- Reset scroll position to top when switching between sidebar navigation pages via useLocation()
- Reorganize MediaPage with horizontal control layout, add Media Type filter (All/Audio/Video), and Custom Media filter (Show All/Official Only/Custom Only)
- Add three-dot menu (MoreHorizontal icon) to collection cards with Edit/Delete options and "Get all parts" feature
- Replace numeric rating input with interactive star rating component in EditCollectionDialog (0-10 stars with half-star support)
- Display entry type badges ("Movie" / "TV Series") on home page trending/popular sections and search results
- Create PeopleSearchResult component with profile images; integrate useTmdbSearchPeople hook linking to `/people/tmdb/:tmdbId`
- Add TMDB Rating and User Rating filters to Library page with range sliders (0-10, step 1) and state persistence in useLibraryStore
- Add All/Movies/TV Series type filter to Watchlist page with filtered count display
- Improve People Details page mobile UI: optimize header, info section sizing, and filmography card layouts for touch

# Phase 2: Architecture Refactoring & Bug Fixes
- Fix scroll-to-top on sidebar navigation by constraining AppLayout root to `h-screen overflow-hidden` so `<main>` becomes proper scroll container
- Extract search from HomePage into dedicated SearchPage component with `/search` route, debounced input, and URL query sync via SearchParams
- Add Search nav item with icon to sidebar for easy search access
- HomePage search input now navigates to `/search?q=...` instead of handling inline, separating concerns and enabling search bookmarking
- Entry type pill badges now conditionally render via `showTypeBadge` prop on EntryCard—only SearchPage passes this to prevent display on home/discover pages
- Fix people ID bug: people search results now link to `/people/tmdb/:tmdbId` (TMDB redirect route) instead of `/people/:id`, correctly mapping TMDB IDs to local database IDs through PersonTmdbRedirectPage
- Enhance People Details filmography sorting: "Not in Library" section now detects self roles (self/themselves/himself/herself) and sorts non-self by release date (new→old) with all self roles pushed to end of list

# Summary
- Created new files: SearchPage.tsx, useDebounce.ts
2026-04-12 01:33:00 +01:00

198 lines
6.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { useState } from 'react';
import { Link } from 'react-router-dom';
import { Plus, Trash2, Star, Loader2 } from 'lucide-react';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import { Skeleton } from '@/components/ui/skeleton';
import { getPosterUrl, getYear, formatRuntime } from '@/lib/media-utils';
import { useCreateEntry, useDeleteEntry } from '@/hooks/useEntries';
import { useLibraryStore } from '@/stores/useLibraryStore';
import { ConfirmDialog } from '@/components/dialogs/ConfirmDialog';
import type { Entry, TmdbEntry } from '@/types';
interface EntryCardProps {
entry?: Entry;
tmdbEntry?: TmdbEntry;
showTypeBadge?: boolean;
}
export function EntryCard({ entry, tmdbEntry, showTypeBadge }: EntryCardProps) {
const [showConfirm, setShowConfirm] = useState(false);
const createEntry = useCreateEntry();
const deleteEntry = useDeleteEntry();
const libraryEntry = useLibraryStore((s) => {
if (entry?.isInLibrary) return entry;
if (tmdbEntry) {
for (const e of s.entries.values()) {
if (e.entryIds?.tmdb_id === tmdbEntry.id) return e;
}
}
return null;
});
const isInLibrary = !!libraryEntry;
const displayEntry = libraryEntry || entry;
// Resolve display data
const title =
displayEntry?.title || tmdbEntry?.title || tmdbEntry?.name || 'Untitled';
const year = displayEntry
? getYear(displayEntry.release_date)
: getYear(tmdbEntry?.release_date || tmdbEntry?.first_air_date || null);
const rating =
displayEntry?.entryRatings?.user_rating ||
displayEntry?.entryRatings?.tmdb_rating ||
tmdbEntry?.vote_average;
const runtime =
displayEntry && !displayEntry.is_tvseries
? formatRuntime(displayEntry.runtime)
: '';
const isTv =
displayEntry?.is_tvseries ||
tmdbEntry?.media_type === 'tv' ||
!!tmdbEntry?.name;
const posterUrl = displayEntry
? getPosterUrl(displayEntry)
: tmdbEntry?.poster_path
? `https://image.tmdb.org/t/p/w342${tmdbEntry.poster_path}`
: '/images/default-poster.png';
const entryLink = displayEntry
? `/entry/${displayEntry.id}`
: undefined;
const handleAdd = (e: React.MouseEvent) => {
e.preventDefault();
e.stopPropagation();
if (!tmdbEntry) return;
createEntry.mutate({ tmdb_id: tmdbEntry.id, is_tvserie: isTv });
};
const handleRemove = (e: React.MouseEvent) => {
e.preventDefault();
e.stopPropagation();
setShowConfirm(true);
};
const confirmRemove = () => {
if (libraryEntry) {
deleteEntry.mutate(libraryEntry.id, {
onSettled: () => setShowConfirm(false),
});
}
};
const card = (
<div className="group relative overflow-hidden rounded-lg transition-all duration-300 hover:scale-[1.02] hover:shadow-xl animate-in fade-in zoom-in-95">
{/* Poster */}
<div className="relative aspect-[2/3] w-full overflow-hidden rounded-lg bg-muted">
<img
src={posterUrl}
alt={title}
className="h-full w-full object-cover transition-transform duration-300 group-hover:scale-105"
loading="lazy"
/>
{/* Library badge – only on home / search (tmdbEntry context) */}
{isInLibrary && tmdbEntry && (
<Badge className="absolute left-2 top-2 bg-primary text-primary-foreground text-[10px] px-1.5 py-0.5">
In Library
</Badge>
)}
{/* Favorite indicator */}
{libraryEntry?.favorit && (
<Star className="absolute right-2 top-2 h-4 w-4 fill-yellow-400 text-yellow-400" />
)}
{/* Entry type pill */}
{showTypeBadge && tmdbEntry && (
<Badge
variant="secondary"
className="absolute bottom-2 right-2 text-[10px] px-1.5 py-0.5 opacity-90 z-10 pointer-events-none"
>
{isTv ? 'TV Series' : 'Movie'}
</Badge>
)}
{/* Hover overlay */}
<div className="absolute inset-0 flex flex-col justify-end bg-gradient-to-t from-black/90 via-black/40 to-transparent opacity-0 transition-opacity duration-200 group-hover:opacity-100">
<div className="p-3 space-y-1">
<p className="text-sm font-semibold text-white line-clamp-2">
{title}
</p>
<div className="flex items-center gap-2 text-xs text-white/70">
{rating != null && rating > 0 && (
<span className="flex items-center gap-1">
<Star className="h-3 w-3 fill-yellow-400 text-yellow-400" />
{typeof rating === 'number' ? rating.toFixed(1) : rating}
</span>
)}
{year && <span>{year}</span>}
{runtime && <span>{runtime}</span>}
</div>
{/* Actions */}
<div className="pt-1">
{isInLibrary ? (
<Button
size="sm"
variant="destructive"
className="h-7 w-full text-xs"
onClick={handleRemove}
disabled={deleteEntry.isPending}
>
{deleteEntry.isPending ? (
<Loader2 className="mr-1 h-3 w-3 animate-spin" />
) : (
<Trash2 className="mr-1 h-3 w-3" />
)}
{deleteEntry.isPending ? 'Removing...' : 'Remove'}
</Button>
) : tmdbEntry ? (
<Button
size="sm"
className="h-7 w-full text-xs"
onClick={handleAdd}
disabled={createEntry.isPending}
>
{createEntry.isPending ? (
<Loader2 className="mr-1 h-3 w-3 animate-spin" />
) : (
<Plus className="mr-1 h-3 w-3" />
)}
{createEntry.isPending ? 'Adding...' : 'Add to Library'}
</Button>
) : null}
</div>
</div>
</div>
</div>
</div>
);
return (
<>
{entryLink ? <Link to={entryLink}>{card}</Link> : card}
<ConfirmDialog
open={showConfirm}
onOpenChange={setShowConfirm}
title="Remove from Library"
description={`Are you sure you want to remove "${title}" from your library? This action cannot be undone.`}
confirmLabel="Remove"
onConfirm={confirmRemove}
variant="destructive"
/>
</>
);
}
export function EntryCardSkeleton() {
return (
<div className="space-y-2">
<Skeleton className="aspect-[2/3] w-full rounded-lg" />
</div>
);
}