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

+71 -15
View File
@@ -1,6 +1,7 @@
import { useState, useMemo } from 'react';
import { useState, useMemo, useCallback, useEffect, useRef } from 'react';
import { useLibrary } from '@/hooks/useEntries';
import { useLibraryEntries } from '@/stores/useLibraryStore';
import { useDebounce } from '@/hooks/useDebounce';
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
import { Input } from '@/components/ui/input';
import { Skeleton } from '@/components/ui/skeleton';
@@ -8,13 +9,38 @@ import { Search } from 'lucide-react';
import { getMediaUrl } from '@/lib/api';
import type { Media } from '@/types';
const PAGE_SIZE = 36;
export function MediaPage() {
const { isLoading } = useLibrary();
const [search, setSearch] = useState('');
const debouncedSearch = useDebounce(search, 300);
const [mediaType, setMediaType] = useState<'all' | 'poster' | 'backdrop' | 'logo'>('all');
const [customFilter, setCustomFilter] = useState<'all' | 'custom' | 'official'>('custom');
const [visibleCount, setVisibleCount] = useState(PAGE_SIZE);
const entries = useLibraryEntries();
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) {
setVisibleCount((c) => c + PAGE_SIZE);
}
});
if (node) observerRef.current.observe(node);
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[isLoading]
);
useEffect(() => {
return () => observerRef.current?.disconnect();
}, []);
const allMedias = useMemo(() => {
const medias: (Media & { entryTitle: string })[] = [];
entries.forEach((entry) => {
@@ -32,19 +58,58 @@ export function MediaPage() {
result = result.filter((m) => m.type === mediaType);
}
if (search) {
const q = search.toLowerCase();
if (customFilter === 'custom') {
result = result.filter((m) => m.is_custom);
} else if (customFilter === 'official') {
result = result.filter((m) => !m.is_custom);
}
if (debouncedSearch) {
const q = debouncedSearch.toLowerCase();
result = result.filter((m) => m.entryTitle.toLowerCase().includes(q));
}
return result;
}, [allMedias, mediaType, search]);
}, [allMedias, mediaType, customFilter, debouncedSearch]);
useEffect(() => {
setVisibleCount(PAGE_SIZE);
}, [mediaType, customFilter, debouncedSearch]);
const paginatedMedia = useMemo(
() => filtered.slice(0, visibleCount),
[filtered, visibleCount]
);
const hasMore = visibleCount < filtered.length;
return (
<div className="space-y-6">
<h1 className="text-2xl font-bold">Media</h1>
<div className="flex flex-wrap items-center gap-3">
<div className="relative flex-1 max-w-xs">
<Search className="absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
<Input
placeholder="Search by title..."
value={search}
onChange={(e) => setSearch(e.target.value)}
className="pl-10"
/>
</div>
<div className="flex-1" />
<Tabs
value={customFilter}
onValueChange={(v) => setCustomFilter(v as typeof customFilter)}
>
<TabsList>
<TabsTrigger value="all">All</TabsTrigger>
<TabsTrigger value="custom">Custom</TabsTrigger>
<TabsTrigger value="official">Official</TabsTrigger>
</TabsList>
</Tabs>
<Tabs
value={mediaType}
onValueChange={(v) => setMediaType(v as typeof mediaType)}
@@ -56,16 +121,6 @@ export function MediaPage() {
<TabsTrigger value="logo">Logos</TabsTrigger>
</TabsList>
</Tabs>
<div className="relative flex-1 max-w-xs">
<Search className="absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
<Input
placeholder="Search by title..."
value={search}
onChange={(e) => setSearch(e.target.value)}
className="pl-10"
/>
</div>
</div>
{isLoading ? (
@@ -93,9 +148,10 @@ export function MediaPage() {
: 'grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6'
}`}
>
{filtered.map((media) => (
{paginatedMedia.map((media, index) => (
<div
key={media.id}
ref={index === paginatedMedia.length - 1 ? lastItemRef : undefined}
className="group relative overflow-hidden rounded-lg bg-muted"
>
<img