Implemented the new react version of the frontend

This commit is contained in:
Mohammed Abad committed 2026-03-31 01:56:38 +01:00
1 parent 236e6e06fb
commit ffe7e52527
65 files changed
+5228 -177

No files matched your search

+139
View File
@@ -0,0 +1,139 @@
import { useState, useMemo } from 'react';
import { format, startOfMonth, endOfMonth, eachDayOfInterval, getDay, addMonths, subMonths, isSameDay } from 'date-fns';
import { ChevronLeft, ChevronRight } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { useEpisodesByMonth } from '@/hooks/useEpisodes';
import { getTmdbPosterUrl } from '@/lib/media-utils';
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
const DAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
export function CalendarPage() {
const [currentDate, setCurrentDate] = useState(new Date());
const monthStart = startOfMonth(currentDate);
const monthEnd = endOfMonth(currentDate);
const startDateStr = format(monthStart, 'yyyy-MM-dd');
const endDateStr = format(monthEnd, 'yyyy-MM-dd');
const { data: episodes = [] } = useEpisodesByMonth(startDateStr, endDateStr);
const days = useMemo(() => eachDayOfInterval({ start: monthStart, end: monthEnd }), [monthStart, monthEnd]);
const startDayOfWeek = getDay(monthStart);
// Group episodes by date
const episodesByDate = useMemo(() => {
const map = new Map<string, typeof episodes>();
episodes.forEach((ep) => {
if (!ep.air_date) return;
const key = format(new Date(ep.air_date), 'yyyy-MM-dd');
const existing = map.get(key) || [];
existing.push(ep);
map.set(key, existing);
});
return map;
}, [episodes]);
return (
<div className="space-y-6">
<div className="flex items-center justify-between">
<h1 className="text-2xl font-bold">Calendar</h1>
<div className="flex items-center gap-2">
<Button
variant="outline"
size="icon"
onClick={() => setCurrentDate(subMonths(currentDate, 1))}
>
<ChevronLeft className="h-4 w-4" />
</Button>
<span className="min-w-[140px] text-center font-medium">
{format(currentDate, 'MMMM yyyy')}
</span>
<Button
variant="outline"
size="icon"
onClick={() => setCurrentDate(addMonths(currentDate, 1))}
>
<ChevronRight className="h-4 w-4" />
</Button>
</div>
</div>
{/* Calendar Grid */}
<div className="rounded-lg border border-border overflow-hidden">
{/* Day headers */}
<div className="grid grid-cols-7 bg-muted/50">
{DAYS.map((day) => (
<div key={day} className="px-2 py-2 text-center text-xs font-medium text-muted-foreground">
{day}
</div>
))}
</div>
{/* Day cells */}
<div className="grid grid-cols-7">
{/* Empty cells for offset */}
{Array.from({ length: startDayOfWeek }).map((_, i) => (
<div key={`empty-${i}`} className="min-h-24 border-t border-r border-border bg-muted/20" />
))}
{days.map((day) => {
const key = format(day, 'yyyy-MM-dd');
const dayEpisodes = episodesByDate.get(key) || [];
const isToday = isSameDay(day, new Date());
return (
<div
key={key}
className={`min-h-24 border-t border-r border-border p-1 ${
isToday ? 'bg-primary/5' : ''
}`}
>
<span
className={`inline-flex h-6 w-6 items-center justify-center rounded-full text-xs ${
isToday
? 'bg-primary text-primary-foreground font-bold'
: 'text-muted-foreground'
}`}
>
{format(day, 'd')}
</span>
<div className="mt-1 space-y-0.5">
{dayEpisodes.slice(0, 3).map((ep) => (
<Tooltip key={ep.id}>
<TooltipTrigger asChild>
<div className="flex items-center gap-1 rounded bg-accent/50 px-1 py-0.5">
{ep.still_path && (
<img
src={getTmdbPosterUrl(ep.still_path, 'w92')}
alt=""
className="h-4 w-6 rounded object-cover"
/>
)}
<span className="text-[10px] truncate">
S{ep.season_id} E{ep.episode_number}
</span>
</div>
</TooltipTrigger>
<TooltipContent>
<p className="text-xs font-medium">{ep.name}</p>
<p className="text-xs text-muted-foreground">
Episode {ep.episode_number}
</p>
</TooltipContent>
</Tooltip>
))}
{dayEpisodes.length > 3 && (
<span className="text-[10px] text-muted-foreground pl-1">
+{dayEpisodes.length - 3} more
</span>
)}
</div>
</div>
);
})}
</div>
</div>
</div>
);
}
@@ -0,0 +1,118 @@
import { useState } from 'react';
import { useParams } from 'react-router-dom';
import { useCollection } 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 { CollectionEditDialog } from '@/components/dialogs/CollectionEditDialog';
export function CollectionDetailsPage() {
const { id } = useParams<{ id: string }>();
const { data: collection, isLoading } = useCollection(Number(id));
const [showEditDialog, setShowEditDialog] = useState(false);
if (isLoading) {
return (
<div className="space-y-6">
<Skeleton className="h-48 w-full rounded-xl" />
<Skeleton className="h-8 w-64" />
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6">
{Array.from({ length: 6 }).map((_, i) => (
<Skeleton key={i} className="aspect-[2/3] w-full rounded-lg" />
))}
</div>
</div>
);
}
if (!collection) {
return (
<div className="flex h-40 items-center justify-center text-muted-foreground">
Collection not found.
</div>
);
}
const backdropUrl = collection.backdrop_path
? getTmdbImageUrl(collection.backdrop_path, 'w1280')
: null;
const entries = (collection.entries || []).map((e) => ({
...e,
isInLibrary: true,
}));
return (
<div className="space-y-6">
{/* Hero banner */}
<div className="relative overflow-hidden rounded-xl">
{backdropUrl ? (
<img
src={backdropUrl}
alt={collection.name}
className="h-48 w-full object-cover sm:h-64"
/>
) : (
<div className="h-48 w-full bg-muted sm:h-64" />
)}
<div className="absolute inset-0 bg-gradient-to-t from-background via-background/60 to-transparent" />
<div className="absolute bottom-0 left-0 right-0 flex items-end justify-between p-6">
<div className="flex items-end gap-4">
<img
src={getCollectionPosterUrl(collection)}
alt={collection.name}
className="h-32 w-auto rounded-lg shadow-lg sm:h-40"
/>
<div className="space-y-1">
<h1 className="text-2xl font-bold text-white sm:text-3xl">
{collection.name}
</h1>
{collection.description && (
<p className="max-w-xl text-sm text-white/80 line-clamp-3">
{collection.description}
</p>
)}
<div className="flex items-center gap-3">
<p className="text-sm text-white/60">
{entries.length} {entries.length === 1 ? 'entry' : 'entries'}
</p>
{collection.user_rating != null && collection.user_rating > 0 && (
<div className="flex items-center gap-1">
<Star className="h-4 w-4 fill-yellow-400 text-yellow-400" />
<span className="text-sm font-medium text-white">
{collection.user_rating}/10
</span>
</div>
)}
</div>
</div>
</div>
<Button
variant="secondary"
size="sm"
className="shrink-0"
onClick={() => setShowEditDialog(true)}
>
<Pencil className="mr-1 h-4 w-4" />
Edit
</Button>
</div>
</div>
{/* Entries grid */}
<EntryLibraryGrid entries={entries} isLoading={false} />
{/* Edit dialog */}
{showEditDialog && (
<CollectionEditDialog
open={showEditDialog}
onOpenChange={setShowEditDialog}
collection={collection}
/>
)}
</div>
);
}
@@ -0,0 +1,60 @@
import { useState, useMemo } from 'react';
import { useCollections } from '@/hooks/useCollections';
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';
export function CollectionsPage() {
const { data: collections = [], isLoading } = useCollections();
const [search, setSearch] = useState('');
const [filter, setFilter] = useState<'all' | 'official' | 'custom'>('all');
const filtered = useMemo(() => {
let result = collections;
if (filter === 'official') {
result = result.filter((c) => !c.is_user_collection);
} else if (filter === 'custom') {
result = result.filter((c) => c.is_user_collection);
}
if (search) {
const q = search.toLowerCase();
result = result.filter((c) => c.name.toLowerCase().includes(q));
}
return result;
}, [collections, filter, search]);
return (
<div className="space-y-6">
<h1 className="text-2xl font-bold">Collections</h1>
<div className="flex flex-wrap items-center gap-3">
<Tabs
value={filter}
onValueChange={(v) => setFilter(v as 'all' | 'official' | 'custom')}
>
<TabsList>
<TabsTrigger value="all">All</TabsTrigger>
<TabsTrigger value="official">Official</TabsTrigger>
<TabsTrigger value="custom">Custom</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 collections..."
value={search}
onChange={(e) => setSearch(e.target.value)}
className="pl-10"
/>
</div>
</div>
<CollectionsGrid collections={filtered} isLoading={isLoading} />
</div>
);
}
+114
View File
@@ -0,0 +1,114 @@
import { useMemo } from 'react';
import { Link } from 'react-router-dom';
import { useLibrary } from '@/hooks/useEntries';
import { useStatistics } from '@/hooks/useStatistics';
import { useLibraryEntries } from '@/stores/useLibraryStore';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Skeleton } from '@/components/ui/skeleton';
import { Film, Tv, Heart, ListVideo, Clock } from 'lucide-react';
import { formatRuntime, getPosterUrl } from '@/lib/media-utils';
export function DashboardPage() {
useLibrary();
const { data: stats, isLoading: statsLoading } = useStatistics();
const allEntries = useLibraryEntries();
const movies = useMemo(() => allEntries.filter((e) => !e.is_tvseries && !e.watchlist), [allEntries]);
const tvSeries = useMemo(() => allEntries.filter((e) => e.is_tvseries && !e.watchlist), [allEntries]);
const favorites = useMemo(() => allEntries.filter((e) => e.favorit && !e.watchlist), [allEntries]);
const watchlist = useMemo(() => allEntries.filter((e) => e.watchlist), [allEntries]);
const statCards = [
{
title: 'Movies',
value: movies.length,
icon: Film,
color: 'text-blue-500',
},
{
title: 'TV Series',
value: tvSeries.length,
icon: Tv,
color: 'text-green-500',
},
{
title: 'Favorites',
value: favorites.length,
icon: Heart,
color: 'text-red-500',
},
{
title: 'Watchlist',
value: watchlist.length,
icon: ListVideo,
color: 'text-purple-500',
},
{
title: 'Watch Time',
value: stats?.totalWatchTime
? formatRuntime(stats.totalWatchTime)
: '0h',
icon: Clock,
color: 'text-orange-500',
},
];
return (
<div className="space-y-8">
<h1 className="text-2xl font-bold">Dashboard</h1>
{/* Stats Grid */}
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-5">
{statCards.map((stat) => (
<Card key={stat.title}>
<CardHeader className="flex flex-row items-center justify-between pb-2">
<CardTitle className="text-sm font-medium text-muted-foreground">
{stat.title}
</CardTitle>
<stat.icon className={`h-5 w-5 ${stat.color}`} />
</CardHeader>
<CardContent>
{statsLoading ? (
<Skeleton className="h-8 w-16" />
) : (
<p className="text-2xl font-bold">{stat.value}</p>
)}
</CardContent>
</Card>
))}
</div>
{/* Recently Watched */}
<div className="space-y-4">
<h2 className="text-lg font-semibold">Recently Watched</h2>
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 2xl:grid-cols-7">
{allEntries
.filter((e) => e.date_last_seen)
.sort(
(a, b) =>
new Date(b.date_last_seen!).getTime() -
new Date(a.date_last_seen!).getTime()
)
.slice(0, 14)
.map((entry) => (
<Link
key={entry.id}
to={`/entry/${entry.id}`}
className="group transition-transform hover:scale-[1.02]"
>
<img
src={getPosterUrl(entry)}
alt={entry.title}
className="aspect-[2/3] w-full rounded-lg object-cover"
loading="lazy"
/>
<p className="mt-1 text-xs font-medium truncate">
{entry.title}
</p>
</Link>
))}
</div>
</div>
</div>
);
}
@@ -0,0 +1,354 @@
import { useState } from 'react';
import { useParams } from 'react-router-dom';
import { useEntry, useEntrySeasons, useRefreshEntry } from '@/hooks/useEntries';
import { useEntrySeenByEntry, useDeleteEntrySeen } from '@/hooks/useEntrySeen';
import { useLibraryStore } from '@/stores/useLibraryStore';
import { Skeleton } from '@/components/ui/skeleton';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import { Separator } from '@/components/ui/separator';
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
import {
Heart,
MoreHorizontal,
Eye,
EyeOff,
RefreshCw,
FolderPlus,
ImageIcon,
Settings,
Star,
} from 'lucide-react';
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from '@/components/ui/tooltip';
import { CastList } from '@/components/entries/CastList';
import { SeasonsContainer } from '@/components/entries/SeasonsContainer';
import { EpisodeWatchHistory } from '@/components/entries/EpisodeWatchHistory';
import { CollectionsGrid } from '@/components/collections/CollectionsGrid';
import { EntrySettingsDialog } from '@/components/dialogs/EntrySettingsDialog';
import { EntrySeenDialog } from '@/components/dialogs/EntrySeenDialog';
import { EntryMediaDialog } from '@/components/dialogs/EntryMediaDialog';
import { AddEntryToCollectionDialog } from '@/components/dialogs/AddEntryToCollectionDialog';
import {
getPosterUrl,
getBackdropUrl,
getYear,
formatRuntime,
formatDate,
} from '@/lib/media-utils';
import { useUpdateEntry } from '@/hooks/useEntries';
import type { Entry } from '@/types';
export function EntryDetailsPage() {
const { id } = useParams<{ id: string }>();
const entryId = parseInt(id!, 10);
const { data: entry, isLoading } = useEntry(entryId);
const { data: seasons } = useEntrySeasons(entryId);
const { data: watchHistory = [] } = useEntrySeenByEntry(entryId);
const updateEntry = useUpdateEntry();
const refreshEntry = useRefreshEntry();
const deleteEntrySeen = useDeleteEntrySeen();
// Merge library entry with detail entry so we get both library flags AND full details (credits, etc.)
const libraryEntry = useLibraryStore((s) => s.entries.get(entryId));
const displayEntry = libraryEntry && entry
? { ...libraryEntry, ...entry, isInLibrary: true }
: entry || libraryEntry;
// Dialog states
const [showSettings, setShowSettings] = useState(false);
const [showSeenDialog, setShowSeenDialog] = useState(false);
const [showMediaDialog, setShowMediaDialog] = useState(false);
const [showCollectionDialog, setShowCollectionDialog] = useState(false);
if (isLoading || !displayEntry) {
return <EntryDetailsSkeleton />;
}
const e = displayEntry;
const backdrop = getBackdropUrl(e);
const poster = getPosterUrl(e);
const director = e.credits?.find(
(c) => c.cast_type === 'crew' && c.job === 'Director'
);
const toggleFavorite = () => {
updateEntry.mutate({ id: e.id, data: { favorit: !e.favorit } });
};
return (
<div className="space-y-8">
{/* Hero Section */}
<div className="relative -mx-6 -mt-6 overflow-hidden">
{backdrop && (
<img
src={backdrop}
alt=""
className="h-72 w-full object-cover opacity-30 blur-sm"
/>
)}
<div className="absolute inset-0 bg-gradient-to-t from-background to-transparent" />
<div className="relative mx-auto flex max-w-5xl gap-6 px-6 pb-6 pt-4">
{/* Poster */}
<div className="shrink-0">
<img
src={poster}
alt={e.title}
className="h-72 w-48 rounded-lg object-cover shadow-lg"
/>
</div>
{/* Info */}
<div className="flex flex-1 flex-col justify-end space-y-3">
<div className="flex items-center gap-3">
<h1 className="text-3xl font-bold">{e.title}</h1>
{e.status && (
<Badge variant="secondary">{e.status}</Badge>
)}
</div>
<div className="flex flex-wrap items-center gap-2 text-sm text-muted-foreground">
{e.release_date && (
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<span className="cursor-default underline decoration-dotted">
{getYear(e.release_date)}
</span>
</TooltipTrigger>
<TooltipContent>
<p>{formatDate(e.release_date)}</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
)}
{e.runtime && !e.is_tvseries && (
<>
<span>•</span>
<span>{formatRuntime(e.runtime)}</span>
</>
)}
{director && (
<>
<span>•</span>
<span>Dir. {director.people?.name}</span>
</>
)}
</div>
{/* Genres */}
{e.genres && e.genres.length > 0 && (
<div className="flex flex-wrap gap-1.5">
{e.genres.map((g) => (
<Badge key={g.id} variant="outline" className="text-xs">
{g.name}
</Badge>
))}
</div>
)}
{/* Ratings */}
<div className="flex items-center gap-4">
{e.entryRatings?.user_rating != null &&
e.entryRatings.user_rating > 0 && (
<div className="flex items-center gap-1">
<Star className="h-4 w-4 fill-yellow-400 text-yellow-400" />
<span className="text-sm font-medium">
{e.entryRatings.user_rating}/10
</span>
<span className="text-xs text-muted-foreground">You</span>
</div>
)}
{e.entryRatings?.tmdb_rating != null &&
e.entryRatings.tmdb_rating > 0 && (
<div className="flex items-center gap-1">
<span className="text-sm font-medium">
{e.entryRatings.tmdb_rating.toFixed(1)}
</span>
<span className="text-xs text-muted-foreground">TMDB</span>
</div>
)}
{e.entryRatings?.imdb_rating != null &&
e.entryRatings.imdb_rating > 0 && (
<div className="flex items-center gap-1">
<span className="text-sm font-medium">
{e.entryRatings.imdb_rating}
</span>
<span className="text-xs text-muted-foreground">IMDb</span>
</div>
)}
</div>
{/* Actions */}
<div className="flex items-center gap-2 pt-2">
<Button
variant={e.favorit ? 'default' : 'outline'}
size="sm"
onClick={toggleFavorite}
>
<Heart
className={`mr-1 h-4 w-4 ${
e.favorit ? 'fill-current' : ''
}`}
/>
{e.favorit ? 'Favorited' : 'Favorite'}
</Button>
<Button
variant="outline"
size="sm"
onClick={() => setShowSeenDialog(true)}
>
<Eye className="mr-1 h-4 w-4" />
Mark Watched
</Button>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="outline" size="icon" className="h-8 w-8">
<MoreHorizontal className="h-4 w-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem
onClick={() =>
updateEntry.mutate({
id: e.id,
data: { hidden: !e.hidden },
})
}
>
<EyeOff className="mr-2 h-4 w-4" />
{e.hidden ? 'Unhide' : 'Hide'}
</DropdownMenuItem>
<DropdownMenuItem
onClick={() => refreshEntry.mutate(e.id)}
>
<RefreshCw className="mr-2 h-4 w-4" />
Refresh Details
</DropdownMenuItem>
<DropdownMenuItem
onClick={() => setShowCollectionDialog(true)}
>
<FolderPlus className="mr-2 h-4 w-4" />
Add to Collection
</DropdownMenuItem>
<DropdownMenuItem
onClick={() => setShowMediaDialog(true)}
>
<ImageIcon className="mr-2 h-4 w-4" />
Media
</DropdownMenuItem>
<DropdownMenuItem
onClick={() => setShowSettings(true)}
>
<Settings className="mr-2 h-4 w-4" />
Settings
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
</div>
</div>
</div>
{/* Storyline */}
{e.storyline && (
<div className="space-y-2">
<h3 className="text-lg font-semibold">Overview</h3>
<p className="text-sm text-muted-foreground leading-relaxed">
{e.storyline}
</p>
</div>
)}
<Separator />
{/* Cast */}
{e.credits && e.credits.length > 0 && <CastList credits={e.credits} />}
{/* Seasons (TV only) */}
{e.is_tvseries && seasons && seasons.length > 0 && (
<>
<Separator />
<SeasonsContainer seasons={seasons} entryId={e.id} />
</>
)}
{/* Watch History */}
{watchHistory.length > 0 && (
<>
<Separator />
<EpisodeWatchHistory
watchHistory={watchHistory}
onDelete={(seenId) =>
deleteEntrySeen.mutate({ id: seenId, entryId: e.id })
}
/>
</>
)}
{/* Dialogs */}
{showSettings && (
<EntrySettingsDialog
open={showSettings}
onOpenChange={setShowSettings}
entry={e}
/>
)}
{showSeenDialog && (
<EntrySeenDialog
open={showSeenDialog}
onOpenChange={setShowSeenDialog}
entry={e}
seasons={seasons}
mode="add"
/>
)}
{showMediaDialog && (
<EntryMediaDialog
open={showMediaDialog}
onOpenChange={setShowMediaDialog}
entryId={e.id}
medias={e.medias || []}
/>
)}
{showCollectionDialog && (
<AddEntryToCollectionDialog
open={showCollectionDialog}
onOpenChange={setShowCollectionDialog}
entryId={e.id}
/>
)}
</div>
);
}
function EntryDetailsSkeleton() {
return (
<div className="space-y-8">
<div className="flex gap-6">
<Skeleton className="h-72 w-48 shrink-0 rounded-lg" />
<div className="flex-1 space-y-4">
<Skeleton className="h-8 w-64" />
<Skeleton className="h-4 w-40" />
<Skeleton className="h-4 w-80" />
<div className="flex gap-2">
<Skeleton className="h-8 w-24" />
<Skeleton className="h-8 w-32" />
</div>
</div>
</div>
</div>
);
}
+146
View File
@@ -0,0 +1,146 @@
import { useState } from 'react';
import { useParams, Link } from 'react-router-dom';
import { useQuery } from '@tanstack/react-query';
import { seasonsApi } from '@/api/seasons';
import { useEpisodeSeenByEpisode, useCreateEpisodeSeen } from '@/hooks/useEpisodeSeen';
import { Skeleton } from '@/components/ui/skeleton';
import { Button } from '@/components/ui/button';
import { Separator } from '@/components/ui/separator';
import { EpisodeWatchHistory } from '@/components/entries/EpisodeWatchHistory';
import { CastList } from '@/components/entries/CastList';
import { Eye, ChevronLeft, ChevronRight, Clock } from 'lucide-react';
import { getTmdbPosterUrl, formatDate, formatRuntime } from '@/lib/media-utils';
import type { Episode } from '@/types';
export function EpisodePage() {
const { entryId, seasonId, episodeId } = useParams<{
entryId: string;
seasonId: string;
episodeId: string;
}>();
const { data: episodes = [] } = useQuery({
queryKey: ['seasons', parseInt(seasonId!, 10), 'episodes'],
queryFn: () => seasonsApi.getEpisodes(parseInt(seasonId!, 10)),
});
const epId = parseInt(episodeId!, 10);
const episode: Episode | undefined = episodes.find((ep: Episode) => ep.id === epId);
const { data: watchHistory = [] } = useEpisodeSeenByEpisode(epId);
const createEpisodeSeen = useCreateEpisodeSeen();
// Find prev/next episode
const currentIndex = episodes.findIndex((ep: Episode) => ep.id === epId);
const prevEpisode: Episode | undefined = currentIndex > 0 ? episodes[currentIndex - 1] : undefined;
const nextEpisode: Episode | undefined =
currentIndex < episodes.length - 1 ? episodes[currentIndex + 1] : undefined;
if (!episode) {
return (
<div className="space-y-6">
<Skeleton className="h-48 w-full rounded-lg" />
<Skeleton className="h-6 w-48" />
<Skeleton className="h-4 w-80" />
</div>
);
}
const handleMarkWatched = () => {
createEpisodeSeen.mutate({
entry_id: parseInt(entryId!, 10),
episode_id: episode.id,
date_seen: new Date().toISOString().split('T')[0],
});
};
return (
<div className="space-y-8">
{/* Thumbnail */}
{episode.still_path && (
<div className="overflow-hidden rounded-lg">
<img
src={getTmdbPosterUrl(episode.still_path, 'w780')}
alt={episode.name}
className="w-full max-h-80 object-cover"
/>
</div>
)}
{/* Info */}
<div className="space-y-3">
<div className="flex items-center gap-3">
<span className="text-sm text-muted-foreground">
Episode {episode.episode_number}
</span>
<h1 className="text-2xl font-bold">{episode.name}</h1>
</div>
<div className="flex flex-wrap items-center gap-3 text-sm text-muted-foreground">
{episode.air_date && <span>{formatDate(episode.air_date)}</span>}
{episode.runtime && (
<span className="flex items-center gap-1">
<Clock className="h-3 w-3" />
{formatRuntime(episode.runtime)}
</span>
)}
</div>
{episode.overview && (
<p className="text-sm text-muted-foreground leading-relaxed max-w-2xl">
{episode.overview}
</p>
)}
<Button size="sm" onClick={handleMarkWatched}>
<Eye className="mr-1 h-4 w-4" />
Mark as Watched
</Button>
</div>
{/* Guest Stars */}
{episode.guest_stars && episode.guest_stars.length > 0 && (
<>
<Separator />
<CastList credits={episode.guest_stars} />
</>
)}
{/* Watch History */}
{watchHistory.length > 0 && (
<>
<Separator />
<EpisodeWatchHistory watchHistory={watchHistory} />
</>
)}
{/* Navigation */}
<Separator />
<div className="flex justify-between">
{prevEpisode ? (
<Button variant="outline" asChild>
<Link
to={`/entry/${entryId}/season/${seasonId}/episode/${prevEpisode.id}`}
>
<ChevronLeft className="mr-1 h-4 w-4" />
E{prevEpisode.episode_number}: {prevEpisode.name}
</Link>
</Button>
) : (
<div />
)}
{nextEpisode ? (
<Button variant="outline" asChild>
<Link
to={`/entry/${entryId}/season/${seasonId}/episode/${nextEpisode.id}`}
>
E{nextEpisode.episode_number}: {nextEpisode.name}
<ChevronRight className="ml-1 h-4 w-4" />
</Link>
</Button>
) : (
<div />
)}
</div>
</div>
);
}
+78
View File
@@ -0,0 +1,78 @@
import { useTrendingMovies, useTrendingTv, usePopularMovies, usePopularTv, useTmdbSearch } from '@/hooks/useTmdb';
import { useLibrary } from '@/hooks/useEntries';
import { TrendingGrid } from '@/components/entries/TrendingGrid';
import { Input } from '@/components/ui/input';
import { useState } from 'react';
import { Search } from 'lucide-react';
import { EntryCard } from '@/components/entries/EntryCard';
export function HomePage() {
const [searchQuery, setSearchQuery] = useState('');
// Pre-load library
useLibrary();
const trendingMovies = useTrendingMovies();
const trendingTv = useTrendingTv();
const popularMovies = usePopularMovies();
const popularTv = usePopularTv();
const searchResults = useTmdbSearch(searchQuery);
const trendingMovieEntries = trendingMovies.data?.pages.flatMap((p) => p.results) ?? [];
const trendingTvEntries = trendingTv.data?.pages.flatMap((p) => p.results) ?? [];
const popularMovieEntries = popularMovies.data?.pages.flatMap((p) => p.results) ?? [];
const popularTvEntries = popularTv.data?.pages.flatMap((p) => p.results) ?? [];
const searchEntries = searchResults.data?.pages.flatMap((p) => p.results) ?? [];
const isSearching = searchQuery.length > 0;
return (
<div className="space-y-8">
{/* Search */}
<div className="relative max-w-md">
<Search className="absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
<Input
placeholder="Search movies & TV shows..."
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
className="pl-10"
/>
</div>
{isSearching ? (
<div className="space-y-4">
<h2 className="text-xl font-semibold">
Search Results for "{searchQuery}"
</h2>
{searchEntries.length === 0 && !searchResults.isLoading ? (
<p className="text-muted-foreground">No results 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 2xl:grid-cols-7">
{searchEntries.map((entry) => (
<EntryCard key={entry.id} tmdbEntry={entry} />
))}
</div>
)}
</div>
) : (
<>
<TrendingGrid
title="Trending"
movieEntries={trendingMovieEntries}
tvEntries={trendingTvEntries}
isLoading={trendingMovies.isLoading || trendingTv.isLoading}
moreLink="/library"
/>
<TrendingGrid
title="Popular"
movieEntries={popularMovieEntries}
tvEntries={popularTvEntries}
isLoading={popularMovies.isLoading || popularTv.isLoading}
moreLink="/library"
/>
</>
)}
</div>
);
}
+279
View File
@@ -0,0 +1,279 @@
import { useState, useMemo, useCallback } from 'react';
import { useLibrary } from '@/hooks/useEntries';
import { useLibraryEntries } from '@/stores/useLibraryStore';
import { EntryLibraryGrid } from '@/components/entries/EntryLibraryGrid';
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
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 { Search, X, SlidersHorizontal, ArrowUpDown } from 'lucide-react';
import type { Entry } from '@/types';
type FilterTab = 'all' | 'movies' | 'tv' | 'favorites' | 'hidden';
type SortField = 'date_last_seen' | 'createdAt' | 'title' | 'release_date' | 'rating';
type SortDir = 'asc' | 'desc';
interface Filters {
genre: string;
ratingMin: string;
ratingMax: string;
yearMin: string;
yearMax: string;
}
const defaultFilters: Filters = { genre: '', ratingMin: '', ratingMax: '', yearMin: '', yearMax: '' };
const sortLabels: Record<SortField, string> = {
date_last_seen: 'Last Watched',
createdAt: 'Date Added',
title: 'Title',
release_date: 'Release Date',
rating: 'Rating',
};
function sortEntries(entries: Entry[], field: SortField, dir: SortDir): Entry[] {
return [...entries].sort((a, b) => {
let cmp = 0;
switch (field) {
case 'title':
cmp = a.title.localeCompare(b.title);
break;
case 'release_date':
cmp = new Date(a.release_date || '1900').getTime() - new Date(b.release_date || '1900').getTime();
break;
case 'rating':
cmp = (a.entryRatings?.user_rating || a.entryRatings?.tmdb_rating || 0) -
(b.entryRatings?.user_rating || b.entryRatings?.tmdb_rating || 0);
break;
case 'date_last_seen':
cmp = new Date(a.date_last_seen || '1900').getTime() - new Date(b.date_last_seen || '1900').getTime();
break;
case 'createdAt':
cmp = new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime();
break;
}
return dir === 'desc' ? -cmp : cmp;
});
}
export function LibraryPage() {
const { isLoading } = useLibrary();
const [activeTab, setActiveTab] = useState<FilterTab>('all');
const [search, setSearch] = useState('');
const [sortField, setSortField] = useState<SortField>('date_last_seen');
const [sortDir, setSortDir] = useState<SortDir>('desc');
const [filters, setFilters] = useState<Filters>(defaultFilters);
const allEntries = useLibraryEntries();
// Gather unique genres from the library
const allGenres = useMemo(() => {
const set = new Set<string>();
allEntries.forEach((e) => e.genres?.forEach((g) => set.add(g.name)));
return Array.from(set).sort();
}, [allEntries]);
const hasActiveFilters = filters.genre || filters.ratingMin || filters.ratingMax || filters.yearMin || filters.yearMax;
const baseEntries = useMemo(() => {
switch (activeTab) {
case 'movies':
return allEntries.filter((e) => !e.is_tvseries && !e.watchlist);
case 'tv':
return allEntries.filter((e) => e.is_tvseries && !e.watchlist);
case 'favorites':
return allEntries.filter((e) => e.favorit && !e.watchlist);
case 'hidden':
return allEntries.filter((e) => e.hidden);
default:
return allEntries.filter((e) => !e.watchlist);
}
}, [activeTab, allEntries]);
const filteredEntries = useMemo(() => {
let result = baseEntries;
if (search) {
const q = search.toLowerCase();
result = result.filter((e) => e.title.toLowerCase().includes(q));
}
if (filters.genre) {
result = result.filter((e) => e.genres?.some((g) => g.name === filters.genre));
}
if (filters.ratingMin) {
const min = parseFloat(filters.ratingMin);
result = result.filter((e) => (e.entryRatings?.user_rating || e.entryRatings?.tmdb_rating || 0) >= min);
}
if (filters.ratingMax) {
const max = parseFloat(filters.ratingMax);
result = result.filter((e) => (e.entryRatings?.user_rating || e.entryRatings?.tmdb_rating || 0) <= max);
}
if (filters.yearMin) {
const min = parseInt(filters.yearMin);
result = result.filter((e) => e.release_date && new Date(e.release_date).getFullYear() >= min);
}
if (filters.yearMax) {
const max = parseInt(filters.yearMax);
result = result.filter((e) => e.release_date && new Date(e.release_date).getFullYear() <= max);
}
return sortEntries(result, sortField, sortDir);
}, [baseEntries, search, filters, sortField, sortDir]);
const clearFilters = useCallback(() => setFilters(defaultFilters), []);
return (
<div className="space-y-6">
<div className="flex items-center justify-between">
<h1 className="text-2xl font-bold">Library</h1>
</div>
{/* Controls row: search left, sort + filter + tabs right */}
<div className="flex flex-wrap items-center gap-3">
{/* Search - far left */}
<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 library..."
value={search}
onChange={(e) => setSearch(e.target.value)}
className="pl-10"
/>
</div>
{search && (
<Button variant="ghost" size="sm" onClick={() => setSearch('')}>
<X className="mr-1 h-4 w-4" /> Clear
</Button>
)}
{/* Spacer */}
<div className="flex-1" />
{/* Sort */}
<div className="flex items-center gap-1">
<ArrowUpDown className="h-4 w-4 text-muted-foreground" />
<Select value={sortField} onValueChange={(v) => setSortField(v as SortField)}>
<SelectTrigger className="w-[160px] h-9">
<SelectValue>{sortLabels[sortField]}</SelectValue>
</SelectTrigger>
<SelectContent>
{Object.entries(sortLabels).map(([value, label]) => (
<SelectItem key={value} value={value}>{label}</SelectItem>
))}
</SelectContent>
</Select>
<Button
variant="ghost"
size="icon"
className="h-9 w-9"
onClick={() => setSortDir((d) => (d === 'desc' ? 'asc' : 'desc'))}
>
<span className="text-xs font-medium">{sortDir === 'desc' ? '↓' : '↑'}</span>
</Button>
</div>
{/* Filter */}
<Popover>
<PopoverTrigger asChild>
<Button variant="outline" size="sm" className="h-9 gap-1">
<SlidersHorizontal className="h-4 w-4" />
Filter
{hasActiveFilters && <Badge variant="secondary" className="ml-1 h-5 px-1 text-[10px]">Active</Badge>}
</Button>
</PopoverTrigger>
<PopoverContent className="w-72 space-y-4" align="end">
<div className="space-y-2">
<label className="text-sm font-medium">Genre</label>
<Select value={filters.genre} onValueChange={(v) => setFilters((f) => ({ ...f, genre: v === '_all' ? '' : v }))}>
<SelectTrigger className="h-9">
<SelectValue placeholder="All genres" />
</SelectTrigger>
<SelectContent>
<SelectItem value="_all">All genres</SelectItem>
{allGenres.map((g) => (
<SelectItem key={g} value={g}>{g}</SelectItem>
))}
</SelectContent>
</Select>
</div>
<div className="space-y-2">
<label className="text-sm font-medium">Rating Range</label>
<div className="flex items-center gap-2">
<Input
type="number"
placeholder="Min"
min={0}
max={10}
step={0.1}
value={filters.ratingMin}
onChange={(e) => setFilters((f) => ({ ...f, ratingMin: e.target.value }))}
className="h-9"
/>
<span className="text-muted-foreground">–</span>
<Input
type="number"
placeholder="Max"
min={0}
max={10}
step={0.1}
value={filters.ratingMax}
onChange={(e) => setFilters((f) => ({ ...f, ratingMax: e.target.value }))}
className="h-9"
/>
</div>
</div>
<div className="space-y-2">
<label className="text-sm font-medium">Year Range</label>
<div className="flex items-center gap-2">
<Input
type="number"
placeholder="From"
min={1900}
max={2099}
value={filters.yearMin}
onChange={(e) => setFilters((f) => ({ ...f, yearMin: e.target.value }))}
className="h-9"
/>
<span className="text-muted-foreground">–</span>
<Input
type="number"
placeholder="To"
min={1900}
max={2099}
value={filters.yearMax}
onChange={(e) => setFilters((f) => ({ ...f, yearMax: e.target.value }))}
className="h-9"
/>
</div>
</div>
{hasActiveFilters && (
<Button variant="ghost" size="sm" className="w-full" onClick={clearFilters}>
Clear Filters
</Button>
)}
</PopoverContent>
</Popover>
{/* Tabs */}
<Tabs
value={activeTab}
onValueChange={(v) => setActiveTab(v as FilterTab)}
>
<TabsList>
<TabsTrigger value="all">All</TabsTrigger>
<TabsTrigger value="movies">Movies</TabsTrigger>
<TabsTrigger value="tv">TV Series</TabsTrigger>
<TabsTrigger value="favorites">Favorites</TabsTrigger>
<TabsTrigger value="hidden">Hidden</TabsTrigger>
</TabsList>
</Tabs>
</div>
<EntryLibraryGrid entries={filteredEntries} isLoading={isLoading} />
</div>
);
}
+125
View File
@@ -0,0 +1,125 @@
import { useState, useMemo } from 'react';
import { useLibrary } from '@/hooks/useEntries';
import { useLibraryEntries } from '@/stores/useLibraryStore';
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
import { Input } from '@/components/ui/input';
import { Skeleton } from '@/components/ui/skeleton';
import { Search } from 'lucide-react';
import { getMediaUrl } from '@/lib/api';
import type { Media } from '@/types';
export function MediaPage() {
const { isLoading } = useLibrary();
const [search, setSearch] = useState('');
const [mediaType, setMediaType] = useState<'all' | 'poster' | 'backdrop' | 'logo'>('all');
const entries = useLibraryEntries();
const allMedias = useMemo(() => {
const medias: (Media & { entryTitle: string })[] = [];
entries.forEach((entry) => {
entry.medias?.forEach((m) => {
medias.push({ ...m, entryTitle: entry.title });
});
});
return medias;
}, [entries]);
const filtered = useMemo(() => {
let result = allMedias;
if (mediaType !== 'all') {
result = result.filter((m) => m.type === mediaType);
}
if (search) {
const q = search.toLowerCase();
result = result.filter((m) => m.entryTitle.toLowerCase().includes(q));
}
return result;
}, [allMedias, mediaType, search]);
return (
<div className="space-y-6">
<h1 className="text-2xl font-bold">Media</h1>
<div className="flex flex-wrap items-center gap-3">
<Tabs
value={mediaType}
onValueChange={(v) => setMediaType(v as typeof mediaType)}
>
<TabsList>
<TabsTrigger value="all">All</TabsTrigger>
<TabsTrigger value="poster">Posters</TabsTrigger>
<TabsTrigger value="backdrop">Backdrops</TabsTrigger>
<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 ? (
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6">
{Array.from({ length: 18 }).map((_, i) => (
<Skeleton
key={i}
className={
mediaType === 'backdrop'
? 'aspect-video w-full rounded-lg'
: 'aspect-[2/3] w-full rounded-lg'
}
/>
))}
</div>
) : filtered.length === 0 ? (
<div className="flex h-40 items-center justify-center text-muted-foreground">
No media found.
</div>
) : (
<div
className={`grid gap-4 ${
mediaType === 'backdrop'
? 'grid-cols-1 sm:grid-cols-2 lg:grid-cols-3'
: 'grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6'
}`}
>
{filtered.map((media) => (
<div
key={media.id}
className="group relative overflow-hidden rounded-lg bg-muted"
>
<img
src={getMediaUrl(
'entries',
`${media.type}s`,
'preview',
media.path
)}
alt={media.entryTitle}
className={`w-full object-cover ${
media.type === 'backdrop' ? 'aspect-video' : 'aspect-[2/3]'
}`}
loading="lazy"
/>
<div className="absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/80 to-transparent p-2 opacity-0 transition-opacity group-hover:opacity-100">
<p className="text-xs text-white truncate">
{media.entryTitle}
</p>
</div>
</div>
))}
</div>
)}
</div>
);
}
+95
View File
@@ -0,0 +1,95 @@
import { useState, useCallback, useRef, useEffect } from 'react';
import { Link } from 'react-router-dom';
import { usePopularPeople, useTmdbSearchPeople } from '@/hooks/useTmdb';
import { Input } from '@/components/ui/input';
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
import { Skeleton } from '@/components/ui/skeleton';
import { Search } from 'lucide-react';
import { getProfileUrl } from '@/lib/media-utils';
export function PeoplePage() {
const [search, setSearch] = useState('');
const isSearching = search.length > 0;
const popularQuery = usePopularPeople();
const searchQuery = useTmdbSearchPeople(search);
const activeQuery = isSearching ? searchQuery : popularQuery;
const people = activeQuery.data?.pages.flatMap((p) => p.results) ?? [];
const observerRef = useRef<IntersectionObserver | null>(null);
const lastRef = useCallback(
(node: HTMLDivElement | null) => {
if (activeQuery.isFetchingNextPage) return;
if (observerRef.current) observerRef.current.disconnect();
observerRef.current = new IntersectionObserver((entries) => {
if (entries[0].isIntersecting && activeQuery.hasNextPage) {
activeQuery.fetchNextPage();
}
});
if (node) observerRef.current.observe(node);
},
[activeQuery.isFetchingNextPage, activeQuery.hasNextPage, activeQuery.fetchNextPage]
);
useEffect(() => {
return () => observerRef.current?.disconnect();
}, []);
return (
<div className="space-y-6">
<h1 className="text-2xl font-bold">People</h1>
<div className="relative 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 people..."
value={search}
onChange={(e) => setSearch(e.target.value)}
className="pl-10"
/>
</div>
{activeQuery.isLoading ? (
<div className="grid grid-cols-3 gap-4 sm:grid-cols-4 md:grid-cols-5 lg:grid-cols-6 xl:grid-cols-8">
{Array.from({ length: 24 }).map((_, i) => (
<div key={i} className="flex flex-col items-center gap-2">
<Skeleton className="h-24 w-24 rounded-full" />
<Skeleton className="h-4 w-20" />
</div>
))}
</div>
) : (
<div className="grid grid-cols-3 gap-4 sm:grid-cols-4 md:grid-cols-5 lg:grid-cols-6 xl:grid-cols-8">
{people.map((person, index) => (
<div
key={person.id}
ref={index === people.length - 1 ? lastRef : undefined}
>
<Link
to={`/people/${person.id}`}
className="group flex flex-col items-center gap-2 text-center"
>
<Avatar className="h-24 w-24 transition-transform group-hover:scale-105">
<AvatarImage
src={getProfileUrl(person.profile_path)}
alt={person.name}
/>
<AvatarFallback>
{person.name
.split(' ')
.map((n) => n[0])
.join('')}
</AvatarFallback>
</Avatar>
<p className="text-sm font-medium line-clamp-2">
{person.name}
</p>
</Link>
</div>
))}
</div>
)}
</div>
);
}
@@ -0,0 +1,94 @@
import { useParams } from 'react-router-dom';
import { usePerson } from '@/hooks/usePeople';
import { useQuery } from '@tanstack/react-query';
import { peopleApi } from '@/api/people';
import { Skeleton } from '@/components/ui/skeleton';
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
import { Separator } from '@/components/ui/separator';
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
import { EntryCard } from '@/components/entries/EntryCard';
import { getProfileUrl, formatDate } from '@/lib/media-utils';
export function PersonDetailsPage() {
const { id } = useParams<{ id: string }>();
const personId = parseInt(id!, 10);
const { data: person, isLoading } = usePerson(personId);
if (isLoading || !person) {
return (
<div className="space-y-6">
<div className="flex gap-6">
<Skeleton className="h-48 w-48 rounded-full" />
<div className="flex-1 space-y-3">
<Skeleton className="h-8 w-48" />
<Skeleton className="h-4 w-32" />
<Skeleton className="h-20 w-full" />
</div>
</div>
</div>
);
}
return (
<div className="space-y-8">
{/* Profile header */}
<div className="flex gap-8">
<Avatar className="h-48 w-48 shrink-0">
<AvatarImage
src={getProfileUrl(person.profile_path)}
alt={person.name}
/>
<AvatarFallback className="text-3xl">
{person.name
.split(' ')
.map((n: string) => n[0])
.join('')}
</AvatarFallback>
</Avatar>
<div className="space-y-3">
<h1 className="text-3xl font-bold">{person.name}</h1>
<div className="flex flex-wrap items-center gap-3 text-sm text-muted-foreground">
{person.known_for_department && (
<span>{person.known_for_department}</span>
)}
{person.birthday && (
<>
<span>•</span>
<span>Born: {formatDate(person.birthday)}</span>
</>
)}
{person.deathday && (
<>
<span>•</span>
<span>Died: {formatDate(person.deathday)}</span>
</>
)}
{person.place_of_birth && (
<>
<span>•</span>
<span>{person.place_of_birth}</span>
</>
)}
</div>
{person.biography && (
<p className="text-sm text-muted-foreground leading-relaxed max-w-2xl line-clamp-6">
{person.biography}
</p>
)}
</div>
</div>
<Separator />
{/* Filmography placeholder */}
<div className="space-y-4">
<h2 className="text-xl font-semibold">Filmography</h2>
<p className="text-sm text-muted-foreground">
Filmography details will be loaded from credits associated with this person.
</p>
</div>
</div>
);
}
+156
View File
@@ -0,0 +1,156 @@
import { useParams, Link } from 'react-router-dom';
import { useSeason, useSeasonEpisodes } from '@/hooks/useSeasons';
import { Skeleton } from '@/components/ui/skeleton';
import { Progress } from '@/components/ui/progress';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import { Eye, CheckCircle2 } from 'lucide-react';
import { getTmdbPosterUrl, getYear, formatDate } from '@/lib/media-utils';
export function SeasonPage() {
const { entryId, seasonId } = useParams<{
entryId: string;
seasonId: string;
}>();
const { data: season, isLoading } = useSeason(parseInt(seasonId!, 10));
const { data: episodes = [] } = useSeasonEpisodes(parseInt(seasonId!, 10));
if (isLoading || !season) {
return (
<div className="space-y-6">
<div className="flex gap-6">
<Skeleton className="h-56 w-36 shrink-0 rounded-lg" />
<div className="flex-1 space-y-3">
<Skeleton className="h-6 w-48" />
<Skeleton className="h-4 w-32" />
<Skeleton className="h-4 w-64" />
</div>
</div>
</div>
);
}
const watchedCount = episodes.filter(
(ep) =>
ep.date_first_seen ||
(ep.episodeSeens && ep.episodeSeens.length > 0)
).length;
const totalEpisodes = episodes.length;
const progress = totalEpisodes > 0 ? (watchedCount / totalEpisodes) * 100 : 0;
return (
<div className="space-y-8">
{/* Header */}
<div className="flex gap-6">
<img
src={getTmdbPosterUrl(season.poster_path, 'w185')}
alt={season.name}
className="h-56 w-36 shrink-0 rounded-lg object-cover shadow-lg"
/>
<div className="flex flex-col justify-center space-y-3">
<h1 className="text-2xl font-bold">{season.name}</h1>
<div className="flex items-center gap-2 text-sm text-muted-foreground">
<span>Season {season.season_number}</span>
{season.air_date && (
<>
<span>•</span>
<span>{getYear(season.air_date)}</span>
</>
)}
<span>•</span>
<span>{totalEpisodes} episodes</span>
</div>
{/* Watch progress */}
<div className="flex items-center gap-3 max-w-xs">
<Progress value={progress} className="flex-1 h-2" />
<span className="text-sm font-medium">
{watchedCount}/{totalEpisodes}
</span>
</div>
{season.overview && (
<p className="text-sm text-muted-foreground max-w-lg">
{season.overview}
</p>
)}
</div>
</div>
{/* Episodes */}
<div className="space-y-3">
<h3 className="text-lg font-semibold">Episodes</h3>
<div className="space-y-2">
{episodes.map((episode) => {
const isWatched =
!!episode.date_first_seen ||
(episode.episodeSeens && episode.episodeSeens.length > 0);
return (
<Link
key={episode.id}
to={`/entry/${entryId}/season/${seasonId}/episode/${episode.id}`}
className="flex gap-4 rounded-lg border border-border p-3 transition-colors hover:bg-accent/50"
>
{/* Thumbnail */}
<div className="h-16 w-28 shrink-0 overflow-hidden rounded bg-muted">
{episode.still_path ? (
<img
src={getTmdbPosterUrl(episode.still_path, 'w300')}
alt={episode.name}
className="h-full w-full object-cover"
loading="lazy"
/>
) : (
<div className="flex h-full w-full items-center justify-center text-xs text-muted-foreground">
No Image
</div>
)}
</div>
{/* Info */}
<div className="flex-1 min-w-0">
<div className="flex items-center gap-2">
<span className="text-xs text-muted-foreground">
E{episode.episode_number}
</span>
<span className="text-sm font-medium truncate">
{episode.name}
</span>
{isWatched && (
<CheckCircle2 className="h-4 w-4 shrink-0 text-green-500" />
)}
</div>
{episode.air_date && (
<p className="text-xs text-muted-foreground">
{formatDate(episode.air_date)}
</p>
)}
{episode.overview && (
<p className="mt-1 text-xs text-muted-foreground line-clamp-2">
{episode.overview}
</p>
)}
</div>
{/* Watch button */}
<Button
size="icon"
variant={isWatched ? 'secondary' : 'outline'}
className="h-8 w-8 shrink-0 self-center"
onClick={(ev) => {
ev.preventDefault();
ev.stopPropagation();
// TODO: Mark episode as watched
}}
>
<Eye className="h-4 w-4" />
</Button>
</Link>
);
})}
</div>
</div>
</div>
);
}
+104
View File
@@ -0,0 +1,104 @@
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { settingsApi } from '@/api/settings';
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { z } from 'zod';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Button } from '@/components/ui/button';
import { Skeleton } from '@/components/ui/skeleton';
import { Save } from 'lucide-react';
import type { Settings } from '@/types';
const settingsSchema = z.object({
tmdbApiKey: z.string().min(1, 'TMDB API key is required'),
backPort: z.coerce.number().int().positive(),
});
export function SettingsPage() {
const queryClient = useQueryClient();
const { data: settings, isLoading } = useQuery({
queryKey: ['settings'],
queryFn: settingsApi.get,
});
const updateSettings = useMutation({
mutationFn: (data: Partial<Settings>) => settingsApi.update(data),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['settings'] });
},
});
const {
register,
handleSubmit,
formState: { errors, isDirty },
} = useForm({
resolver: zodResolver(settingsSchema),
values: settings
? { tmdbApiKey: settings.tmdbApiKey, backPort: settings.backPort }
: undefined,
});
const onSubmit = (data: { tmdbApiKey: string; backPort: number }) => {
updateSettings.mutate(data);
};
if (isLoading) {
return (
<div className="space-y-6">
<h1 className="text-2xl font-bold">Settings</h1>
<Skeleton className="h-48 w-full" />
</div>
);
}
return (
<div className="space-y-6 max-w-2xl">
<h1 className="text-2xl font-bold">Settings</h1>
<form onSubmit={handleSubmit(onSubmit)}>
<Card>
<CardHeader>
<CardTitle>General</CardTitle>
</CardHeader>
<CardContent className="space-y-4">
<div className="space-y-2">
<Label htmlFor="tmdbApiKey">TMDB API Key</Label>
<Input
id="tmdbApiKey"
type="password"
{...register('tmdbApiKey')}
/>
{errors.tmdbApiKey && (
<p className="text-xs text-destructive">
{errors.tmdbApiKey.message}
</p>
)}
</div>
<div className="space-y-2">
<Label htmlFor="backPort">Backend Port</Label>
<Input
id="backPort"
type="number"
{...register('backPort')}
/>
{errors.backPort && (
<p className="text-xs text-destructive">
{errors.backPort.message}
</p>
)}
</div>
<Button type="submit" disabled={!isDirty || updateSettings.isPending}>
<Save className="mr-2 h-4 w-4" />
{updateSettings.isPending ? 'Saving...' : 'Save Settings'}
</Button>
</CardContent>
</Card>
</form>
</div>
);
}
+237
View File
@@ -0,0 +1,237 @@
import { useState, useMemo, useCallback } from 'react';
import { useLibrary } from '@/hooks/useEntries';
import { useLibraryEntries } from '@/stores/useLibraryStore';
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 { 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';
interface Filters {
genre: string;
ratingMin: string;
ratingMax: string;
yearMin: string;
yearMax: string;
}
const defaultFilters: Filters = { genre: '', ratingMin: '', ratingMax: '', yearMin: '', yearMax: '' };
const sortLabels: Record<SortField, string> = {
createdAt: 'Date Added',
date_last_seen: 'Last Watched',
title: 'Title',
release_date: 'Release Date',
rating: 'Rating',
};
function sortEntries(entries: Entry[], field: SortField, dir: SortDir): Entry[] {
return [...entries].sort((a, b) => {
let cmp = 0;
switch (field) {
case 'title':
cmp = a.title.localeCompare(b.title);
break;
case 'release_date':
cmp = new Date(a.release_date || '1900').getTime() - new Date(b.release_date || '1900').getTime();
break;
case 'rating':
cmp = (a.entryRatings?.user_rating || a.entryRatings?.tmdb_rating || 0) -
(b.entryRatings?.user_rating || b.entryRatings?.tmdb_rating || 0);
break;
case 'date_last_seen':
cmp = new Date(a.date_last_seen || '1900').getTime() - new Date(b.date_last_seen || '1900').getTime();
break;
case 'createdAt':
cmp = new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime();
break;
}
return dir === 'desc' ? -cmp : cmp;
});
}
export function WatchlistPage() {
const { isLoading } = useLibrary();
const [search, setSearch] = useState('');
const [sortField, setSortField] = useState<SortField>('createdAt');
const [sortDir, setSortDir] = useState<SortDir>('desc');
const [filters, setFilters] = useState<Filters>(defaultFilters);
const allEntries = useLibraryEntries();
const watchlist = useMemo(() => allEntries.filter((e) => e.watchlist), [allEntries]);
const allGenres = useMemo(() => {
const set = new Set<string>();
watchlist.forEach((e) => e.genres?.forEach((g) => set.add(g.name)));
return Array.from(set).sort();
}, [watchlist]);
const hasActiveFilters = filters.genre || filters.ratingMin || filters.ratingMax || filters.yearMin || filters.yearMax;
const filtered = useMemo(() => {
let result = watchlist;
if (search) {
const q = search.toLowerCase();
result = result.filter((e) => e.title.toLowerCase().includes(q));
}
if (filters.genre) {
result = result.filter((e) => e.genres?.some((g) => g.name === filters.genre));
}
if (filters.ratingMin) {
const min = parseFloat(filters.ratingMin);
result = result.filter((e) => (e.entryRatings?.user_rating || e.entryRatings?.tmdb_rating || 0) >= min);
}
if (filters.ratingMax) {
const max = parseFloat(filters.ratingMax);
result = result.filter((e) => (e.entryRatings?.user_rating || e.entryRatings?.tmdb_rating || 0) <= max);
}
if (filters.yearMin) {
const min = parseInt(filters.yearMin);
result = result.filter((e) => e.release_date && new Date(e.release_date).getFullYear() >= min);
}
if (filters.yearMax) {
const max = parseInt(filters.yearMax);
result = result.filter((e) => e.release_date && new Date(e.release_date).getFullYear() <= max);
}
return sortEntries(result, sortField, sortDir);
}, [watchlist, search, filters, sortField, sortDir]);
const clearFilters = useCallback(() => setFilters(defaultFilters), []);
return (
<div className="space-y-6">
<h1 className="text-2xl font-bold">Watchlist</h1>
<div className="flex flex-wrap items-center gap-3">
{/* Search */}
<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 watchlist..."
value={search}
onChange={(e) => setSearch(e.target.value)}
className="pl-10"
/>
</div>
{/* Spacer */}
<div className="flex-1" />
{/* Sort */}
<div className="flex items-center gap-1">
<ArrowUpDown className="h-4 w-4 text-muted-foreground" />
<Select value={sortField} onValueChange={(v) => setSortField(v as SortField)}>
<SelectTrigger className="w-[160px] h-9">
<SelectValue>{sortLabels[sortField]}</SelectValue>
</SelectTrigger>
<SelectContent>
{Object.entries(sortLabels).map(([value, label]) => (
<SelectItem key={value} value={value}>{label}</SelectItem>
))}
</SelectContent>
</Select>
<Button
variant="ghost"
size="icon"
className="h-9 w-9"
onClick={() => setSortDir((d) => (d === 'desc' ? 'asc' : 'desc'))}
>
<span className="text-xs font-medium">{sortDir === 'desc' ? '↓' : '↑'}</span>
</Button>
</div>
{/* Filter */}
<Popover>
<PopoverTrigger asChild>
<Button variant="outline" size="sm" className="h-9 gap-1">
<SlidersHorizontal className="h-4 w-4" />
Filter
{hasActiveFilters && <Badge variant="secondary" className="ml-1 h-5 px-1 text-[10px]">Active</Badge>}
</Button>
</PopoverTrigger>
<PopoverContent className="w-72 space-y-4" align="end">
<div className="space-y-2">
<label className="text-sm font-medium">Genre</label>
<Select value={filters.genre} onValueChange={(v) => setFilters((f) => ({ ...f, genre: v === '_all' ? '' : v }))}>
<SelectTrigger className="h-9">
<SelectValue placeholder="All genres" />
</SelectTrigger>
<SelectContent>
<SelectItem value="_all">All genres</SelectItem>
{allGenres.map((g) => (
<SelectItem key={g} value={g}>{g}</SelectItem>
))}
</SelectContent>
</Select>
</div>
<div className="space-y-2">
<label className="text-sm font-medium">Rating Range</label>
<div className="flex items-center gap-2">
<Input
type="number"
placeholder="Min"
min={0}
max={10}
step={0.1}
value={filters.ratingMin}
onChange={(e) => setFilters((f) => ({ ...f, ratingMin: e.target.value }))}
className="h-9"
/>
<span className="text-muted-foreground">–</span>
<Input
type="number"
placeholder="Max"
min={0}
max={10}
step={0.1}
value={filters.ratingMax}
onChange={(e) => setFilters((f) => ({ ...f, ratingMax: e.target.value }))}
className="h-9"
/>
</div>
</div>
<div className="space-y-2">
<label className="text-sm font-medium">Year Range</label>
<div className="flex items-center gap-2">
<Input
type="number"
placeholder="From"
min={1900}
max={2099}
value={filters.yearMin}
onChange={(e) => setFilters((f) => ({ ...f, yearMin: e.target.value }))}
className="h-9"
/>
<span className="text-muted-foreground">–</span>
<Input
type="number"
placeholder="To"
min={1900}
max={2099}
value={filters.yearMax}
onChange={(e) => setFilters((f) => ({ ...f, yearMax: e.target.value }))}
className="h-9"
/>
</div>
</div>
{hasActiveFilters && (
<Button variant="ghost" size="sm" className="w-full" onClick={clearFilters}>
Clear Filters
</Button>
)}
</PopoverContent>
</Popover>
</div>
<EntryLibraryGrid entries={filtered} isLoading={isLoading} />
</div>
);
}