diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md new file mode 100644 index 0000000..aada8d3 --- /dev/null +++ b/.github/copilot-instructions.md @@ -0,0 +1,29 @@ +# Copilot Instructions + +## Mandatory Task Completion Rule + +After completing ANY task requested by the user, you MUST update the file `changes.md`. + +### Required Format + +Append a new section at the end of `changes.md` using this exact format: + +### Tasks XXX + +```md + + +- +- +- +``` + +### Rules + +- Replace `XXX` with the task number provided by the user (example: `025`). +- The first line inside the code block must be a short commit-style message (imperative tone). +- The bullet list must include all important modifications made. +- Do NOT overwrite previous entries: always APPEND. +- If `changes.md` does not exist, create it. +- If no task number is provided, use the next available number based on the last entry in the file. +- Always ensure formatting matches exactly (heading + code block + bullets). diff --git a/react_frontend/.gitignore b/react_frontend/.gitignore index 8e942ee..9bcc98a 100644 --- a/react_frontend/.gitignore +++ b/react_frontend/.gitignore @@ -26,3 +26,4 @@ dist-ssr # other goal.md prompt.md +changes.md diff --git a/react_frontend/index.html b/react_frontend/index.html index 6795220..a863227 100644 --- a/react_frontend/index.html +++ b/react_frontend/index.html @@ -4,7 +4,7 @@ - react_frontend + Showy
diff --git a/react_frontend/package-lock.json b/react_frontend/package-lock.json index 356b783..daf94ec 100644 --- a/react_frontend/package-lock.json +++ b/react_frontend/package-lock.json @@ -690,9 +690,9 @@ } }, "node_modules/@emnapi/wasi-threads": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.0.tgz", - "integrity": "sha512-N10dEJNSsUx41Z6pZsXU8FjPjpBEplgH24sfkmITrBED1/U2Esum9F3lfLrMjKHHjmi557zQn7kR9R+XWXu5Rg==", + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.1.tgz", + "integrity": "sha512-uTII7OYF+/Mes/MrcIOYp5yOtSMLBWSIoLPpcgwipoiKbli6k322tcoFsxoIIxPDqW01SQGAgko4EzZi2BNv2w==", "dev": true, "license": "MIT", "optional": true, @@ -4654,7 +4654,6 @@ "resolved": "https://registry.npmjs.org/immer/-/immer-10.2.0.tgz", "integrity": "sha512-d/+XTN3zfODyjr89gM3mPq1WNX2B8pYsu7eORitdwyA2sBubnTl3laYlBk4sXY5FUa5qTZGBDPJICVbvqzjlbw==", "license": "MIT", - "peer": true, "funding": { "type": "opencollective", "url": "https://opencollective.com/immer" diff --git a/react_frontend/src/api/collections.ts b/react_frontend/src/api/collections.ts index f295d8d..11df4b5 100644 --- a/react_frontend/src/api/collections.ts +++ b/react_frontend/src/api/collections.ts @@ -29,6 +29,9 @@ export const collectionsApi = { delete: (id: number) => api.delete(`/collections/${id}`).then((r) => r.data), + getCollectionParts: (id: number) => + api.put(`/collections/${id}/parts`).then((r) => normalizeCollection(r.data)), + addEntry: (collectionId: number, entryId: number) => api .post(`/collections/${collectionId}/entries/${entryId}`, {}) diff --git a/react_frontend/src/components/collections/CollectionsGrid.tsx b/react_frontend/src/components/collections/CollectionsGrid.tsx index b06a601..5bfd5df 100644 --- a/react_frontend/src/components/collections/CollectionsGrid.tsx +++ b/react_frontend/src/components/collections/CollectionsGrid.tsx @@ -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(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 (
@@ -66,6 +90,7 @@ export function CollectionsGrid({ {collections.map((collection, index) => (
diff --git a/react_frontend/src/components/dialogs/AddEntryToCollectionDialog.tsx b/react_frontend/src/components/dialogs/AddEntryToCollectionDialog.tsx index a0b5d9c..60cd527 100644 --- a/react_frontend/src/components/dialogs/AddEntryToCollectionDialog.tsx +++ b/react_frontend/src/components/dialogs/AddEntryToCollectionDialog.tsx @@ -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>(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); + 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 ( @@ -82,12 +109,27 @@ export function AddEntryToCollectionDialog({ Add to Collection setSearch(e.target.value)} />
+ {showCreateOption && ( + + )} {filtered.map((collection) => { const checked = isInCollection(collection.id); const loading = pending.has(collection.id); @@ -107,7 +149,7 @@ export function AddEntryToCollectionDialog({ ); })} - {filtered.length === 0 && ( + {filtered.length === 0 && !showCreateOption && (

No collections found.

diff --git a/react_frontend/src/components/dialogs/CollectionEditDialog.tsx b/react_frontend/src/components/dialogs/CollectionEditDialog.tsx index 328067a..f7ea42c 100644 --- a/react_frontend/src/components/dialogs/CollectionEditDialog.tsx +++ b/react_frontend/src/components/dialogs/CollectionEditDialog.tsx @@ -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(null); const [posterFile, setPosterFile] = useState(null); const [backdropFile, setBackdropFile] = useState(null); const [posterPreview, setPosterPreview] = useState(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({
- - setUserRating(e.target.value)} - /> + +
+
+ {Array.from({ length: 10 }, (_, i) => i + 1).map((star) => { + const displayRating = hoveredStar ?? userRating; + return ( + + ); + })} +
+ + {userRating > 0 ? `${userRating}/10` : '—'} + +
{/* Media uploads */} diff --git a/react_frontend/src/components/entries/EntryCard.tsx b/react_frontend/src/components/entries/EntryCard.tsx index 35f6652..9b5a4d0 100644 --- a/react_frontend/src/components/entries/EntryCard.tsx +++ b/react_frontend/src/components/entries/EntryCard.tsx @@ -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) { )} + {/* Entry type pill */} + {showTypeBadge && tmdbEntry && ( + + {isTv ? 'TV Series' : 'Movie'} + + )} + {/* Hover overlay */}
diff --git a/react_frontend/src/components/layout/AppLayout.tsx b/react_frontend/src/components/layout/AppLayout.tsx index f089a2c..4efcc33 100644 --- a/react_frontend/src/components/layout/AppLayout.tsx +++ b/react_frontend/src/components/layout/AppLayout.tsx @@ -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(null); + const { pathname } = useLocation(); + + useEffect(() => { + mainRef.current?.scrollTo(0, 0); + }, [pathname]); return ( -
+
{/* Desktop sidebar */}
@@ -38,7 +44,7 @@ export function AppLayout() { -
+
diff --git a/react_frontend/src/components/layout/Sidebar.tsx b/react_frontend/src/components/layout/Sidebar.tsx index da7160a..7c6df9c 100644 --- a/react_frontend/src/components/layout/Sidebar.tsx +++ b/react_frontend/src/components/layout/Sidebar.tsx @@ -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 = [ diff --git a/react_frontend/src/hooks/useCollections.ts b/react_frontend/src/hooks/useCollections.ts index 859afc6..51cb177 100644 --- a/react_frontend/src/hooks/useCollections.ts +++ b/react_frontend/src/hooks/useCollections.ts @@ -38,3 +38,34 @@ export function useUpdateCollection() { }, }); } + +export function useDeleteCollection() { + const queryClient = useQueryClient(); + + return useMutation({ + mutationFn: (id: number) => collectionsApi.delete(id), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: collectionKeys.all }); + toast.success('Collection deleted'); + }, + onError: () => { + toast.error('Failed to delete collection'); + }, + }); +} + +export function useGetCollectionParts() { + const queryClient = useQueryClient(); + + return useMutation({ + mutationFn: (id: number) => collectionsApi.getCollectionParts(id), + onSuccess: (_data, id) => { + queryClient.invalidateQueries({ queryKey: collectionKeys.detail(id) }); + queryClient.invalidateQueries({ queryKey: collectionKeys.all }); + toast.success('Collection parts fetched'); + }, + onError: () => { + toast.error('Failed to fetch collection parts'); + }, + }); +} diff --git a/react_frontend/src/hooks/useDebounce.ts b/react_frontend/src/hooks/useDebounce.ts new file mode 100644 index 0000000..680704e --- /dev/null +++ b/react_frontend/src/hooks/useDebounce.ts @@ -0,0 +1,12 @@ +import { useState, useEffect } from 'react'; + +export function useDebounce(value: T, delay = 300): T { + const [debouncedValue, setDebouncedValue] = useState(value); + + useEffect(() => { + const timer = setTimeout(() => setDebouncedValue(value), delay); + return () => clearTimeout(timer); + }, [value, delay]); + + return debouncedValue; +} diff --git a/react_frontend/src/pages/CollectionDetailsPage.tsx b/react_frontend/src/pages/CollectionDetailsPage.tsx index 6a0775d..2819088 100644 --- a/react_frontend/src/pages/CollectionDetailsPage.tsx +++ b/react_frontend/src/pages/CollectionDetailsPage.tsx @@ -1,18 +1,30 @@ import { useState } from 'react'; -import { useParams } from 'react-router-dom'; -import { useCollection } from '@/hooks/useCollections'; +import { useParams, useNavigate } from 'react-router-dom'; +import { useCollection, useDeleteCollection, useGetCollectionParts } from '@/hooks/useCollections'; import { EntryLibraryGrid } from '@/components/entries/EntryLibraryGrid'; import { getCollectionPosterUrl } from '@/lib/media-utils'; import { getTmdbImageUrl } from '@/lib/api'; import { Skeleton } from '@/components/ui/skeleton'; import { Button } from '@/components/ui/button'; -import { Star, Pencil } from 'lucide-react'; +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuTrigger, +} from '@/components/ui/dropdown-menu'; +import { Star, MoreVertical, Pencil, Download, Trash2 } from 'lucide-react'; import { CollectionEditDialog } from '@/components/dialogs/CollectionEditDialog'; +import { ConfirmDialog } from '@/components/dialogs/ConfirmDialog'; +import { toast } from 'sonner'; export function CollectionDetailsPage() { const { id } = useParams<{ id: string }>(); - const { data: collection, isLoading } = useCollection(Number(id)); + const navigate = useNavigate(); + const { data: collection, isLoading, isError } = useCollection(Number(id)); const [showEditDialog, setShowEditDialog] = useState(false); + const [showDeleteConfirm, setShowDeleteConfirm] = useState(false); + const deleteCollection = useDeleteCollection(); + const getCollectionParts = useGetCollectionParts(); if (isLoading) { return ( @@ -28,12 +40,10 @@ export function CollectionDetailsPage() { ); } - if (!collection) { - return ( -
- Collection not found. -
- ); + if (!collection || isError) { + toast.error('Collection not found'); + navigate('/collections', { replace: true }); + return null; } const backdropUrl = collection.backdrop_path @@ -45,6 +55,16 @@ export function CollectionDetailsPage() { isInLibrary: true, })); + const handleDelete = () => { + deleteCollection.mutate(collection.id, { + onSuccess: () => navigate('/collections', { replace: true }), + }); + }; + + const handleGetParts = () => { + getCollectionParts.mutate(collection.id); + }; + return (
{/* Hero banner */} @@ -59,7 +79,36 @@ export function CollectionDetailsPage() {
)}
-
+ + {/* Quick action menu - top right */} +
+ + + + + + setShowEditDialog(true)}> + + Edit + + + + {getCollectionParts.isPending ? 'Fetching...' : 'Get All Parts'} + + setShowDeleteConfirm(true)} + > + + Delete + + + +
+ +
-
@@ -113,6 +153,17 @@ export function CollectionDetailsPage() { collection={collection} /> )} + + {/* Delete confirmation */} +
); } diff --git a/react_frontend/src/pages/CollectionsPage.tsx b/react_frontend/src/pages/CollectionsPage.tsx index 1419ae1..bab37ed 100644 --- a/react_frontend/src/pages/CollectionsPage.tsx +++ b/react_frontend/src/pages/CollectionsPage.tsx @@ -1,14 +1,19 @@ -import { useState, useMemo } from 'react'; +import { useState, useMemo, useCallback, useEffect } from 'react'; import { useCollections } from '@/hooks/useCollections'; +import { useDebounce } from '@/hooks/useDebounce'; import { CollectionsGrid } from '@/components/collections/CollectionsGrid'; import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs'; import { Input } from '@/components/ui/input'; import { Search } from 'lucide-react'; +const PAGE_SIZE = 24; + export function CollectionsPage() { const { data: collections = [], isLoading } = useCollections(); const [search, setSearch] = useState(''); + const debouncedSearch = useDebounce(search, 300); const [filter, setFilter] = useState<'all' | 'official' | 'custom'>('all'); + const [visibleCount, setVisibleCount] = useState(PAGE_SIZE); const filtered = useMemo(() => { let result = collections; @@ -19,13 +24,24 @@ export function CollectionsPage() { result = result.filter((c) => c.is_user_collection); } - if (search) { - const q = search.toLowerCase(); + if (debouncedSearch) { + const q = debouncedSearch.toLowerCase(); result = result.filter((c) => c.name.toLowerCase().includes(q)); } return result; - }, [collections, filter, search]); + }, [collections, filter, debouncedSearch]); + + useEffect(() => { + setVisibleCount(PAGE_SIZE); + }, [filter, debouncedSearch]); + + const paginatedCollections = useMemo( + () => filtered.slice(0, visibleCount), + [filtered, visibleCount] + ); + const hasMore = visibleCount < filtered.length; + const loadMore = useCallback(() => setVisibleCount((c) => c + PAGE_SIZE), []); return (
@@ -54,7 +70,7 @@ export function CollectionsPage() {
- +
); } diff --git a/react_frontend/src/pages/EntryDetailsPage.tsx b/react_frontend/src/pages/EntryDetailsPage.tsx index 4813430..c77d4f5 100644 --- a/react_frontend/src/pages/EntryDetailsPage.tsx +++ b/react_frontend/src/pages/EntryDetailsPage.tsx @@ -254,13 +254,13 @@ export function EntryDetailsPage() { <> • {watchHistory.length === 1 ? ( - seen {formatDate(watchHistory[0].date_seen)} + Seen {formatDate(watchHistory[0].date_seen)} ) : ( - seen {watchHistory.length} times + Seen {watchHistory.length} times @@ -353,7 +353,7 @@ export function EntryDetailsPage() { )} - {watchHistory.length > 0 && ( + {/* {watchHistory.length > 0 && ( <> - )} + )} */}
diff --git a/react_frontend/src/pages/HomePage.tsx b/react_frontend/src/pages/HomePage.tsx index 83e53a5..99c6d17 100644 --- a/react_frontend/src/pages/HomePage.tsx +++ b/react_frontend/src/pages/HomePage.tsx @@ -6,30 +6,18 @@ import { useTopRatedMovies, useTopRatedTv, useUpcomingMovies, - useTmdbSearch, } from '@/hooks/useTmdb'; import { useLibrary } from '@/hooks/useEntries'; import { TrendingGrid } from '@/components/entries/TrendingGrid'; import { TrendingSlider } from '@/components/entries/TrendingSlider'; import { Input } from '@/components/ui/input'; -import { useState, useEffect, useRef } from 'react'; import { Search } from 'lucide-react'; -import { EntryCard } from '@/components/entries/EntryCard'; +import { useNavigate } from 'react-router-dom'; +import { useState } from 'react'; export function HomePage() { + const navigate = useNavigate(); const [searchInput, setSearchInput] = useState(''); - const [debouncedQuery, setDebouncedQuery] = useState(''); - const debounceRef = useRef>(); - - useEffect(() => { - if (debounceRef.current) clearTimeout(debounceRef.current); - debounceRef.current = setTimeout(() => { - setDebouncedQuery(searchInput); - }, 400); - return () => { - if (debounceRef.current) clearTimeout(debounceRef.current); - }; - }, [searchInput]); // Pre-load library useLibrary(); @@ -41,7 +29,6 @@ export function HomePage() { const topRatedMovies = useTopRatedMovies(); const topRatedTv = useTopRatedTv(); const upcomingMovies = useUpcomingMovies(); - const searchResults = useTmdbSearch(debouncedQuery); const trendingMovieEntries = trendingMovies.data?.pages.flatMap((p) => p.results) ?? []; const trendingTvEntries = trendingTv.data?.pages.flatMap((p) => p.results) ?? []; @@ -50,87 +37,67 @@ export function HomePage() { const topRatedMovieEntries = topRatedMovies.data?.pages.flatMap((p) => p.results) ?? []; const topRatedTvEntries = topRatedTv.data?.pages.flatMap((p) => p.results) ?? []; const upcomingMovieEntries = upcomingMovies.data?.pages.flatMap((p) => p.results) ?? []; - const searchEntries = searchResults.data?.pages.flatMap((p) => p.results) ?? []; - const isSearching = debouncedQuery.length > 0; + const handleSearchSubmit = () => { + const q = searchInput.trim(); + if (q) { + navigate(`/search?q=${encodeURIComponent(q)}`); + } + }; return (
{/* Trending Slider Hero */} - {!isSearching && ( - - )} + {/* Search */}
setSearchInput(e.target.value)} + onKeyDown={(e) => { + if (e.key === 'Enter') handleSearchSubmit(); + }} className="pl-10" />
- {isSearching ? ( -
-

- Search Results for "{debouncedQuery}" -

- {searchEntries.length === 0 && !searchResults.isLoading ? ( -

No results found.

- ) : ( -
- {searchEntries.map((entry, index) => ( -
- -
- ))} -
- )} -
- ) : ( - <> - + - + - + - - - )} +
); } diff --git a/react_frontend/src/pages/LibraryPage.tsx b/react_frontend/src/pages/LibraryPage.tsx index e9ec703..3dd0473 100644 --- a/react_frontend/src/pages/LibraryPage.tsx +++ b/react_frontend/src/pages/LibraryPage.tsx @@ -18,13 +18,15 @@ type SortDir = 'asc' | 'desc'; interface Filters { genre: string; - ratingMin: string; - ratingMax: string; + tmdbRatingMin: string; + tmdbRatingMax: string; + userRatingMin: string; + userRatingMax: string; yearMin: string; yearMax: string; } -const defaultFilters: Filters = { genre: '', ratingMin: '', ratingMax: '', yearMin: '', yearMax: '' }; +const defaultFilters: Filters = { genre: '', tmdbRatingMin: '', tmdbRatingMax: '', userRatingMin: '', userRatingMax: '', yearMin: '', yearMax: '' }; const sortLabels: Record = { date_last_seen: 'Last Watched', @@ -84,7 +86,7 @@ export function LibraryPage() { const ratingMin = searchParams.get('ratingMin') || ''; const ratingMax = searchParams.get('ratingMax') || ''; if (genre || ratingMin || ratingMax) { - const newFilters = { ...defaultFilters, genre, ratingMin, ratingMax }; + const newFilters = { ...defaultFilters, genre, userRatingMin: ratingMin, userRatingMax: ratingMax }; setFilters(newFilters); setDebouncedFilters(newFilters); // Clear URL params after applying @@ -116,7 +118,7 @@ export function LibraryPage() { return Array.from(set).sort(); }, [allEntries]); - const hasActiveFilters = filters.genre || filters.ratingMin || filters.ratingMax || filters.yearMin || filters.yearMax; + const hasActiveFilters = filters.genre || filters.tmdbRatingMin || filters.tmdbRatingMax || filters.userRatingMin || filters.userRatingMax || filters.yearMin || filters.yearMax; const baseEntries = useMemo(() => { switch (activeTab) { @@ -144,12 +146,20 @@ export function LibraryPage() { if (debouncedFilters.genre) { result = result.filter((e) => e.genres?.some((g) => g.name === debouncedFilters.genre)); } - if (debouncedFilters.ratingMin) { - const min = parseFloat(debouncedFilters.ratingMin); + if (debouncedFilters.tmdbRatingMin) { + const min = parseFloat(debouncedFilters.tmdbRatingMin); + result = result.filter((e) => (e.entryRatings?.tmdb_rating ?? 0) >= min); + } + if (debouncedFilters.tmdbRatingMax) { + const max = parseFloat(debouncedFilters.tmdbRatingMax); + result = result.filter((e) => (e.entryRatings?.tmdb_rating ?? 0) <= max); + } + if (debouncedFilters.userRatingMin) { + const min = parseFloat(debouncedFilters.userRatingMin); result = result.filter((e) => (e.entryRatings?.user_rating ?? 0) >= min); } - if (debouncedFilters.ratingMax) { - const max = parseFloat(debouncedFilters.ratingMax); + if (debouncedFilters.userRatingMax) { + const max = parseFloat(debouncedFilters.userRatingMax); result = result.filter((e) => (e.entryRatings?.user_rating ?? 0) <= max); } if (debouncedFilters.yearMin) { @@ -260,7 +270,7 @@ export function LibraryPage() { -
+
-
- +
+
- setFilters((f) => ({ ...f, ratingMin: e.target.value }))} className="h-9" /> + setFilters((f) => ({ ...f, tmdbRatingMin: e.target.value }))} className="h-9" /> – - setFilters((f) => ({ ...f, ratingMax: e.target.value }))} className="h-9" /> + setFilters((f) => ({ ...f, tmdbRatingMax: e.target.value }))} className="h-9" />
-
+
+ +
+ setFilters((f) => ({ ...f, userRatingMin: e.target.value }))} className="h-9" /> + – + setFilters((f) => ({ ...f, userRatingMax: e.target.value }))} className="h-9" /> +
+
+
setFilters((f) => ({ ...f, yearMin: e.target.value }))} className="h-9" /> @@ -371,22 +389,30 @@ export function LibraryPage() { -
+
- setFilters((f) => ({ ...f, genre: v === '_all' ? '' : (v || '') }))}> + All genres {allGenres.map((g) => {g})}
-
- +
+
- setFilters((f) => ({ ...f, ratingMin: e.target.value }))} className="h-9" /> + setFilters((f) => ({ ...f, tmdbRatingMin: e.target.value }))} className="h-9" /> – - setFilters((f) => ({ ...f, ratingMax: e.target.value }))} className="h-9" /> + setFilters((f) => ({ ...f, tmdbRatingMax: e.target.value }))} className="h-9" /> +
+
+
+ +
+ setFilters((f) => ({ ...f, userRatingMin: e.target.value }))} className="h-9" /> + – + setFilters((f) => ({ ...f, userRatingMax: e.target.value }))} className="h-9" />
diff --git a/react_frontend/src/pages/MediaPage.tsx b/react_frontend/src/pages/MediaPage.tsx index 9d9772d..2c31a7d 100644 --- a/react_frontend/src/pages/MediaPage.tsx +++ b/react_frontend/src/pages/MediaPage.tsx @@ -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(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 (

Media

+
+ + setSearch(e.target.value)} + className="pl-10" + /> +
+ +
+ + setCustomFilter(v as typeof customFilter)} + > + + All + Custom + Official + + + setMediaType(v as typeof mediaType)} @@ -56,16 +121,6 @@ export function MediaPage() { Logos - -
- - setSearch(e.target.value)} - className="pl-10" - /> -
{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) => (
-
- -
- - +
+ +
+ +
@@ -39,16 +39,16 @@ export function PersonDetailsPage() { return (
-
- +
+ - + {person.name.split(' ').map((n: string) => n[0]).join('')} -
-

{person.name}

-
+
+

{person.name}

+
{person.known_for_department && {person.known_for_department}} {person.birthday && (<>•Born: {formatDate(person.birthday)})} {person.deathday && (<>•Died: {formatDate(person.deathday)})} @@ -85,7 +85,7 @@ function FilmographySection({ libraryMap, libraryLoaded, tmdbFilmography, tmdbLo const [libraryPage, setLibraryPage] = useState(0); const [otherPage, setOtherPage] = useState(0); const PAGE_SIZE = 6; // 6 cols × 1 row - const GRID = 'grid grid-cols-3 gap-3 sm:grid-cols-4 md:grid-cols-5 lg:grid-cols-6'; + const GRID = 'grid grid-cols-2 gap-3 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6'; if (tmdbLoading || !libraryLoaded) { return ( @@ -121,7 +121,25 @@ function FilmographySection({ libraryMap, libraryLoaded, tmdbFilmography, tmdbLo // Sort by popularity descending const sorted = [...dedupedCredits].sort((a, b) => (b.popularity ?? 0) - (a.popularity ?? 0)); const libraryCredits = sorted.filter((c) => tmdbIdToLibraryEntry.has(c.id)); - const otherCredits = sorted.filter((c) => !tmdbIdToLibraryEntry.has(c.id)); + + // "Not in library": sort by release date (new→old), push "self" roles to the end + const isSelfRole = (character?: string) => { + if (!character) return false; + const lower = character.toLowerCase().trim(); + return lower === 'self' || lower.startsWith('self -') || lower.startsWith('self (') || lower === 'themselves' || lower === 'himself' || lower === 'herself'; + }; + const otherCreditsSorted = sorted + .filter((c) => !tmdbIdToLibraryEntry.has(c.id)) + .sort((a, b) => { + const aSelf = isSelfRole(a.character) ? 1 : 0; + const bSelf = isSelfRole(b.character) ? 1 : 0; + if (aSelf !== bSelf) return aSelf - bSelf; + // Both same self status → sort by date descending (new first) + const dateA = new Date(a.release_date || a.first_air_date || '1900').getTime(); + const dateB = new Date(b.release_date || b.first_air_date || '1900').getTime(); + return dateB - dateA; + }); + const otherCredits = otherCreditsSorted; if (sorted.length === 0) { return ( diff --git a/react_frontend/src/pages/SearchPage.tsx b/react_frontend/src/pages/SearchPage.tsx new file mode 100644 index 0000000..fff03e5 --- /dev/null +++ b/react_frontend/src/pages/SearchPage.tsx @@ -0,0 +1,120 @@ +import { useState, useEffect, useRef } from 'react'; +import { useSearchParams, Link } from 'react-router-dom'; +import { useTmdbSearch, useTmdbSearchPeople } from '@/hooks/useTmdb'; +import { useLibrary } from '@/hooks/useEntries'; +import { Input } from '@/components/ui/input'; +import { Search } from 'lucide-react'; +import { EntryCard } from '@/components/entries/EntryCard'; +import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'; +import { getTmdbImageUrl } from '@/lib/api'; + +export function SearchPage() { + const [searchParams, setSearchParams] = useSearchParams(); + const initialQuery = searchParams.get('q') || ''; + const [searchInput, setSearchInput] = useState(initialQuery); + const [debouncedQuery, setDebouncedQuery] = useState(initialQuery); + const debounceRef = useRef>(); + + useEffect(() => { + if (debounceRef.current) clearTimeout(debounceRef.current); + debounceRef.current = setTimeout(() => { + setDebouncedQuery(searchInput); + }, 400); + return () => { + if (debounceRef.current) clearTimeout(debounceRef.current); + }; + }, [searchInput]); + + // Sync debounced query to URL + useEffect(() => { + if (debouncedQuery) { + setSearchParams({ q: debouncedQuery }, { replace: true }); + } else { + setSearchParams({}, { replace: true }); + } + }, [debouncedQuery, setSearchParams]); + + useLibrary(); + + const searchResults = useTmdbSearch(debouncedQuery); + const peopleResults = useTmdbSearchPeople(debouncedQuery); + + const searchEntries = searchResults.data?.pages.flatMap((p) => p.results) ?? []; + const searchPeople = peopleResults.data?.pages.flatMap((p) => p.results) ?? []; + + const isSearching = debouncedQuery.length > 0; + + return ( +
+ {/* Search */} +
+ + setSearchInput(e.target.value)} + className="pl-10" + autoFocus + /> +
+ + {isSearching ? ( +
+ {/* People results */} + {searchPeople.length > 0 && ( +
+

People

+
+ {searchPeople.slice(0, 10).map((person) => ( + + + + + {person.name.split(' ').map((n) => n[0]).join('').slice(0, 2)} + + + {person.name} + {person.known_for_department && ( + {person.known_for_department} + )} + + ))} +
+
+ )} + + {/* Entry results */} +

+ Search Results for “{debouncedQuery}” +

+ {searchEntries.length === 0 && !searchResults.isLoading ? ( +

No results found.

+ ) : ( +
+ {searchEntries.map((entry, index) => ( +
+ +
+ ))} +
+ )} +
+ ) : ( +
+ Start typing to search... +
+ )} +
+ ); +} diff --git a/react_frontend/src/pages/WatchlistPage.tsx b/react_frontend/src/pages/WatchlistPage.tsx index a8b2213..1373d03 100644 --- a/react_frontend/src/pages/WatchlistPage.tsx +++ b/react_frontend/src/pages/WatchlistPage.tsx @@ -1,17 +1,20 @@ -import { useState, useMemo, useCallback } from 'react'; +import { useState, useMemo, useCallback, useEffect } from 'react'; import { useLibrary } from '@/hooks/useEntries'; import { useLibraryEntries } from '@/stores/useLibraryStore'; +import { useDebounce } from '@/hooks/useDebounce'; import { EntryLibraryGrid } from '@/components/entries/EntryLibraryGrid'; import { Input } from '@/components/ui/input'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; +import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs'; import { Search, SlidersHorizontal, ArrowUpDown } from 'lucide-react'; import type { Entry } from '@/types'; type SortField = 'createdAt' | 'date_last_seen' | 'title' | 'release_date' | 'rating'; type SortDir = 'asc' | 'desc'; +type TypeFilter = 'all' | 'movies' | 'tv'; interface Filters { genre: string; @@ -56,12 +59,17 @@ function sortEntries(entries: Entry[], field: SortField, dir: SortDir): Entry[] }); } +const PAGE_SIZE = 28; + export function WatchlistPage() { const { isLoading } = useLibrary(); const [search, setSearch] = useState(''); + const debouncedSearch = useDebounce(search, 300); const [sortField, setSortField] = useState('createdAt'); const [sortDir, setSortDir] = useState('desc'); const [filters, setFilters] = useState(defaultFilters); + const [typeFilter, setTypeFilter] = useState('all'); + const [visibleCount, setVisibleCount] = useState(PAGE_SIZE); const allEntries = useLibraryEntries(); const watchlist = useMemo(() => allEntries.filter((e) => e.watchlist), [allEntries]); @@ -76,8 +84,14 @@ export function WatchlistPage() { const filtered = useMemo(() => { let result = watchlist; - if (search) { - const q = search.toLowerCase(); + if (typeFilter === 'movies') { + result = result.filter((e) => !e.is_tvseries); + } else if (typeFilter === 'tv') { + result = result.filter((e) => e.is_tvseries); + } + + if (debouncedSearch) { + const q = debouncedSearch.toLowerCase(); result = result.filter((e) => e.title.toLowerCase().includes(q)); } @@ -102,7 +116,19 @@ export function WatchlistPage() { } return sortEntries(result, sortField, sortDir); - }, [watchlist, search, filters, sortField, sortDir]); + }, [watchlist, debouncedSearch, filters, sortField, sortDir, typeFilter]); + + // Reset visible count when filters change + useEffect(() => { + setVisibleCount(PAGE_SIZE); + }, [debouncedSearch, filters, sortField, sortDir, typeFilter]); + + const paginatedEntries = useMemo( + () => filtered.slice(0, visibleCount), + [filtered, visibleCount] + ); + const hasMore = visibleCount < filtered.length; + const loadMore = useCallback(() => setVisibleCount((c) => c + PAGE_SIZE), []); const clearFilters = useCallback(() => setFilters(defaultFilters), []); @@ -201,6 +227,17 @@ export function WatchlistPage() {
+ + {/* Row 2: type filter tabs */} +
+ setTypeFilter(v as TypeFilter)}> + + All + Movies + TV Series + + +
{/* ── Desktop controls (≥ md) ── */} @@ -284,7 +321,7 @@ export function WatchlistPage() {
setFilters((f) => ({ ...f, yearMin: e.target.value }))} className="h-9" /> – - setFilters((f) => ({ ...f, yearMax: e.target.value }))} + setFilters((f) => ({ ...f, ratingMax: e.target.value }))} className="h-9" />
@@ -296,9 +333,18 @@ export function WatchlistPage() { )} + + {/* Type filter */} + setTypeFilter(v as TypeFilter)}> + + All + Movies + TV Series + +
- +
); } diff --git a/react_frontend/src/router.tsx b/react_frontend/src/router.tsx index 5e5a67d..356f8f9 100644 --- a/react_frontend/src/router.tsx +++ b/react_frontend/src/router.tsx @@ -77,6 +77,9 @@ const SettingsPage = lazy(() => const DiscoverPage = lazy(() => import('@/pages/DiscoverPage').then((m) => ({ default: m.DiscoverPage })) ); +const SearchPage = lazy(() => + import('@/pages/SearchPage').then((m) => ({ default: m.SearchPage })) +); function SuspensePage({ children, fallback }: { children: ReactNode; fallback?: ReactNode }) { return }>{children}; @@ -94,6 +97,14 @@ export const router = createBrowserRouter([ ), }, + { + path: '/search', + element: ( + }> + + + ), + }, { path: '/dashboard', element: (