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,71 @@
|
||||
import { Link } from 'react-router-dom';
|
||||
import { getCollectionPosterUrl } from '@/lib/media-utils';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import type { Collection } from '@/types';
|
||||
|
||||
interface CollectionCardProps {
|
||||
collection: Collection;
|
||||
}
|
||||
|
||||
export function CollectionCard({ collection }: CollectionCardProps) {
|
||||
return (
|
||||
<Link
|
||||
to={`/collections/${collection.id}`}
|
||||
className="group overflow-hidden rounded-lg transition-all hover:scale-[1.02] hover:shadow-lg"
|
||||
>
|
||||
<div className="relative aspect-[2/3] w-full overflow-hidden rounded-lg bg-muted">
|
||||
<img
|
||||
src={getCollectionPosterUrl(collection)}
|
||||
alt={collection.name}
|
||||
className="h-full w-full object-cover transition-transform group-hover:scale-105"
|
||||
loading="lazy"
|
||||
/>
|
||||
<div className="absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/80 to-transparent p-3">
|
||||
<p className="text-sm font-medium text-white line-clamp-2">
|
||||
{collection.name}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
||||
export function CollectionCardSkeleton() {
|
||||
return <Skeleton className="aspect-[2/3] w-full rounded-lg" />;
|
||||
}
|
||||
|
||||
interface CollectionsGridProps {
|
||||
collections: Collection[];
|
||||
isLoading?: boolean;
|
||||
}
|
||||
|
||||
export function CollectionsGrid({
|
||||
collections,
|
||||
isLoading,
|
||||
}: CollectionsGridProps) {
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6">
|
||||
{Array.from({ length: 12 }).map((_, i) => (
|
||||
<CollectionCardSkeleton key={i} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (collections.length === 0) {
|
||||
return (
|
||||
<div className="flex h-40 items-center justify-center text-muted-foreground">
|
||||
No collections 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">
|
||||
{collections.map((collection) => (
|
||||
<CollectionCard key={collection.id} collection={collection} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
import { useState } from 'react';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Checkbox } from '@/components/ui/checkbox';
|
||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||
import { useCollections } from '@/hooks/useCollections';
|
||||
import { collectionsApi } from '@/api/collections';
|
||||
import type { Collection } from '@/types';
|
||||
|
||||
interface AddEntryToCollectionDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
entryId: number;
|
||||
entryCollections?: Collection[];
|
||||
}
|
||||
|
||||
export function AddEntryToCollectionDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
entryId,
|
||||
entryCollections = [],
|
||||
}: AddEntryToCollectionDialogProps) {
|
||||
const [search, setSearch] = useState('');
|
||||
const { data: allCollections = [] } = useCollections();
|
||||
const entryCollectionIds = new Set(entryCollections.map((c) => c.id));
|
||||
|
||||
const filtered = allCollections.filter((c) =>
|
||||
c.name.toLowerCase().includes(search.toLowerCase())
|
||||
);
|
||||
|
||||
const handleToggle = async (collectionId: number, checked: boolean) => {
|
||||
if (checked) {
|
||||
await collectionsApi.addEntry(collectionId, entryId);
|
||||
} else {
|
||||
await collectionsApi.removeEntry(collectionId, entryId);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Add to Collection</DialogTitle>
|
||||
</DialogHeader>
|
||||
<Input
|
||||
placeholder="Search collections..."
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
/>
|
||||
<ScrollArea className="h-64">
|
||||
<div className="space-y-2 pr-4">
|
||||
{filtered.map((collection) => (
|
||||
<label
|
||||
key={collection.id}
|
||||
className="flex cursor-pointer items-center gap-3 rounded-lg p-2 hover:bg-accent/50"
|
||||
>
|
||||
<Checkbox
|
||||
checked={entryCollectionIds.has(collection.id)}
|
||||
onCheckedChange={(checked) =>
|
||||
handleToggle(collection.id, !!checked)
|
||||
}
|
||||
/>
|
||||
<span className="text-sm">{collection.name}</span>
|
||||
</label>
|
||||
))}
|
||||
{filtered.length === 0 && (
|
||||
<p className="py-4 text-center text-sm text-muted-foreground">
|
||||
No collections found.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
import { useState, useRef } from 'react';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
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 { useUpdateCollection } from '@/hooks/useCollections';
|
||||
import type { Collection } from '@/types';
|
||||
|
||||
interface CollectionEditDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
collection: Collection;
|
||||
}
|
||||
|
||||
export function CollectionEditDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
collection,
|
||||
}: CollectionEditDialogProps) {
|
||||
const [name, setName] = useState(collection.name);
|
||||
const [description, setDescription] = useState(collection.description || '');
|
||||
const [userRating, setUserRating] = useState(
|
||||
collection.user_rating?.toString() || ''
|
||||
);
|
||||
const [posterFile, setPosterFile] = useState<File | null>(null);
|
||||
const [backdropFile, setBackdropFile] = useState<File | null>(null);
|
||||
const [posterPreview, setPosterPreview] = useState<string | null>(null);
|
||||
const [backdropPreview, setBackdropPreview] = useState<string | null>(null);
|
||||
|
||||
const posterInputRef = useRef<HTMLInputElement>(null);
|
||||
const backdropInputRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
const updateCollection = useUpdateCollection();
|
||||
|
||||
const handlePosterChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (file) {
|
||||
setPosterFile(file);
|
||||
setPosterPreview(URL.createObjectURL(file));
|
||||
}
|
||||
};
|
||||
|
||||
const handleBackdropChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (file) {
|
||||
setBackdropFile(file);
|
||||
setBackdropPreview(URL.createObjectURL(file));
|
||||
}
|
||||
};
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('name', name);
|
||||
formData.append('description', description);
|
||||
formData.append('userRating', userRating || '0');
|
||||
|
||||
if (posterFile) {
|
||||
formData.append('poster', posterFile);
|
||||
}
|
||||
if (backdropFile) {
|
||||
formData.append('backdrop', backdropFile);
|
||||
}
|
||||
|
||||
updateCollection.mutate(
|
||||
{ id: collection.id, data: formData },
|
||||
{ onSuccess: () => onOpenChange(false) }
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-lg!">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Edit Collection</DialogTitle>
|
||||
</DialogHeader>
|
||||
<form onSubmit={handleSubmit} className="space-y-4 py-2">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="col-name">Name</Label>
|
||||
<Input
|
||||
id="col-name"
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="col-desc">Description</Label>
|
||||
<Textarea
|
||||
id="col-desc"
|
||||
value={description}
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
rows={3}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="col-rating">User Rating (0-10)</Label>
|
||||
<Input
|
||||
id="col-rating"
|
||||
type="number"
|
||||
min={0}
|
||||
max={10}
|
||||
step={0.1}
|
||||
value={userRating}
|
||||
onChange={(e) => setUserRating(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Media uploads */}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label>Poster</Label>
|
||||
<input
|
||||
ref={posterInputRef}
|
||||
type="file"
|
||||
accept="image/*"
|
||||
onChange={handlePosterChange}
|
||||
className="hidden"
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
className="w-full h-20 flex flex-col gap-1"
|
||||
onClick={() => posterInputRef.current?.click()}
|
||||
>
|
||||
{posterPreview ? (
|
||||
<img
|
||||
src={posterPreview}
|
||||
alt="Poster preview"
|
||||
className="h-14 w-auto rounded object-cover"
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
<ImageIcon className="h-5 w-5 text-muted-foreground" />
|
||||
<span className="text-xs text-muted-foreground">
|
||||
Upload Poster
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label>Backdrop</Label>
|
||||
<input
|
||||
ref={backdropInputRef}
|
||||
type="file"
|
||||
accept="image/*"
|
||||
onChange={handleBackdropChange}
|
||||
className="hidden"
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
className="w-full h-20 flex flex-col gap-1"
|
||||
onClick={() => backdropInputRef.current?.click()}
|
||||
>
|
||||
{backdropPreview ? (
|
||||
<img
|
||||
src={backdropPreview}
|
||||
alt="Backdrop preview"
|
||||
className="h-14 w-auto rounded object-cover"
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
<ImageIcon className="h-5 w-5 text-muted-foreground" />
|
||||
<span className="text-xs text-muted-foreground">
|
||||
Upload Backdrop
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DialogFooter>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
onClick={() => onOpenChange(false)}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button type="submit" disabled={updateCollection.isPending}>
|
||||
{updateCollection.isPending ? 'Saving...' : 'Save'}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { Button } from '@/components/ui/button';
|
||||
|
||||
interface ConfirmDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
title: string;
|
||||
description: string;
|
||||
confirmLabel?: string;
|
||||
cancelLabel?: string;
|
||||
onConfirm: () => void;
|
||||
variant?: 'default' | 'destructive';
|
||||
}
|
||||
|
||||
export function ConfirmDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
title,
|
||||
description,
|
||||
confirmLabel = 'Confirm',
|
||||
cancelLabel = 'Cancel',
|
||||
onConfirm,
|
||||
variant = 'default',
|
||||
}: ConfirmDialogProps) {
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>{title}</DialogTitle>
|
||||
<DialogDescription>{description}</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => onOpenChange(false)}>
|
||||
{cancelLabel}
|
||||
</Button>
|
||||
<Button
|
||||
variant={variant === 'destructive' ? 'destructive' : 'default'}
|
||||
onClick={onConfirm}
|
||||
>
|
||||
{confirmLabel}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
import { useState } from 'react';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||
import { Check, Trash2, Upload } from 'lucide-react';
|
||||
import { getMediaUrl } from '@/lib/api';
|
||||
import { entriesApi } from '@/api/entries';
|
||||
import { useUploadMedia } from '@/hooks/useEntries';
|
||||
import type { Media } from '@/types';
|
||||
|
||||
interface EntryMediaDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
entryId: number;
|
||||
medias: Media[];
|
||||
}
|
||||
|
||||
export function EntryMediaDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
entryId,
|
||||
medias,
|
||||
}: EntryMediaDialogProps) {
|
||||
const [activeTab, setActiveTab] = useState<string>('poster');
|
||||
const uploadMedia = useUploadMedia();
|
||||
|
||||
const filteredMedias = medias.filter((m) => m.type === activeTab);
|
||||
|
||||
const handleUpload = (type: string) => {
|
||||
const input = document.createElement('input');
|
||||
input.type = 'file';
|
||||
input.accept = 'image/*';
|
||||
input.onchange = async (e) => {
|
||||
const file = (e.target as HTMLInputElement).files?.[0];
|
||||
if (!file) return;
|
||||
const formData = new FormData();
|
||||
formData.append(type, file);
|
||||
uploadMedia.mutate({ id: entryId, formData });
|
||||
};
|
||||
input.click();
|
||||
};
|
||||
|
||||
const handleSelect = async (mediaId: number) => {
|
||||
await entriesApi.setMediaSelected(entryId, mediaId);
|
||||
};
|
||||
|
||||
const handleDelete = async (mediaId: number) => {
|
||||
await entriesApi.deleteMedia(entryId, mediaId);
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-2xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Entry Media</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
<Tabs value={activeTab} onValueChange={setActiveTab}>
|
||||
<TabsList>
|
||||
<TabsTrigger value="poster">Posters</TabsTrigger>
|
||||
<TabsTrigger value="backdrop">Backdrops</TabsTrigger>
|
||||
<TabsTrigger value="logo">Logos</TabsTrigger>
|
||||
</TabsList>
|
||||
|
||||
<TabsContent value={activeTab} className="mt-4">
|
||||
<div className="flex justify-end mb-3">
|
||||
<Button
|
||||
size="sm"
|
||||
onClick={() => handleUpload(activeTab)}
|
||||
disabled={uploadMedia.isPending}
|
||||
>
|
||||
<Upload className="mr-2 h-4 w-4" />
|
||||
Upload {activeTab}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<ScrollArea className="h-80">
|
||||
{filteredMedias.length === 0 ? (
|
||||
<p className="py-8 text-center text-sm text-muted-foreground">
|
||||
No {activeTab}s found.
|
||||
</p>
|
||||
) : (
|
||||
<div className="grid grid-cols-3 gap-3">
|
||||
{filteredMedias.map((media) => (
|
||||
<div
|
||||
key={media.id}
|
||||
className={`group relative overflow-hidden rounded-lg border-2 ${
|
||||
media.is_selected
|
||||
? 'border-primary'
|
||||
: 'border-transparent'
|
||||
}`}
|
||||
>
|
||||
<img
|
||||
src={getMediaUrl(
|
||||
'entries',
|
||||
`${activeTab}s`,
|
||||
'preview',
|
||||
media.path
|
||||
)}
|
||||
alt={activeTab}
|
||||
className="w-full object-cover"
|
||||
loading="lazy"
|
||||
/>
|
||||
<div className="absolute inset-0 flex items-center justify-center gap-2 bg-black/60 opacity-0 transition-opacity group-hover:opacity-100">
|
||||
<Button
|
||||
size="icon"
|
||||
variant="secondary"
|
||||
className="h-8 w-8"
|
||||
onClick={() => handleSelect(media.id)}
|
||||
>
|
||||
<Check className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button
|
||||
size="icon"
|
||||
variant="destructive"
|
||||
className="h-8 w-8"
|
||||
onClick={() => handleDelete(media.id)}
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
{media.is_selected && (
|
||||
<div className="absolute right-1 top-1 rounded-full bg-primary p-1">
|
||||
<Check className="h-3 w-3 text-primary-foreground" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</ScrollArea>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
import { useState } from 'react';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { z } from 'zod';
|
||||
import { format } from 'date-fns';
|
||||
import { CalendarIcon } from 'lucide-react';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import {
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
} from '@/components/ui/popover';
|
||||
import { Calendar } from '@/components/ui/calendar';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { useCreateEntrySeen, useUpdateEntrySeen } from '@/hooks/useEntrySeen';
|
||||
import { useCreateEpisodeSeen } from '@/hooks/useEpisodeSeen';
|
||||
import type { Entry, Season, EntrySeen } from '@/types';
|
||||
|
||||
const movieSeenSchema = z.object({
|
||||
date_seen: z.string().min(1, 'Date is required'),
|
||||
seen_with: z.string().optional(),
|
||||
});
|
||||
|
||||
const tvSeenSchema = z.object({
|
||||
season_id: z.string().min(1, 'Season is required'),
|
||||
episode_id: z.string().min(1, 'Episode is required'),
|
||||
date_seen: z.string().min(1, 'Date is required'),
|
||||
seen_with: z.string().optional(),
|
||||
});
|
||||
|
||||
interface EntrySeenDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
entry: Entry;
|
||||
seasons?: Season[];
|
||||
mode: 'add' | 'edit';
|
||||
editRecord?: EntrySeen;
|
||||
}
|
||||
|
||||
export function EntrySeenDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
entry,
|
||||
seasons,
|
||||
mode,
|
||||
editRecord,
|
||||
}: EntrySeenDialogProps) {
|
||||
const [date, setDate] = useState<Date | undefined>(
|
||||
editRecord?.date_seen ? new Date(editRecord.date_seen) : new Date()
|
||||
);
|
||||
const [selectedSeasonId, setSelectedSeasonId] = useState<string>('');
|
||||
|
||||
const isTV = entry.is_tvseries;
|
||||
const schema = isTV ? tvSeenSchema : movieSeenSchema;
|
||||
const seasonList = Array.isArray(seasons) ? seasons : [];
|
||||
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
setValue,
|
||||
formState: { errors },
|
||||
} = useForm({
|
||||
resolver: zodResolver(schema),
|
||||
defaultValues: {
|
||||
date_seen: editRecord?.date_seen || format(new Date(), 'yyyy-MM-dd'),
|
||||
seen_with: editRecord?.seen_with || '',
|
||||
season_id: '',
|
||||
episode_id: '',
|
||||
},
|
||||
});
|
||||
|
||||
const createEntrySeen = useCreateEntrySeen();
|
||||
const updateEntrySeen = useUpdateEntrySeen();
|
||||
const createEpisodeSeen = useCreateEpisodeSeen();
|
||||
|
||||
const selectedSeason = seasonList.find(
|
||||
(s) => s.id.toString() === selectedSeasonId
|
||||
);
|
||||
|
||||
const onSubmit = (data: Record<string, string | undefined>) => {
|
||||
if (isTV && data.episode_id) {
|
||||
createEpisodeSeen.mutate(
|
||||
{
|
||||
entry_id: entry.id,
|
||||
episode_id: parseInt(data.episode_id),
|
||||
date_seen: data.date_seen!,
|
||||
seen_with: data.seen_with || undefined,
|
||||
},
|
||||
{ onSuccess: () => onOpenChange(false) }
|
||||
);
|
||||
} else if (mode === 'edit' && editRecord) {
|
||||
updateEntrySeen.mutate(
|
||||
{
|
||||
id: editRecord.id,
|
||||
data: {
|
||||
entry_id: entry.id,
|
||||
date_seen: data.date_seen,
|
||||
seen_with: data.seen_with || undefined,
|
||||
},
|
||||
},
|
||||
{ onSuccess: () => onOpenChange(false) }
|
||||
);
|
||||
} else {
|
||||
createEntrySeen.mutate(
|
||||
{
|
||||
entry_id: entry.id,
|
||||
date_seen: data.date_seen!,
|
||||
seen_with: data.seen_with || undefined,
|
||||
},
|
||||
{ onSuccess: () => onOpenChange(false) }
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
{mode === 'edit' ? 'Edit Watch Record' : 'Mark as Watched'}
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
<form onSubmit={handleSubmit(onSubmit)} className="space-y-4 py-2">
|
||||
{/* TV specific fields */}
|
||||
{isTV && seasonList.length > 0 && (
|
||||
<>
|
||||
<div className="space-y-2">
|
||||
<Label>Season</Label>
|
||||
<Select
|
||||
value={selectedSeasonId}
|
||||
onValueChange={(v) => {
|
||||
setSelectedSeasonId(v);
|
||||
setValue('season_id', v);
|
||||
setValue('episode_id', '');
|
||||
}}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select season" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{seasonList.map((s) => (
|
||||
<SelectItem key={s.id} value={s.id.toString()}>
|
||||
{s.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{errors.season_id && (
|
||||
<p className="text-xs text-destructive">
|
||||
{errors.season_id.message}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{selectedSeason?.episodes && (
|
||||
<div className="space-y-2">
|
||||
<Label>Episode</Label>
|
||||
<Select onValueChange={(v) => setValue('episode_id', v)}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select episode" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{selectedSeason.episodes.map((ep) => (
|
||||
<SelectItem key={ep.id} value={ep.id.toString()}>
|
||||
E{ep.episode_number} - {ep.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{errors.episode_id && (
|
||||
<p className="text-xs text-destructive">
|
||||
{errors.episode_id.message}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Date picker */}
|
||||
<div className="space-y-2">
|
||||
<Label>Date Seen</Label>
|
||||
<Popover>
|
||||
<PopoverTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
className={cn(
|
||||
'w-full justify-start text-left font-normal',
|
||||
!date && 'text-muted-foreground'
|
||||
)}
|
||||
>
|
||||
<CalendarIcon className="mr-2 h-4 w-4" />
|
||||
{date ? format(date, 'PPP') : <span>Pick a date</span>}
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-auto p-0" align="start">
|
||||
<Calendar
|
||||
mode="single"
|
||||
selected={date}
|
||||
onSelect={(d) => {
|
||||
setDate(d);
|
||||
if (d) setValue('date_seen', format(d, 'yyyy-MM-dd'));
|
||||
}}
|
||||
initialFocus
|
||||
/>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
{errors.date_seen && (
|
||||
<p className="text-xs text-destructive">
|
||||
{errors.date_seen.message}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Seen with */}
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="seen_with">Seen With (optional)</Label>
|
||||
<Input id="seen_with" {...register('seen_with')} placeholder="e.g. John, Jane" />
|
||||
</div>
|
||||
|
||||
<DialogFooter>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => onOpenChange(false)}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button type="submit">
|
||||
{mode === 'edit' ? 'Save Changes' : 'Mark as Watched'}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Switch } from '@/components/ui/switch';
|
||||
import { useUpdateEntry } from '@/hooks/useEntries';
|
||||
import type { Entry } from '@/types';
|
||||
|
||||
interface EntrySettingsDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
entry: Entry;
|
||||
}
|
||||
|
||||
export function EntrySettingsDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
entry,
|
||||
}: EntrySettingsDialogProps) {
|
||||
const updateEntry = useUpdateEntry();
|
||||
|
||||
const handleToggle = (field: keyof Entry, value: boolean) => {
|
||||
updateEntry.mutate({ id: entry.id, data: { [field]: value } });
|
||||
};
|
||||
|
||||
const settings = [
|
||||
{ field: 'favorit' as const, label: 'Favorite' },
|
||||
{ field: 'hidden' as const, label: 'Hidden' },
|
||||
{ field: 'watchlist' as const, label: 'Watchlist' },
|
||||
];
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Entry Settings</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4 py-4">
|
||||
{settings.map(({ field, label }) => (
|
||||
<div key={field} className="flex items-center justify-between">
|
||||
<Label htmlFor={field}>{label}</Label>
|
||||
<Switch
|
||||
id={field}
|
||||
checked={!!entry[field]}
|
||||
onCheckedChange={(checked) => handleToggle(field, checked)}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { Outlet } from 'react-router-dom';
|
||||
import { Sidebar } from './Sidebar';
|
||||
|
||||
export function AppLayout() {
|
||||
return (
|
||||
<div className="flex min-h-screen">
|
||||
<Sidebar />
|
||||
<main className="ml-56 flex-1 overflow-y-auto">
|
||||
<div className="container mx-auto px-6 py-6">
|
||||
<Outlet />
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
import { NavLink } from 'react-router-dom';
|
||||
import {
|
||||
LayoutDashboard,
|
||||
Home,
|
||||
Library,
|
||||
ListVideo,
|
||||
FolderOpen,
|
||||
Image,
|
||||
CalendarDays,
|
||||
Users,
|
||||
Settings,
|
||||
Moon,
|
||||
Sun,
|
||||
Film,
|
||||
} from 'lucide-react';
|
||||
import { useThemeStore } from '@/stores/useThemeStore';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import {
|
||||
Tooltip,
|
||||
TooltipContent,
|
||||
TooltipTrigger,
|
||||
} from '@/components/ui/tooltip';
|
||||
|
||||
const mainNav = [
|
||||
{ to: '/dashboard', icon: LayoutDashboard, label: 'Dashboard' },
|
||||
{ to: '/', icon: Home, label: 'Home' },
|
||||
];
|
||||
|
||||
const libraryNav = [
|
||||
{ to: '/library', icon: Library, label: 'Library' },
|
||||
{ to: '/watchlist', icon: ListVideo, label: 'Watchlist' },
|
||||
{ to: '/collections', icon: FolderOpen, label: 'Collections' },
|
||||
{ to: '/media', icon: Image, label: 'Media' },
|
||||
];
|
||||
|
||||
const otherNav = [
|
||||
{ to: '/calendar', icon: CalendarDays, label: 'Calendar' },
|
||||
{ to: '/people', icon: Users, label: 'People' },
|
||||
];
|
||||
|
||||
function NavItem({
|
||||
to,
|
||||
icon: Icon,
|
||||
label,
|
||||
}: {
|
||||
to: string;
|
||||
icon: React.ComponentType<{ className?: string }>;
|
||||
label: string;
|
||||
}) {
|
||||
return (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<NavLink
|
||||
to={to}
|
||||
end={to === '/'}
|
||||
className={({ isActive }) =>
|
||||
`flex items-center gap-3 rounded-lg px-3 py-2 text-sm transition-colors ${
|
||||
isActive
|
||||
? 'bg-sidebar-accent text-sidebar-primary font-medium'
|
||||
: 'text-sidebar-foreground/70 hover:bg-sidebar-accent/50 hover:text-sidebar-foreground'
|
||||
}`
|
||||
}
|
||||
>
|
||||
<Icon className="h-4 w-4 shrink-0" />
|
||||
<span>{label}</span>
|
||||
</NavLink>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="right">{label}</TooltipContent>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
|
||||
export function Sidebar() {
|
||||
const { theme, toggleTheme } = useThemeStore();
|
||||
|
||||
return (
|
||||
<aside className="fixed inset-y-0 left-0 z-50 flex w-56 flex-col border-r border-sidebar-border bg-sidebar">
|
||||
{/* Logo */}
|
||||
<div className="flex h-14 items-center gap-2 px-4">
|
||||
<Film className="h-6 w-6 text-sidebar-primary" />
|
||||
<span className="text-lg font-bold text-sidebar-foreground">
|
||||
Showy
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<Separator className="bg-sidebar-border" />
|
||||
|
||||
{/* Nav */}
|
||||
<nav className="flex-1 space-y-1 overflow-y-auto px-3 py-4">
|
||||
<p className="mb-2 px-3 text-xs font-semibold uppercase tracking-wider text-sidebar-foreground/50">
|
||||
Main
|
||||
</p>
|
||||
{mainNav.map((item) => (
|
||||
<NavItem key={item.to} {...item} />
|
||||
))}
|
||||
|
||||
<Separator className="my-3 bg-sidebar-border" />
|
||||
|
||||
<p className="mb-2 px-3 text-xs font-semibold uppercase tracking-wider text-sidebar-foreground/50">
|
||||
Library
|
||||
</p>
|
||||
{libraryNav.map((item) => (
|
||||
<NavItem key={item.to} {...item} />
|
||||
))}
|
||||
|
||||
<Separator className="my-3 bg-sidebar-border" />
|
||||
|
||||
<p className="mb-2 px-3 text-xs font-semibold uppercase tracking-wider text-sidebar-foreground/50">
|
||||
Other
|
||||
</p>
|
||||
{otherNav.map((item) => (
|
||||
<NavItem key={item.to} {...item} />
|
||||
))}
|
||||
</nav>
|
||||
|
||||
{/* Bottom actions */}
|
||||
<div className="border-t border-sidebar-border px-3 py-3 space-y-1">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="w-full justify-start gap-3 text-sidebar-foreground/70 hover:bg-sidebar-accent/50 hover:text-sidebar-foreground"
|
||||
onClick={toggleTheme}
|
||||
>
|
||||
{theme === 'dark' ? (
|
||||
<Sun className="h-4 w-4" />
|
||||
) : (
|
||||
<Moon className="h-4 w-4" />
|
||||
)}
|
||||
<span>{theme === 'dark' ? 'Light Mode' : 'Dark Mode'}</span>
|
||||
</Button>
|
||||
<NavItem to="/settings" icon={Settings} label="Settings" />
|
||||
</div>
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user