Fix EntrySeenDialog layout and select display values

Season/Episode on same row with grid-cols-2, Date/Accuracy same row.
Selects show labels instead of IDs. Season 0 shown as Specials,
sorted to bottom. All selects stretch full width.
This commit is contained in:
X4Lo committed 2026-06-23 04:00:52 +01:00
1 parent b001ee2240
commit d8b95cb3e9
1 file changed
+90 -56
@@ -1,36 +1,36 @@
import { useState } from "react"; import { useState } from 'react';
import { useForm } from "react-hook-form"; import { useForm } from 'react-hook-form';
import { zodResolver } from "@hookform/resolvers/zod"; import { zodResolver } from '@hookform/resolvers/zod';
import { z } from "zod"; import { z } from 'zod';
import { format } from "date-fns"; import { format } from 'date-fns';
import { Loader2 } from "lucide-react"; import { Loader2 } from 'lucide-react';
import { import {
Dialog, Dialog,
DialogContent, DialogContent,
DialogFooter, DialogFooter,
DialogHeader, DialogHeader,
DialogTitle, DialogTitle,
} from "@/components/ui/dialog"; } from '@/components/ui/dialog';
import { Button } from "@/components/ui/button"; import { Button } from '@/components/ui/button';
import { Input } from "@/components/ui/input"; import { Input } from '@/components/ui/input';
import { Label } from "@/components/ui/label"; import { Label } from '@/components/ui/label';
import { import {
Select, Select,
SelectContent, SelectContent,
SelectItem, SelectItem,
SelectTrigger, SelectTrigger,
SelectValue, SelectValue,
} from "@/components/ui/select"; } from '@/components/ui/select';
import { useCreateEntrySeen, useUpdateEntrySeen } from "@/hooks/useEntrySeen"; import { useCreateEntrySeen, useUpdateEntrySeen } from '@/hooks/useEntrySeen';
import { useCreateEpisodeSeen } from "@/hooks/useEpisodeSeen"; import { useCreateEpisodeSeen } from '@/hooks/useEpisodeSeen';
import type { Entry, Season, EntrySeen, SeenAccuracy } from "@/types"; import type { Entry, Season, EntrySeen, SeenAccuracy } from '@/types';
const seenSchema = z.object({ const seenSchema = z.object({
season_id: z.string().optional(), season_id: z.string().optional(),
episode_id: z.string().optional(), episode_id: z.string().optional(),
date_seen: z.string().min(1, "Date is required"), date_seen: z.string().min(1, 'Date is required'),
seen_with: z.string().optional(), seen_with: z.string().optional(),
accuracy: z.enum(["EXACT", "ESTIMATED", "UNKNOWN"]).default("EXACT"), accuracy: z.enum(['EXACT', 'ESTIMATED', 'UNKNOWN']).default('EXACT'),
}); });
interface EntrySeenDialogProps { interface EntrySeenDialogProps {
@@ -38,7 +38,7 @@ interface EntrySeenDialogProps {
onOpenChange: (open: boolean) => void; onOpenChange: (open: boolean) => void;
entry: Entry; entry: Entry;
seasons?: Season[]; seasons?: Season[];
mode: "add" | "edit"; mode: 'add' | 'edit';
editRecord?: EntrySeen; editRecord?: EntrySeen;
} }
@@ -50,7 +50,7 @@ export function EntrySeenDialog({
mode, mode,
editRecord, editRecord,
}: EntrySeenDialogProps) { }: EntrySeenDialogProps) {
const [selectedSeasonId, setSelectedSeasonId] = useState<string>(""); const [selectedSeasonId, setSelectedSeasonId] = useState<string>('');
const isTV = entry.is_tvseries; const isTV = entry.is_tvseries;
const seasonList = Array.isArray(seasons) ? seasons : []; const seasonList = Array.isArray(seasons) ? seasons : [];
@@ -64,15 +64,15 @@ export function EntrySeenDialog({
} = useForm({ } = useForm({
resolver: zodResolver(seenSchema), resolver: zodResolver(seenSchema),
defaultValues: { defaultValues: {
date_seen: editRecord?.date_seen || format(new Date(), "yyyy-MM-dd"), date_seen: editRecord?.date_seen || format(new Date(), 'yyyy-MM-dd'),
seen_with: editRecord?.seen_with || "", seen_with: editRecord?.seen_with || '',
season_id: "", season_id: '',
episode_id: "", episode_id: '',
accuracy: (editRecord?.accuracy || "EXACT") as SeenAccuracy, accuracy: (editRecord?.accuracy || 'EXACT') as SeenAccuracy,
}, },
}); });
const accuracyValue = watch("accuracy") as SeenAccuracy; const accuracyValue = watch('accuracy') as SeenAccuracy;
const createEntrySeen = useCreateEntrySeen(); const createEntrySeen = useCreateEntrySeen();
const updateEntrySeen = useUpdateEntrySeen(); const updateEntrySeen = useUpdateEntrySeen();
@@ -83,7 +83,7 @@ export function EntrySeenDialog({
); );
const onSubmit = (data: Record<string, string | undefined>) => { const onSubmit = (data: Record<string, string | undefined>) => {
const acc = (data.accuracy as SeenAccuracy) || "EXACT"; const acc = (data.accuracy as SeenAccuracy) || 'EXACT';
if (isTV && data.episode_id) { if (isTV && data.episode_id) {
createEpisodeSeen.mutate( createEpisodeSeen.mutate(
{ {
@@ -95,7 +95,7 @@ export function EntrySeenDialog({
}, },
{ onSuccess: () => onOpenChange(false) }, { onSuccess: () => onOpenChange(false) },
); );
} else if (mode === "edit" && editRecord) { } else if (mode === 'edit' && editRecord) {
updateEntrySeen.mutate( updateEntrySeen.mutate(
{ {
id: editRecord.id, id: editRecord.id,
@@ -126,47 +126,76 @@ export function EntrySeenDialog({
<DialogContent className="sm:max-w-md"> <DialogContent className="sm:max-w-md">
<DialogHeader> <DialogHeader>
<DialogTitle> <DialogTitle>
{mode === "edit" ? "Edit Watch Record" : "Mark as Watched"} {mode === 'edit' ? 'Edit Watch Record' : 'Mark as Watched'}
</DialogTitle> </DialogTitle>
</DialogHeader> </DialogHeader>
<form onSubmit={handleSubmit(onSubmit)} className="space-y-4 py-2"> <form onSubmit={handleSubmit(onSubmit)} className="space-y-4 py-2">
{/* TV specific fields */} {/* TV specific fields */}
{isTV && seasonList.length > 0 && ( {isTV && seasonList.length > 0 && (
<> <>
<div className="grid grid-cols-2 gap-3">
<div className="space-y-2"> <div className="space-y-2">
<Label>Season</Label> <Label>Season</Label>
<Select <Select
value={selectedSeasonId} value={selectedSeasonId}
onValueChange={(v) => { onValueChange={(v) => {
setSelectedSeasonId(v); setSelectedSeasonId(v);
setValue("season_id", v); setValue('season_id', v);
setValue("episode_id", ""); setValue('episode_id', '');
}} }}
> >
<SelectTrigger> <SelectTrigger className="w-full">
<SelectValue placeholder="Select season" /> <SelectValue placeholder="Select season">
{selectedSeasonId
? (() => {
const s = seasonList.find(
(s) => s.id.toString() === selectedSeasonId,
);
return s?.season_number === 0
? 'Specials'
: `Season ${s?.season_number}`;
})()
: null}
</SelectValue>
</SelectTrigger> </SelectTrigger>
<SelectContent> <SelectContent>
{seasonList.map((s) => ( {[...seasonList]
.sort((a, b) => {
if (a.season_number === 0) return 1;
if (b.season_number === 0) return -1;
return a.season_number - b.season_number;
})
.map((s) => (
<SelectItem key={s.id} value={s.id.toString()}> <SelectItem key={s.id} value={s.id.toString()}>
{s.name} {s.season_number === 0
? 'Specials'
: `Season ${s.season_number}`}
</SelectItem> </SelectItem>
))} ))}
</SelectContent> </SelectContent>
</Select> </Select>
{errors.season_id && (
<p className="text-xs text-destructive">
{errors.season_id.message}
</p>
)}
</div> </div>
{selectedSeason?.episodes && (
<div className="space-y-2"> <div className="space-y-2">
<Label>Episode</Label> <Label>Episode</Label>
<Select onValueChange={(v) => setValue("episode_id", v)}> <Select
<SelectTrigger> value={watch('episode_id')}
<SelectValue placeholder="Select episode" /> onValueChange={(v) => setValue('episode_id', v)}
disabled={!selectedSeason}
>
<SelectTrigger className="w-full">
<SelectValue placeholder="Select episode">
{(() => {
const epId = watch('episode_id');
if (!epId || !selectedSeason?.episodes) return null;
const ep = selectedSeason.episodes.find(
(e) => e.id.toString() === epId,
);
return ep
? `E${ep.episode_number} - ${ep.name}`
: null;
})()}
</SelectValue>
</SelectTrigger> </SelectTrigger>
<SelectContent> <SelectContent>
{selectedSeason.episodes.map((ep) => ( {selectedSeason.episodes.map((ep) => (
@@ -176,36 +205,41 @@ export function EntrySeenDialog({
))} ))}
</SelectContent> </SelectContent>
</Select> </Select>
</div>
</div>
{errors.season_id && (
<p className="text-xs text-destructive">
{errors.season_id.message}
</p>
)}
{errors.episode_id && ( {errors.episode_id && (
<p className="text-xs text-destructive"> <p className="text-xs text-destructive">
{errors.episode_id.message} {errors.episode_id.message}
</p> </p>
)} )}
</div>
)}
</> </>
)} )}
{/* Date + Accuracy */} {/* Date + Accuracy */}
<div className="grid grid-cols-2 gap-3">
<div className="space-y-2"> <div className="space-y-2">
<Label>Date Seen</Label> <Label>Date Seen</Label>
<div className="flex items-center gap-2">
<Input <Input
type="date" type="date"
value={watch("date_seen")} value={watch('date_seen')}
onChange={(e) => { onChange={(e) => {
setValue("date_seen", e.target.value); setValue('date_seen', e.target.value);
setDate(
e.target.value ? new Date(e.target.value) : undefined,
);
}} }}
className="flex-1"
/> />
</div>
<div className="space-y-2">
<Label>Accuracy</Label>
<Select <Select
value={accuracyValue} value={accuracyValue}
onValueChange={(v) => setValue("accuracy", v as SeenAccuracy)} onValueChange={(v) => setValue('accuracy', v as SeenAccuracy)}
> >
<SelectTrigger className="w-[120px] shrink-0"> <SelectTrigger className="w-full">
<SelectValue /> <SelectValue />
</SelectTrigger> </SelectTrigger>
<SelectContent> <SelectContent>
@@ -215,19 +249,19 @@ export function EntrySeenDialog({
</SelectContent> </SelectContent>
</Select> </Select>
</div> </div>
</div>
{errors.date_seen && ( {errors.date_seen && (
<p className="text-xs text-destructive"> <p className="text-xs text-destructive">
{errors.date_seen.message} {errors.date_seen.message}
</p> </p>
)} )}
</div>
{/* Seen with */} {/* Seen with */}
<div className="space-y-2"> <div className="space-y-2">
<Label htmlFor="seen_with">Seen With (optional)</Label> <Label htmlFor="seen_with">Seen With (optional)</Label>
<Input <Input
id="seen_with" id="seen_with"
{...register("seen_with")} {...register('seen_with')}
placeholder="e.g. John, Jane" placeholder="e.g. John, Jane"
/> />
</div> </div>
@@ -258,7 +292,7 @@ export function EntrySeenDialog({
createEpisodeSeen.isPending) && ( createEpisodeSeen.isPending) && (
<Loader2 className="mr-2 h-4 w-4 animate-spin" /> <Loader2 className="mr-2 h-4 w-4 animate-spin" />
)} )}
{mode === "edit" ? "Save Changes" : "Mark as Watched"} {mode === 'edit' ? 'Save Changes' : 'Mark as Watched'}
</Button> </Button>
</DialogFooter> </DialogFooter>
</form> </form>