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,26 +1,26 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { useParams, Link, useNavigate } from "react-router-dom";
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useParams, Link, useNavigate } from 'react-router-dom';
|
||||
import {
|
||||
useEntry,
|
||||
useEntrySeasons,
|
||||
useRefreshEntry,
|
||||
useEntryCredits,
|
||||
} from "@/hooks/useEntries";
|
||||
import { useEntrySeenByEntry, useDeleteEntrySeen } from "@/hooks/useEntrySeen";
|
||||
import { useCollections } from "@/hooks/useCollections";
|
||||
import { useLibraryStore } from "@/stores/useLibraryStore";
|
||||
import { useCommandPaletteStore } from "@/stores/useCommandPaletteStore";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
|
||||
} from '@/hooks/useEntries';
|
||||
import { useEntrySeenByEntry, useDeleteEntrySeen } from '@/hooks/useEntrySeen';
|
||||
import { useCollections } from '@/hooks/useCollections';
|
||||
import { useLibraryStore } from '@/stores/useLibraryStore';
|
||||
import { useCommandPaletteStore } from '@/stores/useCommandPaletteStore';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { ScrollArea, ScrollBar } from '@/components/ui/scroll-area';
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import {
|
||||
Heart,
|
||||
MoreHorizontal,
|
||||
@@ -35,25 +35,32 @@ import {
|
||||
Trash2,
|
||||
ExternalLink,
|
||||
Play,
|
||||
} from "lucide-react";
|
||||
BookmarkCheck,
|
||||
} from 'lucide-react';
|
||||
import {
|
||||
Tooltip,
|
||||
TooltipContent,
|
||||
TooltipProvider,
|
||||
TooltipTrigger,
|
||||
} from "@/components/ui/tooltip";
|
||||
import { CastList } from "@/components/entries/CastList";
|
||||
import { SeasonsContainer } from "@/components/entries/SeasonsContainer";
|
||||
import { StreamingSection } from "@/components/streaming/StreamingSection";
|
||||
} from '@/components/ui/tooltip';
|
||||
import { CastList } from '@/components/entries/CastList';
|
||||
import { SeasonsContainer } from '@/components/entries/SeasonsContainer';
|
||||
import { StreamingSection } from '@/components/streaming/StreamingSection';
|
||||
// EpisodeWatchHistory is available for future use
|
||||
import { EntrySettingsDialog } from "@/components/dialogs/EntrySettingsDialog";
|
||||
import { EntrySeenDialog } from "@/components/dialogs/EntrySeenDialog";
|
||||
import { EntryMediaDialog } from "@/components/dialogs/EntryMediaDialog";
|
||||
import { AddEntryToCollectionDialog } from "@/components/dialogs/AddEntryToCollectionDialog";
|
||||
import { RatingDialog } from "@/components/dialogs/RatingDialog";
|
||||
import { MovieWatchHistoryDialog } from "@/components/dialogs/MovieWatchHistoryDialog";
|
||||
import { ConfirmDialog } from "@/components/dialogs/ConfirmDialog";
|
||||
import { EntryDetailsSkeleton } from "@/components/skeletons/PageSkeletons";
|
||||
import { EntrySettingsDialog } from '@/components/dialogs/EntrySettingsDialog';
|
||||
import { EntrySeenDialog } from '@/components/dialogs/EntrySeenDialog';
|
||||
import { EntryMediaDialog } from '@/components/dialogs/EntryMediaDialog';
|
||||
import { AddEntryToCollectionDialog } from '@/components/dialogs/AddEntryToCollectionDialog';
|
||||
import { RatingDialog } from '@/components/dialogs/RatingDialog';
|
||||
import { MovieWatchHistoryDialog } from '@/components/dialogs/MovieWatchHistoryDialog';
|
||||
import { ConfirmDialog } from '@/components/dialogs/ConfirmDialog';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { EntryDetailsSkeleton } from '@/components/skeletons/PageSkeletons';
|
||||
import {
|
||||
getPosterUrl,
|
||||
getBackdropUrl,
|
||||
@@ -61,9 +68,44 @@ import {
|
||||
getYear,
|
||||
formatRuntime,
|
||||
formatDate,
|
||||
} from "@/lib/media-utils";
|
||||
import { useUpdateEntry, useDeleteEntry } from "@/hooks/useEntries";
|
||||
import type { Collection, Entry } from "@/types";
|
||||
} from '@/lib/media-utils';
|
||||
import { useUpdateEntry, useDeleteEntry } from '@/hooks/useEntries';
|
||||
import type { Collection, Entry } from '@/types';
|
||||
|
||||
const WATCH_STATUSES = [
|
||||
{
|
||||
value: 'plan_to_watch',
|
||||
label: 'Plan to Watch',
|
||||
color:
|
||||
'bg-slate-500/15 border-slate-500/30 text-slate-600 dark:text-slate-400',
|
||||
},
|
||||
{
|
||||
value: 'watching',
|
||||
label: 'Watching',
|
||||
color: 'bg-blue-500/15 border-blue-500/30 text-blue-600 dark:text-blue-400',
|
||||
},
|
||||
{
|
||||
value: 'completed',
|
||||
label: 'Completed',
|
||||
color:
|
||||
'bg-green-500/15 border-green-500/30 text-green-600 dark:text-green-400',
|
||||
},
|
||||
{
|
||||
value: 'on_hold',
|
||||
label: 'On Hold',
|
||||
color:
|
||||
'bg-amber-500/15 border-amber-500/30 text-amber-600 dark:text-amber-400',
|
||||
},
|
||||
{
|
||||
value: 'dropped',
|
||||
label: 'Dropped',
|
||||
color: 'bg-red-500/15 border-red-500/30 text-red-600 dark:text-red-400',
|
||||
},
|
||||
];
|
||||
|
||||
function getWatchStatusInfo(value: string | null | undefined) {
|
||||
return WATCH_STATUSES.find((s) => s.value === value);
|
||||
}
|
||||
|
||||
export function EntryDetailsPage() {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
@@ -92,6 +134,7 @@ export function EntryDetailsPage() {
|
||||
const [showRatingDialog, setShowRatingDialog] = useState(false);
|
||||
const [showWatchHistoryDialog, setShowWatchHistoryDialog] = useState(false);
|
||||
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false);
|
||||
const [showStatusDialog, setShowStatusDialog] = useState(false);
|
||||
|
||||
// Track recently viewed for command palette
|
||||
const addRecentlyViewed = useCommandPaletteStore((s) => s.addRecentlyViewed);
|
||||
@@ -100,7 +143,7 @@ export function EntryDetailsPage() {
|
||||
addRecentlyViewed({
|
||||
id: `lib-${entryId}`,
|
||||
title: displayEntry.title,
|
||||
type: displayEntry.is_tvseries ? "tv" : "movie",
|
||||
type: displayEntry.is_tvseries ? 'tv' : 'movie',
|
||||
poster_path: displayEntry.poster_path,
|
||||
libraryId: entryId,
|
||||
tmdbId: displayEntry.entryIds?.tmdb_id ?? undefined,
|
||||
@@ -119,7 +162,7 @@ export function EntryDetailsPage() {
|
||||
const backdrop = getBackdropUrl(e);
|
||||
const poster = getPosterUrl(e);
|
||||
const director = credits.find(
|
||||
(c) => c.cast_type === "crew" && c.job === "Director",
|
||||
(c) => c.cast_type === 'crew' && c.job === 'Director',
|
||||
);
|
||||
|
||||
const toggleFavorite = () => {
|
||||
@@ -162,6 +205,13 @@ export function EntryDetailsPage() {
|
||||
<Star className="mr-2 h-4 w-4" />
|
||||
Rate this
|
||||
</DropdownMenuItem>
|
||||
{e.is_tvseries && <DropdownMenuSeparator />}
|
||||
{e.is_tvseries && (
|
||||
<DropdownMenuItem onClick={() => setShowStatusDialog(true)}>
|
||||
<BookmarkCheck className="mr-2 h-4 w-4" />
|
||||
Set Status
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
{!e.is_tvseries && (
|
||||
<DropdownMenuItem
|
||||
onClick={() => setShowWatchHistoryDialog(true)}
|
||||
@@ -177,9 +227,9 @@ export function EntryDetailsPage() {
|
||||
disabled={updateEntry.isPending}
|
||||
>
|
||||
<Heart
|
||||
className={`mr-2 h-4 w-4 ${e.favorit ? "fill-current" : ""}`}
|
||||
className={`mr-2 h-4 w-4 ${e.favorit ? 'fill-current' : ''}`}
|
||||
/>
|
||||
{e.favorit ? "Unfavorite" : "Favorite"}
|
||||
{e.favorit ? 'Unfavorite' : 'Favorite'}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={() => setShowCollectionDialog(true)}>
|
||||
<FolderPlus className="mr-2 h-4 w-4" />
|
||||
@@ -191,7 +241,7 @@ export function EntryDetailsPage() {
|
||||
}
|
||||
>
|
||||
<EyeOff className="mr-2 h-4 w-4" />
|
||||
{e.hidden ? "Unhide" : "Hide"}
|
||||
{e.hidden ? 'Unhide' : 'Hide'}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
{/* Manage */}
|
||||
@@ -200,9 +250,9 @@ export function EntryDetailsPage() {
|
||||
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={() => setShowMediaDialog(true)}>
|
||||
<ImageIcon className="mr-2 h-4 w-4" />
|
||||
@@ -241,7 +291,7 @@ export function EntryDetailsPage() {
|
||||
<div className="flex items-center justify-center gap-3 mt-3">
|
||||
{e.entryIds.tmdb_id && (
|
||||
<a
|
||||
href={`https://www.themoviedb.org/${e.is_tvseries ? "tv" : "movie"}/${e.entryIds.tmdb_id}`}
|
||||
href={`https://www.themoviedb.org/${e.is_tvseries ? 'tv' : 'movie'}/${e.entryIds.tmdb_id}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors"
|
||||
@@ -272,7 +322,7 @@ export function EntryDetailsPage() {
|
||||
<h1 className="text-3xl font-bold leading-tight">{e.title}</h1>
|
||||
{director?.people?.name && (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
by{" "}
|
||||
by{' '}
|
||||
<Link
|
||||
to={`/people/${director.people_id}`}
|
||||
className="font-medium text-foreground hover:underline"
|
||||
@@ -414,23 +464,39 @@ export function EntryDetailsPage() {
|
||||
disabled={updateEntry.isPending}
|
||||
className={`inline-flex items-center gap-1 rounded-full border px-3 py-1 text-sm font-medium transition-colors ${
|
||||
e.favorit
|
||||
? "bg-yellow-500/15 border-yellow-500/30 text-yellow-600 dark:text-yellow-400 hover:bg-yellow-500/25"
|
||||
: "border-dashed border-border text-muted-foreground hover:border-yellow-500/40 hover:text-yellow-500"
|
||||
? 'bg-yellow-500/15 border-yellow-500/30 text-yellow-600 dark:text-yellow-400 hover:bg-yellow-500/25'
|
||||
: 'border-dashed border-border text-muted-foreground hover:border-yellow-500/40 hover:text-yellow-500'
|
||||
}`}
|
||||
>
|
||||
<Star
|
||||
className={`h-3.5 w-3.5 ${e.favorit ? "fill-yellow-400 text-yellow-400" : ""}`}
|
||||
className={`h-3.5 w-3.5 ${e.favorit ? 'fill-yellow-400 text-yellow-400' : ''}`}
|
||||
/>
|
||||
Favorit
|
||||
</button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>
|
||||
<p>
|
||||
{e.favorit ? "Remove from favorites" : "Add to favorites"}
|
||||
{e.favorit ? 'Remove from favorites' : 'Add to favorites'}
|
||||
</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
|
||||
{/* Watch status pill — TV only */}
|
||||
{e.is_tvseries &&
|
||||
e.watch_status &&
|
||||
(() => {
|
||||
const info = getWatchStatusInfo(e.watch_status);
|
||||
return (
|
||||
<button
|
||||
onClick={() => setShowStatusDialog(true)}
|
||||
className={`inline-flex items-center gap-1 rounded-full border px-3 py-1 text-sm font-medium transition-colors cursor-pointer ${info?.color ?? ''}`}
|
||||
>
|
||||
<BookmarkCheck className="h-3.5 w-3.5" />
|
||||
{info?.label}
|
||||
</button>
|
||||
);
|
||||
})()}
|
||||
</div>
|
||||
|
||||
{/* Storyline */}
|
||||
@@ -448,7 +514,7 @@ export function EntryDetailsPage() {
|
||||
<div className="flex flex-wrap items-center justify-center gap-2">
|
||||
<StreamingSection entry={e} seasons={seasons} />
|
||||
<a
|
||||
href={`https://www.youtube.com/results?search_query=${encodeURIComponent(e.title + " official trailer")}`}
|
||||
href={`https://www.youtube.com/results?search_query=${encodeURIComponent(e.title + ' official trailer')}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="inline-flex items-center gap-2 h-11 px-6 text-sm font-medium rounded-md border border-input bg-background hover:bg-accent hover:text-accent-foreground transition-colors"
|
||||
@@ -552,11 +618,39 @@ export function EntryDetailsPage() {
|
||||
variant="destructive"
|
||||
onConfirm={() => {
|
||||
deleteEntry.mutate(e.id, {
|
||||
onSuccess: () => navigate("/library"),
|
||||
onSuccess: () => navigate('/library'),
|
||||
});
|
||||
setShowDeleteConfirm(false);
|
||||
}}
|
||||
/>
|
||||
|
||||
<Dialog open={showStatusDialog} onOpenChange={setShowStatusDialog}>
|
||||
<DialogContent className="sm:max-w-xs">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Set Watch Status</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="space-y-1">
|
||||
{WATCH_STATUSES.map((s) => (
|
||||
<button
|
||||
key={s.value}
|
||||
onClick={() => {
|
||||
updateEntry.mutate({
|
||||
id: e.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 ${
|
||||
e.watch_status === s.value ? 'bg-accent font-medium' : ''
|
||||
}`}
|
||||
>
|
||||
<BookmarkCheck className="h-4 w-4" />
|
||||
{s.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -598,8 +692,8 @@ function EntryCollectionsSection({ entryId }: { entryId: number }) {
|
||||
</p>
|
||||
{col.entries && (
|
||||
<p className="text-xs text-white/70 mt-0.5">
|
||||
{col.entries.length}{" "}
|
||||
{col.entries.length === 1 ? "title" : "titles"}
|
||||
{col.entries.length}{' '}
|
||||
{col.entries.length === 1 ? 'title' : 'titles'}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user