Implemented the new react version of the frontend
This commit is contained in:
1 parent
236e6e06fb
commit
ffe7e52527
65 files changed
+5228
-177
No files matched your search
@@ -0,0 +1,60 @@
|
||||
import { Link } from 'react-router-dom';
|
||||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
||||
import { ScrollArea, ScrollBar } from '@/components/ui/scroll-area';
|
||||
import { getProfileUrl } from '@/lib/media-utils';
|
||||
import type { Credit } from '@/types';
|
||||
|
||||
interface CastListProps {
|
||||
credits: Credit[];
|
||||
}
|
||||
|
||||
export function CastList({ credits }: CastListProps) {
|
||||
const castCredits = credits.filter((c) => c.cast_type === 'cast');
|
||||
|
||||
if (castCredits.length === 0) return null;
|
||||
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<h3 className="text-lg font-semibold">Cast</h3>
|
||||
<ScrollArea className="w-full">
|
||||
<div className="flex gap-4 pb-4">
|
||||
{castCredits.map((credit) => (
|
||||
<CastCard key={credit.id} credit={credit} />
|
||||
))}
|
||||
</div>
|
||||
<ScrollBar orientation="horizontal" />
|
||||
</ScrollArea>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function CastCard({ credit }: { credit: Credit }) {
|
||||
const profileUrl = credit.people?.profile_path
|
||||
? getProfileUrl(credit.people.profile_path)
|
||||
: undefined;
|
||||
|
||||
return (
|
||||
<Link
|
||||
to={`/people/${credit.people_id}`}
|
||||
className="flex w-28 shrink-0 flex-col items-center gap-2 text-center"
|
||||
>
|
||||
<Avatar className="h-20 w-20">
|
||||
<AvatarImage src={profileUrl} alt={credit.people?.name} />
|
||||
<AvatarFallback className="text-xs">
|
||||
{credit.people?.name
|
||||
?.split(' ')
|
||||
.map((n) => n[0])
|
||||
.join('')}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
<div>
|
||||
<p className="text-xs font-medium leading-tight line-clamp-2">
|
||||
{credit.people?.name}
|
||||
</p>
|
||||
<p className="text-[10px] text-muted-foreground leading-tight line-clamp-1">
|
||||
{credit.character}
|
||||
</p>
|
||||
</div>
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
import { useState } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { Plus, Trash2, Star } from 'lucide-react';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { getPosterUrl, getYear, formatRuntime } from '@/lib/media-utils';
|
||||
import { useCreateEntry, useDeleteEntry } from '@/hooks/useEntries';
|
||||
import { useLibraryStore } from '@/stores/useLibraryStore';
|
||||
import { ConfirmDialog } from '@/components/dialogs/ConfirmDialog';
|
||||
import type { Entry, TmdbEntry } from '@/types';
|
||||
|
||||
interface EntryCardProps {
|
||||
entry?: Entry;
|
||||
tmdbEntry?: TmdbEntry;
|
||||
}
|
||||
|
||||
export function EntryCard({ entry, tmdbEntry }: EntryCardProps) {
|
||||
const [showConfirm, setShowConfirm] = useState(false);
|
||||
const createEntry = useCreateEntry();
|
||||
const deleteEntry = useDeleteEntry();
|
||||
const libraryEntry = useLibraryStore((s) => {
|
||||
if (entry?.isInLibrary) return entry;
|
||||
if (tmdbEntry) {
|
||||
for (const e of s.entries.values()) {
|
||||
if (e.entryIds?.tmdb_id === tmdbEntry.id) return e;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
const isInLibrary = !!libraryEntry;
|
||||
const displayEntry = libraryEntry || entry;
|
||||
|
||||
// Resolve display data
|
||||
const title =
|
||||
displayEntry?.title || tmdbEntry?.title || tmdbEntry?.name || 'Untitled';
|
||||
const year = displayEntry
|
||||
? getYear(displayEntry.release_date)
|
||||
: getYear(tmdbEntry?.release_date || tmdbEntry?.first_air_date || null);
|
||||
const rating =
|
||||
displayEntry?.entryRatings?.user_rating ||
|
||||
displayEntry?.entryRatings?.tmdb_rating ||
|
||||
tmdbEntry?.vote_average;
|
||||
const runtime =
|
||||
displayEntry && !displayEntry.is_tvseries
|
||||
? formatRuntime(displayEntry.runtime)
|
||||
: '';
|
||||
const isTv =
|
||||
displayEntry?.is_tvseries ||
|
||||
tmdbEntry?.media_type === 'tv' ||
|
||||
!!tmdbEntry?.name;
|
||||
|
||||
const posterUrl = displayEntry
|
||||
? getPosterUrl(displayEntry)
|
||||
: tmdbEntry?.poster_path
|
||||
? `https://image.tmdb.org/t/p/w342${tmdbEntry.poster_path}`
|
||||
: '/images/default-poster.png';
|
||||
|
||||
const entryLink = displayEntry
|
||||
? `/entry/${displayEntry.id}`
|
||||
: undefined;
|
||||
|
||||
const handleAdd = (e: React.MouseEvent) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
if (!tmdbEntry) return;
|
||||
createEntry.mutate({ tmdb_id: tmdbEntry.id, is_tvserie: isTv });
|
||||
};
|
||||
|
||||
const handleRemove = (e: React.MouseEvent) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
setShowConfirm(true);
|
||||
};
|
||||
|
||||
const confirmRemove = () => {
|
||||
if (libraryEntry) {
|
||||
deleteEntry.mutate(libraryEntry.id);
|
||||
}
|
||||
setShowConfirm(false);
|
||||
};
|
||||
|
||||
const card = (
|
||||
<div className="group relative overflow-hidden rounded-lg transition-all duration-200 hover:scale-[1.02] hover:shadow-xl">
|
||||
{/* Poster */}
|
||||
<div className="relative aspect-[2/3] w-full overflow-hidden rounded-lg bg-muted">
|
||||
<img
|
||||
src={posterUrl}
|
||||
alt={title}
|
||||
className="h-full w-full object-cover transition-transform duration-300 group-hover:scale-105"
|
||||
loading="lazy"
|
||||
/>
|
||||
|
||||
{/* Library badge – only on home / search (tmdbEntry context) */}
|
||||
{isInLibrary && tmdbEntry && (
|
||||
<Badge className="absolute left-2 top-2 bg-primary text-primary-foreground text-[10px] px-1.5 py-0.5">
|
||||
In Library
|
||||
</Badge>
|
||||
)}
|
||||
|
||||
{/* Favorite indicator */}
|
||||
{libraryEntry?.favorit && (
|
||||
<Star className="absolute right-2 top-2 h-4 w-4 fill-yellow-400 text-yellow-400" />
|
||||
)}
|
||||
|
||||
{/* Hover overlay */}
|
||||
<div className="absolute inset-0 flex flex-col justify-end bg-gradient-to-t from-black/90 via-black/40 to-transparent opacity-0 transition-opacity duration-200 group-hover:opacity-100">
|
||||
<div className="p-3 space-y-1">
|
||||
<p className="text-sm font-semibold text-white line-clamp-2">
|
||||
{title}
|
||||
</p>
|
||||
<div className="flex items-center gap-2 text-xs text-white/70">
|
||||
{rating != null && rating > 0 && (
|
||||
<span className="flex items-center gap-1">
|
||||
<Star className="h-3 w-3 fill-yellow-400 text-yellow-400" />
|
||||
{typeof rating === 'number' ? rating.toFixed(1) : rating}
|
||||
</span>
|
||||
)}
|
||||
{year && <span>{year}</span>}
|
||||
{runtime && <span>{runtime}</span>}
|
||||
</div>
|
||||
|
||||
{/* Actions */}
|
||||
<div className="pt-1">
|
||||
{isInLibrary ? (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="destructive"
|
||||
className="h-7 w-full text-xs"
|
||||
onClick={handleRemove}
|
||||
>
|
||||
<Trash2 className="mr-1 h-3 w-3" />
|
||||
Remove
|
||||
</Button>
|
||||
) : tmdbEntry ? (
|
||||
<Button
|
||||
size="sm"
|
||||
className="h-7 w-full text-xs"
|
||||
onClick={handleAdd}
|
||||
disabled={createEntry.isPending}
|
||||
>
|
||||
<Plus className="mr-1 h-3 w-3" />
|
||||
{createEntry.isPending ? 'Adding...' : 'Add to Library'}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
{entryLink ? <Link to={entryLink}>{card}</Link> : card}
|
||||
<ConfirmDialog
|
||||
open={showConfirm}
|
||||
onOpenChange={setShowConfirm}
|
||||
title="Remove from Library"
|
||||
description={`Are you sure you want to remove "${title}" from your library? This action cannot be undone.`}
|
||||
confirmLabel="Remove"
|
||||
onConfirm={confirmRemove}
|
||||
variant="destructive"
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export function EntryCardSkeleton() {
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="aspect-[2/3] w-full rounded-lg" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import { useCallback, useRef, useEffect } from 'react';
|
||||
import { EntryCard, EntryCardSkeleton } from './EntryCard';
|
||||
import type { Entry } from '@/types';
|
||||
|
||||
interface EntryLibraryGridProps {
|
||||
entries: Entry[];
|
||||
isLoading?: boolean;
|
||||
hasMore?: boolean;
|
||||
onLoadMore?: () => void;
|
||||
}
|
||||
|
||||
export function EntryLibraryGrid({
|
||||
entries,
|
||||
isLoading,
|
||||
hasMore,
|
||||
onLoadMore,
|
||||
}: EntryLibraryGridProps) {
|
||||
const observerRef = useRef<IntersectionObserver | null>(null);
|
||||
|
||||
const lastEntryRef = 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 && entries.length === 0) {
|
||||
return (
|
||||
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 2xl:grid-cols-7">
|
||||
{Array.from({ length: 21 }).map((_, i) => (
|
||||
<EntryCardSkeleton key={i} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (entries.length === 0) {
|
||||
return (
|
||||
<div className="flex h-40 items-center justify-center text-muted-foreground">
|
||||
No entries found.
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 2xl:grid-cols-7">
|
||||
{entries.map((entry, index) => (
|
||||
<div
|
||||
key={entry.id}
|
||||
ref={index === entries.length - 1 ? lastEntryRef : undefined}
|
||||
>
|
||||
<EntryCard entry={entry} />
|
||||
</div>
|
||||
))}
|
||||
{isLoading &&
|
||||
Array.from({ length: 7 }).map((_, i) => (
|
||||
<EntryCardSkeleton key={`loading-${i}`} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import { format } from 'date-fns';
|
||||
import type { EntrySeen, EpisodeSeen } from '@/types';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Pencil, Trash2 } from 'lucide-react';
|
||||
|
||||
interface EpisodeWatchHistoryProps {
|
||||
watchHistory: (EntrySeen | EpisodeSeen)[];
|
||||
onEdit?: (id: number) => void;
|
||||
onDelete?: (id: number) => void;
|
||||
}
|
||||
|
||||
export function EpisodeWatchHistory({
|
||||
watchHistory,
|
||||
onEdit,
|
||||
onDelete,
|
||||
}: EpisodeWatchHistoryProps) {
|
||||
if (watchHistory.length === 0) {
|
||||
return (
|
||||
<p className="text-sm text-muted-foreground">No watch history yet.</p>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<h3 className="text-lg font-semibold">Watch History</h3>
|
||||
<div className="overflow-x-auto rounded-lg border border-border">
|
||||
<table className="w-full text-sm">
|
||||
<thead>
|
||||
<tr className="border-b border-border bg-muted/50">
|
||||
<th className="px-4 py-2 text-left font-medium">Date</th>
|
||||
<th className="px-4 py-2 text-left font-medium">Seen With</th>
|
||||
<th className="px-4 py-2 text-right font-medium">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{watchHistory.map((record) => (
|
||||
<tr
|
||||
key={record.id}
|
||||
className="border-b border-border last:border-0"
|
||||
>
|
||||
<td className="px-4 py-2">
|
||||
{record.date_seen
|
||||
? format(new Date(record.date_seen), 'MMM d, yyyy')
|
||||
: '-'}
|
||||
</td>
|
||||
<td className="px-4 py-2 text-muted-foreground">
|
||||
{record.seen_with || '-'}
|
||||
</td>
|
||||
<td className="px-4 py-2">
|
||||
<div className="flex justify-end gap-1">
|
||||
{onEdit && (
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="h-7 w-7"
|
||||
onClick={() => onEdit(record.id)}
|
||||
>
|
||||
<Pencil className="h-3 w-3" />
|
||||
</Button>
|
||||
)}
|
||||
{onDelete && (
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="h-7 w-7 text-destructive"
|
||||
onClick={() => onDelete(record.id)}
|
||||
>
|
||||
<Trash2 className="h-3 w-3" />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
import { useState } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { ChevronDown, ChevronUp, Play } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Progress } from '@/components/ui/progress';
|
||||
import { getYear, getTmdbPosterUrl } from '@/lib/media-utils';
|
||||
import type { Season } from '@/types';
|
||||
|
||||
interface SeasonsContainerProps {
|
||||
seasons: Season[];
|
||||
entryId: number;
|
||||
}
|
||||
|
||||
export function SeasonsContainer({
|
||||
seasons,
|
||||
entryId,
|
||||
}: SeasonsContainerProps) {
|
||||
const [expanded, setExpanded] = useState(false);
|
||||
|
||||
// Sort: specials (season 0) at bottom, rest latest to oldest
|
||||
const sorted = [...seasons].sort((a, b) => {
|
||||
if (a.season_number === 0) return 1;
|
||||
if (b.season_number === 0) return -1;
|
||||
return b.season_number - a.season_number;
|
||||
});
|
||||
|
||||
const display = expanded ? sorted : sorted.slice(0, 2);
|
||||
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<h3 className="text-lg font-semibold">Seasons</h3>
|
||||
<div className="space-y-2">
|
||||
{display.map((season) => (
|
||||
<SeasonItem key={season.id} season={season} entryId={entryId} />
|
||||
))}
|
||||
</div>
|
||||
{sorted.length > 2 && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => setExpanded(!expanded)}
|
||||
className="w-full"
|
||||
>
|
||||
{expanded ? (
|
||||
<>
|
||||
<ChevronUp className="mr-1 h-4 w-4" /> Show Less
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<ChevronDown className="mr-1 h-4 w-4" /> Show All (
|
||||
{sorted.length})
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function SeasonItem({
|
||||
season,
|
||||
entryId,
|
||||
}: {
|
||||
season: Season;
|
||||
entryId: number;
|
||||
}) {
|
||||
const watchedCount =
|
||||
season.episodes?.filter(
|
||||
(ep) => ep.date_first_seen || (ep.episodeSeens && ep.episodeSeens.length > 0)
|
||||
).length ?? 0;
|
||||
const totalEpisodes = season.episode_count || season.episodes?.length || 0;
|
||||
const progress = totalEpisodes > 0 ? (watchedCount / totalEpisodes) * 100 : 0;
|
||||
|
||||
return (
|
||||
<Link
|
||||
to={`/entry/${entryId}/season/${season.id}`}
|
||||
className="flex items-center gap-4 rounded-lg border border-border p-3 transition-colors hover:bg-accent/50"
|
||||
>
|
||||
{/* Poster thumbnail */}
|
||||
<div className="h-16 w-11 shrink-0 overflow-hidden rounded bg-muted">
|
||||
<img
|
||||
src={getTmdbPosterUrl(season.poster_path, 'w92')}
|
||||
alt={season.name}
|
||||
className="h-full w-full object-cover"
|
||||
loading="lazy"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Info */}
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="font-medium text-sm truncate">{season.name}</span>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{getYear(season.air_date)}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 mt-1">
|
||||
<Progress value={progress} className="h-1.5 flex-1" />
|
||||
<span className="text-xs text-muted-foreground shrink-0">
|
||||
{watchedCount}/{totalEpisodes}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Quick watch button */}
|
||||
{watchedCount < totalEpisodes && (
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="h-8 w-8 shrink-0"
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
// TODO: Mark next unwatched episode as seen
|
||||
}}
|
||||
>
|
||||
<Play className="h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
import { useState } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { ChevronRight } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||
import { EntryCard, EntryCardSkeleton } from './EntryCard';
|
||||
import type { TmdbEntry } from '@/types';
|
||||
|
||||
interface TrendingGridProps {
|
||||
title: string;
|
||||
movieEntries: TmdbEntry[];
|
||||
tvEntries: TmdbEntry[];
|
||||
isLoading?: boolean;
|
||||
moreLink: string;
|
||||
}
|
||||
|
||||
export function TrendingGrid({
|
||||
title,
|
||||
movieEntries,
|
||||
tvEntries,
|
||||
isLoading,
|
||||
moreLink,
|
||||
}: TrendingGridProps) {
|
||||
const [activeTab, setActiveTab] = useState<'movie' | 'tv'>('movie');
|
||||
const entries = activeTab === 'movie' ? movieEntries : tvEntries;
|
||||
|
||||
// Limit to 2 rows (14 items for a 7-column grid)
|
||||
const displayEntries = entries.slice(0, 14);
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<h2 className="text-xl font-semibold">{title}</h2>
|
||||
<div className="flex items-center gap-3">
|
||||
<Tabs
|
||||
value={activeTab}
|
||||
onValueChange={(v) => setActiveTab(v as 'movie' | 'tv')}
|
||||
>
|
||||
<TabsList className="h-8">
|
||||
<TabsTrigger value="movie" className="text-xs px-3">
|
||||
Movies
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="tv" className="text-xs px-3">
|
||||
TV Series
|
||||
</TabsTrigger>
|
||||
</TabsList>
|
||||
</Tabs>
|
||||
<Button variant="ghost" size="sm" asChild>
|
||||
<Link to={moreLink}>
|
||||
More <ChevronRight className="ml-1 h-4 w-4" />
|
||||
</Link>
|
||||
</Button>
|
||||
</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 2xl:grid-cols-7">
|
||||
{Array.from({ length: 14 }).map((_, i) => (
|
||||
<EntryCardSkeleton key={i} />
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<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">
|
||||
{displayEntries.map((tmdbEntry) => (
|
||||
<EntryCard key={tmdbEntry.id} tmdbEntry={tmdbEntry} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user