From d8b95cb3e9faf825e5205cd56e1973fcfb858be0 Mon Sep 17 00:00:00 2001 From: X4Lo Date: Tue, 23 Jun 2026 04:00:52 +0100 Subject: [PATCH] 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. --- .../components/dialogs/EntrySeenDialog.tsx | 196 ++++++++++-------- 1 file changed, 115 insertions(+), 81 deletions(-) diff --git a/react_frontend/src/components/dialogs/EntrySeenDialog.tsx b/react_frontend/src/components/dialogs/EntrySeenDialog.tsx index 991bf13..7cca745 100644 --- a/react_frontend/src/components/dialogs/EntrySeenDialog.tsx +++ b/react_frontend/src/components/dialogs/EntrySeenDialog.tsx @@ -1,36 +1,36 @@ -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 { Loader2 } from "lucide-react"; +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 { Loader2 } 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"; +} from '@/components/ui/dialog'; +import { Button } from '@/components/ui/button'; +import { Input } from '@/components/ui/input'; +import { Label } from '@/components/ui/label'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, -} from "@/components/ui/select"; -import { useCreateEntrySeen, useUpdateEntrySeen } from "@/hooks/useEntrySeen"; -import { useCreateEpisodeSeen } from "@/hooks/useEpisodeSeen"; -import type { Entry, Season, EntrySeen, SeenAccuracy } from "@/types"; +} from '@/components/ui/select'; +import { useCreateEntrySeen, useUpdateEntrySeen } from '@/hooks/useEntrySeen'; +import { useCreateEpisodeSeen } from '@/hooks/useEpisodeSeen'; +import type { Entry, Season, EntrySeen, SeenAccuracy } from '@/types'; const seenSchema = z.object({ season_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(), - accuracy: z.enum(["EXACT", "ESTIMATED", "UNKNOWN"]).default("EXACT"), + accuracy: z.enum(['EXACT', 'ESTIMATED', 'UNKNOWN']).default('EXACT'), }); interface EntrySeenDialogProps { @@ -38,7 +38,7 @@ interface EntrySeenDialogProps { onOpenChange: (open: boolean) => void; entry: Entry; seasons?: Season[]; - mode: "add" | "edit"; + mode: 'add' | 'edit'; editRecord?: EntrySeen; } @@ -50,7 +50,7 @@ export function EntrySeenDialog({ mode, editRecord, }: EntrySeenDialogProps) { - const [selectedSeasonId, setSelectedSeasonId] = useState(""); + const [selectedSeasonId, setSelectedSeasonId] = useState(''); const isTV = entry.is_tvseries; const seasonList = Array.isArray(seasons) ? seasons : []; @@ -64,15 +64,15 @@ export function EntrySeenDialog({ } = useForm({ resolver: zodResolver(seenSchema), defaultValues: { - date_seen: editRecord?.date_seen || format(new Date(), "yyyy-MM-dd"), - seen_with: editRecord?.seen_with || "", - season_id: "", - episode_id: "", - accuracy: (editRecord?.accuracy || "EXACT") as SeenAccuracy, + date_seen: editRecord?.date_seen || format(new Date(), 'yyyy-MM-dd'), + seen_with: editRecord?.seen_with || '', + season_id: '', + episode_id: '', + accuracy: (editRecord?.accuracy || 'EXACT') as SeenAccuracy, }, }); - const accuracyValue = watch("accuracy") as SeenAccuracy; + const accuracyValue = watch('accuracy') as SeenAccuracy; const createEntrySeen = useCreateEntrySeen(); const updateEntrySeen = useUpdateEntrySeen(); @@ -83,7 +83,7 @@ export function EntrySeenDialog({ ); const onSubmit = (data: Record) => { - const acc = (data.accuracy as SeenAccuracy) || "EXACT"; + const acc = (data.accuracy as SeenAccuracy) || 'EXACT'; if (isTV && data.episode_id) { createEpisodeSeen.mutate( { @@ -95,7 +95,7 @@ export function EntrySeenDialog({ }, { onSuccess: () => onOpenChange(false) }, ); - } else if (mode === "edit" && editRecord) { + } else if (mode === 'edit' && editRecord) { updateEntrySeen.mutate( { id: editRecord.id, @@ -126,47 +126,76 @@ export function EntrySeenDialog({ - {mode === "edit" ? "Edit Watch Record" : "Mark as Watched"} + {mode === 'edit' ? 'Edit Watch Record' : 'Mark as Watched'}
{/* TV specific fields */} {isTV && seasonList.length > 0 && ( <> -
- - - {errors.season_id && ( -

- {errors.season_id.message} -

- )} -
+
+
+ + +
- {selectedSeason?.episodes && (
- setValue('episode_id', v)} + disabled={!selectedSeason} + > + + + {(() => { + 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; + })()} + {selectedSeason.episodes.map((ep) => ( @@ -176,36 +205,41 @@ export function EntrySeenDialog({ ))} - {errors.episode_id && ( -

- {errors.episode_id.message} -

- )}
+
+ + {errors.season_id && ( +

+ {errors.season_id.message} +

+ )} + {errors.episode_id && ( +

+ {errors.episode_id.message} +

)} )} {/* Date + Accuracy */} -
- -
+
+
+ { - setValue("date_seen", e.target.value); - setDate( - e.target.value ? new Date(e.target.value) : undefined, - ); + setValue('date_seen', e.target.value); }} - className="flex-1" /> +
+
+
- {errors.date_seen && ( -

- {errors.date_seen.message} -

- )}
+ {errors.date_seen && ( +

+ {errors.date_seen.message} +

+ )} {/* Seen with */}
@@ -258,7 +292,7 @@ export function EntrySeenDialog({ createEpisodeSeen.isPending) && ( )} - {mode === "edit" ? "Save Changes" : "Mark as Watched"} + {mode === 'edit' ? 'Save Changes' : 'Mark as Watched'}