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,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>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user