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
This commit is contained in:
Mohammed Abad committed 2026-04-12 01:33:00 +01:00
1 parent d28b4caa7e
commit 9a8ee181e5
23 files changed
+680 -188

No files matched your search

@@ -1,3 +1,4 @@
import { useCallback, useRef, useEffect } from 'react';
import { Link } from 'react-router-dom';
import { getCollectionPosterUrl } from '@/lib/media-utils';
import { Skeleton } from '@/components/ui/skeleton';
@@ -37,12 +38,35 @@ export function CollectionCardSkeleton() {
interface CollectionsGridProps {
collections: Collection[];
isLoading?: boolean;
hasMore?: boolean;
onLoadMore?: () => void;
}
export function CollectionsGrid({
collections,
isLoading,
hasMore,
onLoadMore,
}: CollectionsGridProps) {
const observerRef = useRef<IntersectionObserver | null>(null);
const lastItemRef = useCallback(
(node: HTMLDivElement | null) => {
if (isLoading) return;
if (observerRef.current) observerRef.current.disconnect();
observerRef.current = new IntersectionObserver((entries) => {
if (entries[0].isIntersecting && hasMore && onLoadMore) {
onLoadMore();
}
});
if (node) observerRef.current.observe(node);
},
[isLoading, hasMore, onLoadMore]
);
useEffect(() => {
return () => observerRef.current?.disconnect();
}, []);
if (isLoading) {
return (
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6">
@@ -66,6 +90,7 @@ export function CollectionsGrid({
{collections.map((collection, index) => (
<div
key={collection.id}
ref={index === collections.length - 1 ? lastItemRef : undefined}
className="animate-card-enter"
style={{ animationDelay: `${Math.min(index * 30, 300)}ms` }}
>
@@ -8,10 +8,13 @@ import {
import { Input } from '@/components/ui/input';
import { Checkbox } from '@/components/ui/checkbox';
import { ScrollArea } from '@/components/ui/scroll-area';
import { Button } from '@/components/ui/button';
import { Plus, Loader2 } from 'lucide-react';
import { useCollections } from '@/hooks/useCollections';
import { useQueryClient } from '@tanstack/react-query';
import { collectionsApi } from '@/api/collections';
import { collectionKeys } from '@/hooks/useCollections';
import { toast } from 'sonner';
import type { Collection } from '@/types';
interface AddEntryToCollectionDialogProps {
@@ -27,6 +30,7 @@ export function AddEntryToCollectionDialog({
}: AddEntryToCollectionDialogProps) {
const [search, setSearch] = useState('');
const [pending, setPending] = useState<Set<number>>(new Set());
const [creating, setCreating] = useState(false);
const { data: allCollections = [] } = useCollections();
const queryClient = useQueryClient();
@@ -34,6 +38,12 @@ export function AddEntryToCollectionDialog({
c.name.toLowerCase().includes(search.toLowerCase())
);
const showCreateOption =
search.trim().length > 0 &&
!allCollections.some(
(c) => c.name.toLowerCase() === search.trim().toLowerCase()
);
const isInCollection = (collectionId: number) =>
allCollections
.find((c) => c.id === collectionId)
@@ -75,6 +85,23 @@ export function AddEntryToCollectionDialog({
}
};
const handleCreate = async () => {
const name = search.trim();
if (!name) return;
setCreating(true);
try {
const newCollection = await collectionsApi.create({ name, is_user_collection: true } as Partial<Collection>);
await collectionsApi.addEntry(newCollection.id, entryId);
await queryClient.invalidateQueries({ queryKey: collectionKeys.all });
toast.success(`Created "${name}" and added entry`);
setSearch('');
} catch {
toast.error('Failed to create collection');
} finally {
setCreating(false);
}
};
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-md">
@@ -82,12 +109,27 @@ export function AddEntryToCollectionDialog({
<DialogTitle>Add to Collection</DialogTitle>
</DialogHeader>
<Input
placeholder="Search collections..."
placeholder="Search or create collection..."
value={search}
onChange={(e) => setSearch(e.target.value)}
/>
<ScrollArea className="h-64">
<div className="space-y-2 pr-4">
{showCreateOption && (
<Button
variant="ghost"
className="flex w-full items-center justify-start gap-2 rounded-lg p-2 text-sm text-primary hover:bg-accent/50"
disabled={creating}
onClick={handleCreate}
>
{creating ? (
<Loader2 className="h-4 w-4 animate-spin" />
) : (
<Plus className="h-4 w-4" />
)}
Create "{search.trim()}"
</Button>
)}
{filtered.map((collection) => {
const checked = isInCollection(collection.id);
const loading = pending.has(collection.id);
@@ -107,7 +149,7 @@ export function AddEntryToCollectionDialog({
</label>
);
})}
{filtered.length === 0 && (
{filtered.length === 0 && !showCreateOption && (
<p className="py-4 text-center text-sm text-muted-foreground">
No collections found.
</p>
@@ -10,7 +10,7 @@ import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Textarea } from '@/components/ui/textarea';
import { ImageIcon } from 'lucide-react';
import { ImageIcon, Star } from 'lucide-react';
import { useUpdateCollection } from '@/hooks/useCollections';
import type { Collection } from '@/types';
@@ -28,8 +28,9 @@ export function CollectionEditDialog({
const [name, setName] = useState(collection.name);
const [description, setDescription] = useState(collection.description || '');
const [userRating, setUserRating] = useState(
collection.user_rating?.toString() || ''
collection.user_rating ?? 0
);
const [hoveredStar, setHoveredStar] = useState<number | null>(null);
const [posterFile, setPosterFile] = useState<File | null>(null);
const [backdropFile, setBackdropFile] = useState<File | null>(null);
const [posterPreview, setPosterPreview] = useState<string | null>(null);
@@ -62,7 +63,7 @@ export function CollectionEditDialog({
const formData = new FormData();
formData.append('name', name);
formData.append('description', description);
formData.append('userRating', userRating || '0');
formData.append('userRating', String(userRating || 0));
if (posterFile) {
formData.append('poster', posterFile);
@@ -105,16 +106,35 @@ export function CollectionEditDialog({
</div>
<div className="space-y-2">
<Label htmlFor="col-rating">User Rating (0-10)</Label>
<Input
id="col-rating"
type="number"
min={0}
max={10}
step={0.1}
value={userRating}
onChange={(e) => setUserRating(e.target.value)}
/>
<Label>User Rating</Label>
<div className="flex items-center gap-2">
<div className="flex gap-1">
{Array.from({ length: 10 }, (_, i) => i + 1).map((star) => {
const displayRating = hoveredStar ?? userRating;
return (
<button
key={star}
type="button"
className="transition-transform hover:scale-125 focus:outline-none"
onMouseEnter={() => setHoveredStar(star)}
onMouseLeave={() => setHoveredStar(null)}
onClick={() => setUserRating(star === userRating ? 0 : star)}
>
<Star
className={`h-5 w-5 transition-colors ${
star <= displayRating
? 'fill-yellow-400 text-yellow-400'
: 'text-muted-foreground/30'
}`}
/>
</button>
);
})}
</div>
<span className="text-sm text-muted-foreground tabular-nums">
{userRating > 0 ? `${userRating}/10` : '—'}
</span>
</div>
</div>
{/* Media uploads */}
@@ -13,9 +13,10 @@ import type { Entry, TmdbEntry } from '@/types';
interface EntryCardProps {
entry?: Entry;
tmdbEntry?: TmdbEntry;
showTypeBadge?: boolean;
}
export function EntryCard({ entry, tmdbEntry }: EntryCardProps) {
export function EntryCard({ entry, tmdbEntry, showTypeBadge }: EntryCardProps) {
const [showConfirm, setShowConfirm] = useState(false);
const createEntry = useCreateEntry();
const deleteEntry = useDeleteEntry();
@@ -105,6 +106,16 @@ export function EntryCard({ entry, tmdbEntry }: EntryCardProps) {
<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">
@@ -1,5 +1,5 @@
import { Outlet } from 'react-router-dom';
import { useState } from 'react';
import { Outlet, useLocation } from 'react-router-dom';
import { useState, useRef, useEffect } from 'react';
import { Menu } from 'lucide-react';
import { Button } from '@/components/ui/button';
import {
@@ -12,9 +12,15 @@ import { Sidebar, MobileSidebarContent } from './Sidebar';
export function AppLayout() {
const [mobileOpen, setMobileOpen] = useState(false);
const mainRef = useRef<HTMLElement>(null);
const { pathname } = useLocation();
useEffect(() => {
mainRef.current?.scrollTo(0, 0);
}, [pathname]);
return (
<div className="flex min-h-screen">
<div className="flex h-screen overflow-hidden">
{/* Desktop sidebar */}
<div className="hidden md:block">
<Sidebar />
@@ -38,7 +44,7 @@ export function AppLayout() {
</SheetContent>
</Sheet>
<main className="flex-1 overflow-y-auto md:ml-56">
<main ref={mainRef} className="flex-1 overflow-y-auto md:ml-56">
<div className="container mx-auto px-4 py-4 pt-18 md:px-6 md:py-6 md:pt-6">
<Outlet />
</div>
@@ -12,6 +12,7 @@ import {
Moon,
Sun,
Film,
// Search,
} from 'lucide-react';
import { useThemeStore } from '@/stores/useThemeStore';
import { Button } from '@/components/ui/button';
@@ -25,6 +26,7 @@ import {
const mainNav = [
{ to: '/dashboard', icon: LayoutDashboard, label: 'Dashboard' },
{ to: '/', icon: Home, label: 'Home' },
// { to: '/search', icon: Search, label: 'Search' },
];
const libraryNav = [