Add watch status for TV series with UI and auto-fix
Added watch_status column to Entry model (plan_to_watch/watching/completed/ on_hold/dropped). Status pill on entry details page opens selection dialog. Set Status in quick actions menu and EntryCard dropdown (TV only). Status filter in Library filter popover. Maintenance auto-fix endpoint that sets statuses based on watched episodes (excl. season 0).
This commit is contained in:
1 parent
a5659cf4c8
commit
cdbaedd7d0
11 files changed
+663
-286
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { useState } from "react";
|
||||
import { Link, useNavigate } from "react-router-dom";
|
||||
import { useState } from 'react';
|
||||
import { Link, useNavigate } from 'react-router-dom';
|
||||
import {
|
||||
Plus,
|
||||
Star,
|
||||
@@ -15,35 +15,50 @@ import {
|
||||
RefreshCw,
|
||||
ImageIcon,
|
||||
Settings,
|
||||
} from "lucide-react";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
BookmarkCheck,
|
||||
} 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";
|
||||
import type { Entry, TmdbEntry } from "@/types";
|
||||
} 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';
|
||||
|
||||
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' },
|
||||
];
|
||||
|
||||
interface EntryCardProps {
|
||||
entry?: Entry;
|
||||
@@ -75,6 +90,7 @@ export function EntryCard({
|
||||
const [showMediaDialog, setShowMediaDialog] = useState(false);
|
||||
const [showSettingsDialog, setShowSettingsDialog] = useState(false);
|
||||
const [dropdownOpen, setDropdownOpen] = useState(false);
|
||||
const [showStatusDialog, setShowStatusDialog] = useState(false);
|
||||
const navigate = useNavigate();
|
||||
const createEntry = useCreateEntry();
|
||||
const deleteEntry = useDeleteEntry();
|
||||
@@ -100,7 +116,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);
|
||||
@@ -111,22 +127,22 @@ 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) => {
|
||||
@@ -173,7 +189,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"
|
||||
/>
|
||||
@@ -193,7 +209,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>
|
||||
@@ -233,6 +249,20 @@ export function EntryCard({
|
||||
<Star className="mr-2 h-4 w-4" />
|
||||
Rate this
|
||||
</DropdownMenuItem>
|
||||
{isTv && (
|
||||
<>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setShowStatusDialog(true);
|
||||
}}
|
||||
>
|
||||
<BookmarkCheck className="mr-2 h-4 w-4" />
|
||||
Set Status
|
||||
</DropdownMenuItem>
|
||||
</>
|
||||
)}
|
||||
{!isTv && (
|
||||
<DropdownMenuItem
|
||||
onClick={(e) => {
|
||||
@@ -253,9 +283,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) => {
|
||||
@@ -273,7 +303,7 @@ export function EntryCard({
|
||||
}}
|
||||
>
|
||||
<EyeOff className="mr-2 h-4 w-4" />
|
||||
{libraryEntry?.hidden ? "Unhide" : "Hide"}
|
||||
{libraryEntry?.hidden ? 'Unhide' : 'Hide'}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
{/* Manage */}
|
||||
@@ -285,9 +315,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) => {
|
||||
@@ -346,7 +376,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>
|
||||
)}
|
||||
|
||||
@@ -360,7 +390,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>}
|
||||
@@ -381,7 +411,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>
|
||||
)}
|
||||
@@ -460,6 +490,37 @@ export function EntryCard({
|
||||
entry={libraryEntry}
|
||||
/>
|
||||
)}
|
||||
|
||||
<Dialog open={showStatusDialog} onOpenChange={setShowStatusDialog}>
|
||||
<DialogContent className="sm:max-w-xs">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Set Watch Status</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="space-y-1">
|
||||
{CARD_WATCH_STATUSES.map((s) => (
|
||||
<button
|
||||
key={s.value}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
updateEntry.mutate({
|
||||
id: libraryEntry!.id,
|
||||
data: { watch_status: s.value },
|
||||
});
|
||||
setShowStatusDialog(false);
|
||||
}}
|
||||
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'
|
||||
: ''
|
||||
}`}
|
||||
>
|
||||
<BookmarkCheck className="h-4 w-4" />
|
||||
{s.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user