Fix EntryCard add to library redirecting to entry
Remove navigate on successful createEntry so the user stays on the current page after adding from a card
This commit is contained in:
1 parent
4d6b235ddc
commit
b117b6bb98
1 file changed
+43
-47
@@ -1,5 +1,5 @@
|
||||
import { useState } from 'react';
|
||||
import { Link, useNavigate } from 'react-router-dom';
|
||||
import { useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import {
|
||||
Plus,
|
||||
Star,
|
||||
@@ -16,48 +16,48 @@ import {
|
||||
ImageIcon,
|
||||
Settings,
|
||||
BookmarkCheck,
|
||||
} from 'lucide-react';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
} from "lucide-react";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import { getPosterUrl, getYear, formatRuntime } from '@/lib/media-utils';
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { getPosterUrl, getYear, formatRuntime } from "@/lib/media-utils";
|
||||
import {
|
||||
useCreateEntry,
|
||||
useDeleteEntry,
|
||||
useUpdateEntry,
|
||||
useRefreshEntry,
|
||||
useEntrySeasons,
|
||||
} from '@/hooks/useEntries';
|
||||
import { useEntrySeenByEntry, useDeleteEntrySeen } from '@/hooks/useEntrySeen';
|
||||
import { useLibraryStore } from '@/stores/useLibraryStore';
|
||||
import { ConfirmDialog } from '@/components/dialogs/ConfirmDialog';
|
||||
import { EntrySeenDialog } from '@/components/dialogs/EntrySeenDialog';
|
||||
import { RatingDialog } from '@/components/dialogs/RatingDialog';
|
||||
import { MovieWatchHistoryDialog } from '@/components/dialogs/MovieWatchHistoryDialog';
|
||||
import { AddEntryToCollectionDialog } from '@/components/dialogs/AddEntryToCollectionDialog';
|
||||
import { EntryMediaDialog } from '@/components/dialogs/EntryMediaDialog';
|
||||
import { EntrySettingsDialog } from '@/components/dialogs/EntrySettingsDialog';
|
||||
} from "@/hooks/useEntries";
|
||||
import { useEntrySeenByEntry, useDeleteEntrySeen } from "@/hooks/useEntrySeen";
|
||||
import { useLibraryStore } from "@/stores/useLibraryStore";
|
||||
import { ConfirmDialog } from "@/components/dialogs/ConfirmDialog";
|
||||
import { EntrySeenDialog } from "@/components/dialogs/EntrySeenDialog";
|
||||
import { RatingDialog } from "@/components/dialogs/RatingDialog";
|
||||
import { MovieWatchHistoryDialog } from "@/components/dialogs/MovieWatchHistoryDialog";
|
||||
import { AddEntryToCollectionDialog } from "@/components/dialogs/AddEntryToCollectionDialog";
|
||||
import { EntryMediaDialog } from "@/components/dialogs/EntryMediaDialog";
|
||||
import { EntrySettingsDialog } from "@/components/dialogs/EntrySettingsDialog";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import type { Entry, TmdbEntry } from '@/types';
|
||||
} from "@/components/ui/dialog";
|
||||
import type { Entry, TmdbEntry } from "@/types";
|
||||
|
||||
const CARD_WATCH_STATUSES = [
|
||||
{ value: 'plan_to_watch', label: 'Plan to Watch' },
|
||||
{ value: 'watching', label: 'Watching' },
|
||||
{ value: 'completed', label: 'Completed' },
|
||||
{ value: 'on_hold', label: 'On Hold' },
|
||||
{ value: 'dropped', label: 'Dropped' },
|
||||
{ value: "plan_to_watch", label: "Plan to Watch" },
|
||||
{ value: "watching", label: "Watching" },
|
||||
{ value: "completed", label: "Completed" },
|
||||
{ value: "on_hold", label: "On Hold" },
|
||||
{ value: "dropped", label: "Dropped" },
|
||||
];
|
||||
|
||||
interface EntryCardProps {
|
||||
@@ -91,7 +91,6 @@ export function EntryCard({
|
||||
const [showSettingsDialog, setShowSettingsDialog] = useState(false);
|
||||
const [dropdownOpen, setDropdownOpen] = useState(false);
|
||||
const [showStatusDialog, setShowStatusDialog] = useState(false);
|
||||
const navigate = useNavigate();
|
||||
const createEntry = useCreateEntry();
|
||||
const deleteEntry = useDeleteEntry();
|
||||
const updateEntry = useUpdateEntry();
|
||||
@@ -116,7 +115,7 @@ export function EntryCard({
|
||||
|
||||
// Resolve display data
|
||||
const title =
|
||||
displayEntry?.title || tmdbEntry?.title || tmdbEntry?.name || 'Untitled';
|
||||
displayEntry?.title || tmdbEntry?.title || tmdbEntry?.name || "Untitled";
|
||||
const year = displayEntry
|
||||
? getYear(displayEntry.release_date)
|
||||
: getYear(tmdbEntry?.release_date || tmdbEntry?.first_air_date || null);
|
||||
@@ -127,32 +126,29 @@ export function EntryCard({
|
||||
const runtime =
|
||||
displayEntry && !displayEntry.is_tvseries
|
||||
? formatRuntime(displayEntry.runtime)
|
||||
: '';
|
||||
: "";
|
||||
const isTv =
|
||||
displayEntry?.is_tvseries ||
|
||||
tmdbEntry?.media_type === 'tv' ||
|
||||
tmdbEntry?.media_type === "tv" ||
|
||||
!!tmdbEntry?.name;
|
||||
|
||||
const posterUrl = displayEntry
|
||||
? getPosterUrl(displayEntry)
|
||||
: tmdbEntry?.poster_path
|
||||
? `https://image.tmdb.org/t/p/w342${tmdbEntry.poster_path}`
|
||||
: '/images/default-poster.png';
|
||||
: "/images/default-poster.png";
|
||||
|
||||
const entryLink = displayEntry
|
||||
? `/entry/${displayEntry.id}`
|
||||
: tmdbEntry
|
||||
? `/entry/tmdb/${isTv ? 'tv' : 'movie'}/${tmdbEntry.id}`
|
||||
? `/entry/tmdb/${isTv ? "tv" : "movie"}/${tmdbEntry.id}`
|
||||
: undefined;
|
||||
|
||||
const handleAdd = (e: React.MouseEvent) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
if (!tmdbEntry) return;
|
||||
createEntry.mutate(
|
||||
{ tmdb_id: tmdbEntry.id, is_tvserie: isTv },
|
||||
{ onSuccess: (newEntry) => navigate(`/entry/${newEntry.id}`) },
|
||||
);
|
||||
createEntry.mutate({ tmdb_id: tmdbEntry.id, is_tvserie: isTv });
|
||||
};
|
||||
|
||||
const confirmRemove = () => {
|
||||
@@ -189,7 +185,7 @@ export function EntryCard({
|
||||
src={posterUrl}
|
||||
alt={title}
|
||||
className={`h-full w-full object-cover transition-all duration-300 group-hover:scale-105 ${
|
||||
grayOutUnseen && !isSeen ? 'grayscale opacity-40' : ''
|
||||
grayOutUnseen && !isSeen ? "grayscale opacity-40" : ""
|
||||
}`}
|
||||
loading="lazy"
|
||||
/>
|
||||
@@ -209,7 +205,7 @@ export function EntryCard({
|
||||
{/* Quick actions button – top right, shown on hover */}
|
||||
{isInLibrary && (
|
||||
<div
|
||||
className={`absolute right-2 top-2 z-20 transition-opacity ${dropdownOpen ? 'opacity-100' : 'opacity-0 group-hover:opacity-100'}`}
|
||||
className={`absolute right-2 top-2 z-20 transition-opacity ${dropdownOpen ? "opacity-100" : "opacity-0 group-hover:opacity-100"}`}
|
||||
>
|
||||
<DropdownMenu open={dropdownOpen} onOpenChange={setDropdownOpen}>
|
||||
<DropdownMenuTrigger asChild>
|
||||
@@ -283,9 +279,9 @@ export function EntryCard({
|
||||
}}
|
||||
>
|
||||
<Heart
|
||||
className={`mr-2 h-4 w-4 ${libraryEntry?.favorit ? 'fill-current' : ''}`}
|
||||
className={`mr-2 h-4 w-4 ${libraryEntry?.favorit ? "fill-current" : ""}`}
|
||||
/>
|
||||
{libraryEntry?.favorit ? 'Unfavorite' : 'Favorite'}
|
||||
{libraryEntry?.favorit ? "Unfavorite" : "Favorite"}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
onClick={(e) => {
|
||||
@@ -303,7 +299,7 @@ export function EntryCard({
|
||||
}}
|
||||
>
|
||||
<EyeOff className="mr-2 h-4 w-4" />
|
||||
{libraryEntry?.hidden ? 'Unhide' : 'Hide'}
|
||||
{libraryEntry?.hidden ? "Unhide" : "Hide"}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
{/* Manage */}
|
||||
@@ -315,9 +311,9 @@ export function EntryCard({
|
||||
disabled={refreshEntry.isPending}
|
||||
>
|
||||
<RefreshCw
|
||||
className={`mr-2 h-4 w-4 ${refreshEntry.isPending ? 'animate-spin' : ''}`}
|
||||
className={`mr-2 h-4 w-4 ${refreshEntry.isPending ? "animate-spin" : ""}`}
|
||||
/>
|
||||
{refreshEntry.isPending ? 'Refreshing...' : 'Refresh details'}
|
||||
{refreshEntry.isPending ? "Refreshing..." : "Refresh details"}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
onClick={(e) => {
|
||||
@@ -376,7 +372,7 @@ export function EntryCard({
|
||||
variant="secondary"
|
||||
className="absolute bottom-2 right-2 text-[10px] px-1.5 py-0.5 opacity-90 z-10 pointer-events-none"
|
||||
>
|
||||
{isTv ? 'TV Series' : 'Movie'}
|
||||
{isTv ? "TV Series" : "Movie"}
|
||||
</Badge>
|
||||
)}
|
||||
|
||||
@@ -390,7 +386,7 @@ export function EntryCard({
|
||||
{rating != null && rating > 0 && (
|
||||
<span className="flex items-center gap-1">
|
||||
<Star className="h-3 w-3 fill-yellow-400 text-yellow-400" />
|
||||
{typeof rating === 'number' ? rating.toFixed(1) : rating}
|
||||
{typeof rating === "number" ? rating.toFixed(1) : rating}
|
||||
</span>
|
||||
)}
|
||||
{year && <span>{year}</span>}
|
||||
@@ -411,7 +407,7 @@ export function EntryCard({
|
||||
) : (
|
||||
<Plus className="mr-1 h-3 w-3" />
|
||||
)}
|
||||
{createEntry.isPending ? 'Adding...' : 'Add to Library'}
|
||||
{createEntry.isPending ? "Adding..." : "Add to Library"}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
@@ -510,8 +506,8 @@ export function EntryCard({
|
||||
}}
|
||||
className={`w-full flex items-center gap-2 rounded-md px-3 py-2 text-sm transition-colors hover:bg-accent ${
|
||||
libraryEntry?.watch_status === s.value
|
||||
? 'bg-accent font-medium'
|
||||
: ''
|
||||
? "bg-accent font-medium"
|
||||
: ""
|
||||
}`}
|
||||
>
|
||||
<BookmarkCheck className="h-4 w-4" />
|
||||
|
||||
Reference in new issue
Block a user