Files
Showy/react_frontend/src/components/dialogs/EntrySettingsDialog.tsx
T
X4Lo 72600cbc5d Fix collection images and entry settings toggles
- Show the uploaded backdrop on the collection details page; it only
  looked at the TMDB backdrop and ignored the collection's media
- Fall back to the first entry's poster for collections without a poster
  on both the collections grid and the details page
- Read the live entry from the library store in EntrySettingsDialog so
  toggles reflect the new value instead of a stale prop snapshot
2026-11-03 16:25:12 +00:00

98 lines
3.2 KiB
TypeScript

import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import { Label } from "@/components/ui/label";
import { Switch } from "@/components/ui/switch";
import { Separator } from "@/components/ui/separator";
import { useUpdateEntry, useUpdateEntryRatings } from "@/hooks/useEntries";
import { StarRating } from "@/components/ui/star-rating";
import { useLibraryStore } from "@/stores/useLibraryStore";
import type { Entry } from "@/types";
interface EntrySettingsDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
entry: Entry;
}
export function EntrySettingsDialog({
open,
onOpenChange,
entry: entryProp,
}: EntrySettingsDialogProps) {
// The entry prop can be a stale snapshot (e.g. from a collection query), so
// read the live copy from the library store, which updates on every mutation.
const storeEntry = useLibraryStore((s) => s.entries.get(entryProp.id));
const entry = storeEntry ? { ...entryProp, ...storeEntry } : entryProp;
const updateEntry = useUpdateEntry();
const updateRatings = useUpdateEntryRatings();
const handleToggle = (field: keyof Entry, value: boolean) => {
updateEntry.mutate({ id: entry.id, data: { [field]: value } });
};
const boolSettings = [
{ field: "favorit" as const, label: "Favorite" },
{ field: "hidden" as const, label: "Hidden" },
{ field: "watchlist" as const, label: "Watchlist" },
{ field: "show_in_calendar" as const, label: "Show in Calendar" },
{ field: "auto_sync" as const, label: "Auto Sync" },
];
const userRating = entry.entryRatings?.user_rating ?? 0;
const handleRatingChange = (rating: number) => {
updateRatings.mutate({
id: entry.id,
ratings: { id: entry.entryRatings?.id, user_rating: rating || null },
});
};
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-md">
<DialogHeader>
<DialogTitle>Entry Settings</DialogTitle>
<p className="text-sm text-muted-foreground line-clamp-1">
{entry.title}
</p>
</DialogHeader>
<div className="space-y-1 py-2">
{boolSettings.map(({ field, label }) => (
<div
key={field}
className="flex items-center justify-between rounded-lg px-1 py-2.5"
>
<Label htmlFor={field} className="cursor-pointer">
{label}
</Label>
<Switch
id={field}
checked={!!entry[field]}
onCheckedChange={(checked) => handleToggle(field, checked)}
/>
</div>
))}
<Separator className="my-2" />
<div className="space-y-2 rounded-lg px-1 py-2.5">
<Label>Your Rating</Label>
<div className="flex items-center gap-3">
<StarRating
value={userRating}
onChange={handleRatingChange}
size="sm"
/>
<span className="text-sm text-muted-foreground tabular-nums">
{userRating > 0 ? `${userRating}/10` : "—"}
</span>
</div>
</div>
</div>
</DialogContent>
</Dialog>
);
}