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:
1 parent
b001ee2240
commit
d8b95cb3e9
1 file changed
+90
-56
@@ -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<string>("");
|
||||
const [selectedSeasonId, setSelectedSeasonId] = useState<string>('');
|
||||
|
||||
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<string, string | undefined>) => {
|
||||
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({
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
{mode === "edit" ? "Edit Watch Record" : "Mark as Watched"}
|
||||
{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="grid grid-cols-2 gap-3">
|
||||
<div className="space-y-2">
|
||||
<Label>Season</Label>
|
||||
<Select
|
||||
value={selectedSeasonId}
|
||||
onValueChange={(v) => {
|
||||
setSelectedSeasonId(v);
|
||||
setValue("season_id", v);
|
||||
setValue("episode_id", "");
|
||||
setValue('season_id', v);
|
||||
setValue('episode_id', '');
|
||||
}}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select season" />
|
||||
<SelectTrigger className="w-full">
|
||||
<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>
|
||||
<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()}>
|
||||
{s.name}
|
||||
{s.season_number === 0
|
||||
? 'Specials'
|
||||
: `Season ${s.season_number}`}
|
||||
</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" />
|
||||
<Select
|
||||
value={watch('episode_id')}
|
||||
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>
|
||||
<SelectContent>
|
||||
{selectedSeason.episodes.map((ep) => (
|
||||
@@ -176,36 +205,41 @@ export function EntrySeenDialog({
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{errors.season_id && (
|
||||
<p className="text-xs text-destructive">
|
||||
{errors.season_id.message}
|
||||
</p>
|
||||
)}
|
||||
{errors.episode_id && (
|
||||
<p className="text-xs text-destructive">
|
||||
{errors.episode_id.message}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Date + Accuracy */}
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div className="space-y-2">
|
||||
<Label>Date Seen</Label>
|
||||
<div className="flex items-center gap-2">
|
||||
<Input
|
||||
type="date"
|
||||
value={watch("date_seen")}
|
||||
value={watch('date_seen')}
|
||||
onChange={(e) => {
|
||||
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"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label>Accuracy</Label>
|
||||
<Select
|
||||
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 />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
@@ -215,19 +249,19 @@ export function EntrySeenDialog({
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
{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")}
|
||||
{...register('seen_with')}
|
||||
placeholder="e.g. John, Jane"
|
||||
/>
|
||||
</div>
|
||||
@@ -258,7 +292,7 @@ export function EntrySeenDialog({
|
||||
createEpisodeSeen.isPending) && (
|
||||
<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>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
|
||||
Reference in new issue
Block a user