fix: season episode dialog, mark season watched, episode 404 handling
Seasons Page: - Episode watch button now opens EpisodeSeenEditDialog instead of directly marking as watched, allowing date/seen-with input - Added "Mark Season as Watched" button that sequentially marks all unwatched episodes in the season Episode Page: - Fixed UI not updating after deleting the last episode seen record; the backend returns 404 when no records exist for an episode, which caused the query to error instead of resolving to an empty array. The API layer now catches 404 and returns [] gracefully.
This commit is contained in:
1 parent
984e2c8b50
commit
6bff2055b4
12 files changed
+337
-47
No files matched your search
@@ -54,10 +54,6 @@ class EntrySeenController {
|
||||
|
||||
}
|
||||
|
||||
async getEntrySeensByEntryId(req, res) {
|
||||
|
||||
}
|
||||
|
||||
async updateEntrySeen(req, res) {
|
||||
const { date_seen, seen_with } = req.body;
|
||||
const updated = await EntrySeen.update({ date_seen, seen_with }, { where: { id: req.params.id } });
|
||||
|
||||
@@ -7,15 +7,15 @@ const entrySeenController = require('../controllers/entrySeenController');
|
||||
// * GET - ALL ENTRY SEEN
|
||||
entrySeenRouter.get('/', entrySeenController.getEntrySeens);
|
||||
|
||||
// * GET - ENTRY SEEN BY ENTRY ID (must be before /:id to avoid conflict)
|
||||
entrySeenRouter.get('/by-entry/:entryId', entrySeenController.getEntrySeensByEntryId);
|
||||
|
||||
// * GET - ENTRY SEEN BY ID
|
||||
entrySeenRouter.get('/:id', entrySeenController.getEntrySeenById);
|
||||
|
||||
// * POST - CREATE ENTRY SEEN
|
||||
entrySeenRouter.post('/', entrySeenController.createEntrySeen);
|
||||
|
||||
// * GET - ENTRY SEEN BY ENTRY ID
|
||||
entrySeenRouter.get('/by-entry/:entryId', entrySeenController.getEntrySeensByEntryId);
|
||||
|
||||
// * PUT - UPDATE ENTRY SEEN
|
||||
entrySeenRouter.put('/:id', entrySeenController.updateEntrySeen);
|
||||
|
||||
|
||||
@@ -8,7 +8,13 @@ export const entrySeenApi = {
|
||||
api.get<EntrySeen>(`/entry-seen/${id}`).then((r) => r.data),
|
||||
|
||||
getByEntry: (entryId: number) =>
|
||||
api.get<EntrySeen[]>(`/entry-seen/by-entry/${entryId}`).then((r) => r.data),
|
||||
api
|
||||
.get<EntrySeen[]>(`/entry-seen/by-entry/${entryId}`)
|
||||
.then((r) => r.data)
|
||||
.catch((err) => {
|
||||
if (err?.response?.status === 404) return [] as EntrySeen[];
|
||||
throw err;
|
||||
}),
|
||||
|
||||
create: (data: { entry_id: number; date_seen: string; seen_with?: string }) =>
|
||||
api.post<EntrySeen>('/entry-seen', data).then((r) => r.data),
|
||||
|
||||
@@ -10,7 +10,11 @@ export const episodeSeenApi = {
|
||||
getByEpisode: (episodeId: number) =>
|
||||
api
|
||||
.get<EpisodeSeen[]>(`/episode-seen/by-episode/${episodeId}`)
|
||||
.then((r) => r.data),
|
||||
.then((r) => r.data)
|
||||
.catch((err) => {
|
||||
if (err?.response?.status === 404) return [] as EpisodeSeen[];
|
||||
throw err;
|
||||
}),
|
||||
|
||||
create: (data: {
|
||||
entry_id: number;
|
||||
|
||||
@@ -20,7 +20,10 @@ interface EpisodeSeenEditDialogProps {
|
||||
/** Required for create mode */
|
||||
episodeId?: number;
|
||||
entryId: number;
|
||||
seasonId?: number;
|
||||
mode?: 'create' | 'edit';
|
||||
/** If provided, called instead of the normal create/update mutation */
|
||||
overrideSubmit?: (date: string, seenWith: string) => void;
|
||||
}
|
||||
|
||||
export function EpisodeSeenEditDialog({
|
||||
@@ -29,7 +32,9 @@ export function EpisodeSeenEditDialog({
|
||||
record,
|
||||
episodeId,
|
||||
entryId,
|
||||
seasonId,
|
||||
mode = record ? 'edit' : 'create',
|
||||
overrideSubmit,
|
||||
}: EpisodeSeenEditDialogProps) {
|
||||
const today = new Date().toISOString().split('T')[0];
|
||||
const [date, setDate] = useState(record?.date_seen?.split('T')[0] ?? today);
|
||||
@@ -39,6 +44,10 @@ export function EpisodeSeenEditDialog({
|
||||
const createEpisodeSeen = useCreateEpisodeSeen();
|
||||
|
||||
const handleSave = () => {
|
||||
if (overrideSubmit) {
|
||||
overrideSubmit(date, seenWith);
|
||||
return;
|
||||
}
|
||||
if (mode === 'edit' && record) {
|
||||
updateEpisodeSeen.mutate({
|
||||
id: record.id,
|
||||
@@ -57,6 +66,7 @@ export function EpisodeSeenEditDialog({
|
||||
episode_id: epId,
|
||||
date_seen: date,
|
||||
seen_with: seenWith || undefined,
|
||||
season_id: seasonId,
|
||||
});
|
||||
}
|
||||
onOpenChange(false);
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
import { format } from 'date-fns';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Trash2 } from 'lucide-react';
|
||||
import type { EntrySeen } from '@/types';
|
||||
|
||||
interface MovieWatchHistoryDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
entryId: number;
|
||||
watchHistory: EntrySeen[];
|
||||
onDelete: (seenId: number) => void;
|
||||
}
|
||||
|
||||
export function MovieWatchHistoryDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
watchHistory,
|
||||
onDelete,
|
||||
}: MovieWatchHistoryDialogProps) {
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Watch History</DialogTitle>
|
||||
</DialogHeader>
|
||||
{watchHistory.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground py-4">
|
||||
No watch history yet.
|
||||
</p>
|
||||
) : (
|
||||
<div className="overflow-x-auto rounded-lg border border-border">
|
||||
<table className="w-full text-sm">
|
||||
<thead>
|
||||
<tr className="border-b border-border bg-muted/50">
|
||||
<th className="px-4 py-2 text-left font-medium">Date</th>
|
||||
<th className="px-4 py-2 text-left font-medium">Seen With</th>
|
||||
<th className="px-4 py-2 text-right font-medium">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{watchHistory.map((record) => (
|
||||
<tr
|
||||
key={record.id}
|
||||
className="border-b border-border last:border-0"
|
||||
>
|
||||
<td className="px-4 py-2">
|
||||
{record.date_seen
|
||||
? format(new Date(record.date_seen), 'MMM d, yyyy')
|
||||
: '-'}
|
||||
</td>
|
||||
<td className="px-4 py-2 text-muted-foreground">
|
||||
{record.seen_with || '-'}
|
||||
</td>
|
||||
<td className="px-4 py-2">
|
||||
<div className="flex justify-end">
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="h-7 w-7 text-destructive"
|
||||
onClick={() => onDelete(record.id)}
|
||||
>
|
||||
<Trash2 className="h-3 w-3" />
|
||||
</Button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -3,8 +3,8 @@ import { Link } from 'react-router-dom';
|
||||
import { ChevronDown, ChevronUp, Play } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Progress } from '@/components/ui/progress';
|
||||
import { EpisodeSeenEditDialog } from '@/components/dialogs/EpisodeSeenEditDialog';
|
||||
import { getYear, getTmdbPosterUrl } from '@/lib/media-utils';
|
||||
import { useCreateEpisodeSeen } from '@/hooks/useEpisodeSeen';
|
||||
import type { Season } from '@/types';
|
||||
|
||||
interface SeasonsContainerProps {
|
||||
@@ -65,7 +65,7 @@ function SeasonItem({
|
||||
season: Season;
|
||||
entryId: number;
|
||||
}) {
|
||||
const createEpisodeSeen = useCreateEpisodeSeen();
|
||||
const [dialogOpen, setDialogOpen] = useState(false);
|
||||
const watchedCount =
|
||||
season.episodes?.filter(
|
||||
(ep) => ep.date_first_seen || (ep.episodeSeens && ep.episodeSeens.length > 0)
|
||||
@@ -79,6 +79,7 @@ function SeasonItem({
|
||||
.find((ep) => !ep.date_first_seen && (!ep.episodeSeens || ep.episodeSeens.length === 0));
|
||||
|
||||
return (
|
||||
<>
|
||||
<Link
|
||||
to={`/entry/${entryId}/season/${season.id}`}
|
||||
className="flex items-center gap-4 rounded-lg border border-border p-3 transition-colors hover:bg-accent/50"
|
||||
@@ -109,7 +110,7 @@ function SeasonItem({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Quick watch button */}
|
||||
{/* Quick watch button - opens dialog */}
|
||||
{nextUnwatched && (
|
||||
<Button
|
||||
size="icon"
|
||||
@@ -118,17 +119,23 @@ function SeasonItem({
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
createEpisodeSeen.mutate({
|
||||
entry_id: entryId,
|
||||
episode_id: nextUnwatched.id,
|
||||
date_seen: new Date().toISOString(),
|
||||
});
|
||||
setDialogOpen(true);
|
||||
}}
|
||||
disabled={createEpisodeSeen.isPending}
|
||||
>
|
||||
<Play className="h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
</Link>
|
||||
|
||||
{nextUnwatched && dialogOpen && (
|
||||
<EpisodeSeenEditDialog
|
||||
open={dialogOpen}
|
||||
onOpenChange={setDialogOpen}
|
||||
mode="create"
|
||||
episodeId={nextUnwatched.id}
|
||||
entryId={entryId}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -27,6 +27,7 @@ export function useCreateEpisodeSeen() {
|
||||
episode_id: number;
|
||||
date_seen: string;
|
||||
seen_with?: string;
|
||||
season_id?: number;
|
||||
}) => episodeSeenApi.create(data),
|
||||
onSuccess: (_data, variables) => {
|
||||
queryClient.invalidateQueries({
|
||||
@@ -38,6 +39,11 @@ export function useCreateEpisodeSeen() {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: entryKeys.seasons(variables.entry_id),
|
||||
});
|
||||
if (variables.season_id) {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: seasonKeys.episodes(variables.season_id),
|
||||
});
|
||||
}
|
||||
toast.success('Episode marked as watched');
|
||||
},
|
||||
onError: () => {
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
Settings,
|
||||
Star,
|
||||
Loader2,
|
||||
History,
|
||||
} from 'lucide-react';
|
||||
import {
|
||||
Tooltip,
|
||||
@@ -40,6 +41,7 @@ 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 { EntryDetailsSkeleton } from '@/components/skeletons/PageSkeletons';
|
||||
import {
|
||||
getPosterUrl,
|
||||
@@ -73,6 +75,7 @@ export function EntryDetailsPage() {
|
||||
const [showMediaDialog, setShowMediaDialog] = useState(false);
|
||||
const [showCollectionDialog, setShowCollectionDialog] = useState(false);
|
||||
const [showRatingDialog, setShowRatingDialog] = useState(false);
|
||||
const [showWatchHistoryDialog, setShowWatchHistoryDialog] = useState(false);
|
||||
|
||||
if (isLoading || !displayEntry) {
|
||||
return <EntryDetailsSkeleton />;
|
||||
@@ -155,6 +158,12 @@ export function EntryDetailsPage() {
|
||||
<Star className="mr-2 h-4 w-4" />
|
||||
Rate this
|
||||
</DropdownMenuItem>
|
||||
{!e.is_tvseries && (
|
||||
<DropdownMenuItem onClick={() => setShowWatchHistoryDialog(true)}>
|
||||
<History className="mr-2 h-4 w-4" />
|
||||
Watch History
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
<DropdownMenuItem
|
||||
onClick={() =>
|
||||
updateEntry.mutate({ id: e.id, data: { hidden: !e.hidden } })
|
||||
@@ -241,6 +250,31 @@ export function EntryDetailsPage() {
|
||||
<span>{formatRuntime(e.runtime)}</span>
|
||||
</>
|
||||
)}
|
||||
{!e.is_tvseries && watchHistory.length > 0 && (
|
||||
<>
|
||||
<span>•</span>
|
||||
{watchHistory.length === 1 ? (
|
||||
<span>seen {formatDate(watchHistory[0].date_seen)}</span>
|
||||
) : (
|
||||
<TooltipProvider>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<span className="cursor-default underline decoration-dotted">
|
||||
seen {watchHistory.length} times
|
||||
</span>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>
|
||||
<div className="space-y-0.5 text-xs">
|
||||
{watchHistory.map((wh) => (
|
||||
<p key={wh.id}>{formatDate(wh.date_seen)}</p>
|
||||
))}
|
||||
</div>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Genres */}
|
||||
@@ -372,6 +406,17 @@ export function EntryDetailsPage() {
|
||||
entry={e}
|
||||
/>
|
||||
)}
|
||||
{showWatchHistoryDialog && (
|
||||
<MovieWatchHistoryDialog
|
||||
open={showWatchHistoryDialog}
|
||||
onOpenChange={setShowWatchHistoryDialog}
|
||||
entryId={e.id}
|
||||
watchHistory={watchHistory}
|
||||
onDelete={(seenId) =>
|
||||
deleteEntrySeen.mutate({ id: seenId, entryId: e.id })
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -172,6 +172,7 @@ export function EpisodePage() {
|
||||
mode="create"
|
||||
episodeId={episode.id}
|
||||
entryId={entryIdNum}
|
||||
seasonId={parseInt(seasonId!, 10)}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -183,6 +184,7 @@ export function EpisodePage() {
|
||||
mode="edit"
|
||||
record={editRecord}
|
||||
entryId={entryIdNum}
|
||||
seasonId={parseInt(seasonId!, 10)}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useState, useMemo, useCallback } from 'react';
|
||||
import { useState, useMemo, useCallback, useEffect, useRef } from 'react';
|
||||
import { useSearchParams } from 'react-router-dom';
|
||||
import { useLibrary } from '@/hooks/useEntries';
|
||||
import { useLibraryEntries } from '@/stores/useLibraryStore';
|
||||
import { EntryLibraryGrid } from '@/components/entries/EntryLibraryGrid';
|
||||
@@ -44,8 +45,8 @@ function sortEntries(entries: Entry[], field: SortField, dir: SortDir): Entry[]
|
||||
cmp = new Date(a.release_date || '1900').getTime() - new Date(b.release_date || '1900').getTime();
|
||||
break;
|
||||
case 'rating':
|
||||
cmp = (a.entryRatings?.user_rating || a.entryRatings?.tmdb_rating || 0) -
|
||||
(b.entryRatings?.user_rating || b.entryRatings?.tmdb_rating || 0);
|
||||
cmp = (a.entryRatings?.user_rating ?? 0) -
|
||||
(b.entryRatings?.user_rating ?? 0);
|
||||
break;
|
||||
case 'date_last_seen':
|
||||
cmp = new Date(a.date_last_seen || '1900').getTime() - new Date(b.date_last_seen || '1900').getTime();
|
||||
@@ -58,16 +59,56 @@ function sortEntries(entries: Entry[], field: SortField, dir: SortDir): Entry[]
|
||||
});
|
||||
}
|
||||
|
||||
const PAGE_SIZE = 28;
|
||||
|
||||
export function LibraryPage() {
|
||||
const { isLoading } = useLibrary();
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
const [activeTab, setActiveTab] = useState<FilterTab>('all');
|
||||
const [search, setSearch] = useState('');
|
||||
const [debouncedSearch, setDebouncedSearch] = useState('');
|
||||
const [sortField, setSortField] = useState<SortField>('date_last_seen');
|
||||
const [sortDir, setSortDir] = useState<SortDir>('desc');
|
||||
const [filters, setFilters] = useState<Filters>(defaultFilters);
|
||||
const [debouncedFilters, setDebouncedFilters] = useState<Filters>(defaultFilters);
|
||||
const [visibleCount, setVisibleCount] = useState(PAGE_SIZE);
|
||||
const filtersInitialized = useRef(false);
|
||||
|
||||
const allEntries = useLibraryEntries();
|
||||
|
||||
// Read URL query params once on mount
|
||||
useEffect(() => {
|
||||
if (filtersInitialized.current) return;
|
||||
filtersInitialized.current = true;
|
||||
const genre = searchParams.get('genre') || '';
|
||||
const ratingMin = searchParams.get('ratingMin') || '';
|
||||
const ratingMax = searchParams.get('ratingMax') || '';
|
||||
if (genre || ratingMin || ratingMax) {
|
||||
const newFilters = { ...defaultFilters, genre, ratingMin, ratingMax };
|
||||
setFilters(newFilters);
|
||||
setDebouncedFilters(newFilters);
|
||||
// Clear URL params after applying
|
||||
setSearchParams({}, { replace: true });
|
||||
}
|
||||
}, [searchParams, setSearchParams]);
|
||||
|
||||
// Debounce search
|
||||
useEffect(() => {
|
||||
const timer = setTimeout(() => setDebouncedSearch(search), 300);
|
||||
return () => clearTimeout(timer);
|
||||
}, [search]);
|
||||
|
||||
// Debounce filters
|
||||
useEffect(() => {
|
||||
const timer = setTimeout(() => setDebouncedFilters(filters), 300);
|
||||
return () => clearTimeout(timer);
|
||||
}, [filters]);
|
||||
|
||||
// Reset visible count when filters/search/tab/sort change
|
||||
useEffect(() => {
|
||||
setVisibleCount(PAGE_SIZE);
|
||||
}, [activeTab, debouncedSearch, debouncedFilters, sortField, sortDir]);
|
||||
|
||||
// Gather unique genres from the library
|
||||
const allGenres = useMemo(() => {
|
||||
const set = new Set<string>();
|
||||
@@ -95,33 +136,40 @@ export function LibraryPage() {
|
||||
const filteredEntries = useMemo(() => {
|
||||
let result = baseEntries;
|
||||
|
||||
if (search) {
|
||||
const q = search.toLowerCase();
|
||||
if (debouncedSearch) {
|
||||
const q = debouncedSearch.toLowerCase();
|
||||
result = result.filter((e) => e.title.toLowerCase().includes(q));
|
||||
}
|
||||
|
||||
if (filters.genre) {
|
||||
result = result.filter((e) => e.genres?.some((g) => g.name === filters.genre));
|
||||
if (debouncedFilters.genre) {
|
||||
result = result.filter((e) => e.genres?.some((g) => g.name === debouncedFilters.genre));
|
||||
}
|
||||
if (filters.ratingMin) {
|
||||
const min = parseFloat(filters.ratingMin);
|
||||
result = result.filter((e) => (e.entryRatings?.user_rating || e.entryRatings?.tmdb_rating || 0) >= min);
|
||||
if (debouncedFilters.ratingMin) {
|
||||
const min = parseFloat(debouncedFilters.ratingMin);
|
||||
result = result.filter((e) => (e.entryRatings?.user_rating ?? 0) >= min);
|
||||
}
|
||||
if (filters.ratingMax) {
|
||||
const max = parseFloat(filters.ratingMax);
|
||||
result = result.filter((e) => (e.entryRatings?.user_rating || e.entryRatings?.tmdb_rating || 0) <= max);
|
||||
if (debouncedFilters.ratingMax) {
|
||||
const max = parseFloat(debouncedFilters.ratingMax);
|
||||
result = result.filter((e) => (e.entryRatings?.user_rating ?? 0) <= max);
|
||||
}
|
||||
if (filters.yearMin) {
|
||||
const min = parseInt(filters.yearMin);
|
||||
if (debouncedFilters.yearMin) {
|
||||
const min = parseInt(debouncedFilters.yearMin);
|
||||
result = result.filter((e) => e.release_date && new Date(e.release_date).getFullYear() >= min);
|
||||
}
|
||||
if (filters.yearMax) {
|
||||
const max = parseInt(filters.yearMax);
|
||||
if (debouncedFilters.yearMax) {
|
||||
const max = parseInt(debouncedFilters.yearMax);
|
||||
result = result.filter((e) => e.release_date && new Date(e.release_date).getFullYear() <= max);
|
||||
}
|
||||
|
||||
return sortEntries(result, sortField, sortDir);
|
||||
}, [baseEntries, search, filters, sortField, sortDir]);
|
||||
}, [baseEntries, debouncedSearch, debouncedFilters, sortField, sortDir]);
|
||||
|
||||
const paginatedEntries = useMemo(
|
||||
() => filteredEntries.slice(0, visibleCount),
|
||||
[filteredEntries, visibleCount]
|
||||
);
|
||||
const hasMore = visibleCount < filteredEntries.length;
|
||||
const loadMore = useCallback(() => setVisibleCount((c) => c + PAGE_SIZE), []);
|
||||
|
||||
const clearFilters = useCallback(() => setFilters(defaultFilters), []);
|
||||
|
||||
@@ -214,7 +262,7 @@ export function LibraryPage() {
|
||||
<PopoverContent className="w-72 space-y-4" align="end">
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm font-medium">Genre</label>
|
||||
<Select value={filters.genre} onValueChange={(v) => setFilters((f) => ({ ...f, genre: v === '_all' ? '' : v }))}>
|
||||
<Select value={filters.genre} onValueChange={(v) => setFilters((f) => ({ ...f, genre: v === '_all' ? '' : (v || '') }))}>
|
||||
<SelectTrigger className="h-9"><SelectValue placeholder="All genres" /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="_all">All genres</SelectItem>
|
||||
@@ -325,7 +373,7 @@ export function LibraryPage() {
|
||||
<PopoverContent className="w-72 space-y-4" align="end">
|
||||
<div className="space-y-2">
|
||||
<label className="text-sm font-medium">Genre</label>
|
||||
<Select value={filters.genre} onValueChange={(v) => setFilters((f) => ({ ...f, genre: v === '_all' ? '' : v }))}>
|
||||
<Select value={filters.genre} onValueChange={(v) => setFilters((f) => ({ ...f, genre: v === '_all' ? '' : (v || '') }))}>
|
||||
<SelectTrigger className="h-9"><SelectValue placeholder="All genres" /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="_all">All genres</SelectItem>
|
||||
@@ -367,7 +415,12 @@ export function LibraryPage() {
|
||||
</Tabs>
|
||||
</div>
|
||||
|
||||
<EntryLibraryGrid entries={filteredEntries} isLoading={isLoading} />
|
||||
<EntryLibraryGrid
|
||||
entries={paginatedEntries}
|
||||
isLoading={isLoading}
|
||||
hasMore={hasMore}
|
||||
onLoadMore={loadMore}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,12 +1,16 @@
|
||||
import { useState } from 'react';
|
||||
import { useParams, Link } from 'react-router-dom';
|
||||
import { useSeason, useSeasonEpisodes } from '@/hooks/useSeasons';
|
||||
import { useCreateEpisodeSeen } from '@/hooks/useEpisodeSeen';
|
||||
import { EpisodeSeenEditDialog } from '@/components/dialogs/EpisodeSeenEditDialog';
|
||||
import { ConfirmDialog } from '@/components/dialogs/ConfirmDialog';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { Progress } from '@/components/ui/progress';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Eye, CheckCircle2 } from 'lucide-react';
|
||||
import { Eye, CheckCircle2, ListChecks } from 'lucide-react';
|
||||
import { getTmdbPosterUrl, getYear, formatDate } from '@/lib/media-utils';
|
||||
import type { Episode } from '@/types';
|
||||
|
||||
export function SeasonPage() {
|
||||
const { entryId, seasonId } = useParams<{
|
||||
@@ -16,6 +20,12 @@ export function SeasonPage() {
|
||||
const { data: season, isLoading } = useSeason(parseInt(seasonId!, 10));
|
||||
const { data: episodes = [] } = useSeasonEpisodes(parseInt(seasonId!, 10));
|
||||
const createEpisodeSeen = useCreateEpisodeSeen();
|
||||
const [dialogEpisode, setDialogEpisode] = useState<Episode | null>(null);
|
||||
const [markingAll, setMarkingAll] = useState(false);
|
||||
const [showMarkAllDialog, setShowMarkAllDialog] = useState(false);
|
||||
const [markAllDate, setMarkAllDate] = useState(new Date().toISOString().split('T')[0]);
|
||||
const [markAllSeenWith, setMarkAllSeenWith] = useState('');
|
||||
const [showMarkAllConfirm, setShowMarkAllConfirm] = useState(false);
|
||||
|
||||
if (isLoading || !season) {
|
||||
return (
|
||||
@@ -49,8 +59,23 @@ export function SeasonPage() {
|
||||
alt={season.name}
|
||||
className="h-56 w-36 shrink-0 rounded-lg object-cover shadow-lg"
|
||||
/>
|
||||
<div className="flex flex-col justify-center space-y-3">
|
||||
<div className="flex-1 flex flex-col justify-center space-y-3">
|
||||
<div className="flex items-start justify-between gap-4">
|
||||
<h1 className="text-2xl font-bold">{season.name}</h1>
|
||||
{/* Mark Season as Watched — top right */}
|
||||
{watchedCount < totalEpisodes && (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="shrink-0"
|
||||
disabled={markingAll}
|
||||
onClick={() => setShowMarkAllDialog(true)}
|
||||
>
|
||||
<ListChecks className="mr-1.5 h-4 w-4" />
|
||||
{markingAll ? 'Marking...' : 'Mark Season Watched'}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
||||
<span>Season {season.season_number}</span>
|
||||
{season.air_date && (
|
||||
@@ -144,14 +169,10 @@ export function SeasonPage() {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
if (!isWatched) {
|
||||
createEpisodeSeen.mutate({
|
||||
entry_id: parseInt(entryId!, 10),
|
||||
episode_id: episode.id,
|
||||
date_seen: new Date().toISOString(),
|
||||
});
|
||||
setDialogEpisode(episode);
|
||||
}
|
||||
}}
|
||||
disabled={isWatched || createEpisodeSeen.isPending}
|
||||
disabled={isWatched}
|
||||
>
|
||||
<Eye className="h-4 w-4" />
|
||||
</Button>
|
||||
@@ -160,6 +181,65 @@ export function SeasonPage() {
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Episode Seen Dialog */}
|
||||
{dialogEpisode && (
|
||||
<EpisodeSeenEditDialog
|
||||
open={!!dialogEpisode}
|
||||
onOpenChange={(open) => { if (!open) setDialogEpisode(null); }}
|
||||
mode="create"
|
||||
episodeId={dialogEpisode.id}
|
||||
entryId={parseInt(entryId!, 10)}
|
||||
seasonId={parseInt(seasonId!, 10)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Mark Season Watched — step 1: date/seen-with dialog */}
|
||||
{showMarkAllDialog && (
|
||||
<EpisodeSeenEditDialog
|
||||
open={showMarkAllDialog}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) setShowMarkAllDialog(false);
|
||||
}}
|
||||
mode="create"
|
||||
episodeId={-1}
|
||||
entryId={parseInt(entryId!, 10)}
|
||||
seasonId={parseInt(seasonId!, 10)}
|
||||
overrideSubmit={(date, seenWith) => {
|
||||
setMarkAllDate(date);
|
||||
setMarkAllSeenWith(seenWith);
|
||||
setShowMarkAllDialog(false);
|
||||
setShowMarkAllConfirm(true);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Mark Season Watched — step 2: confirmation */}
|
||||
<ConfirmDialog
|
||||
open={showMarkAllConfirm}
|
||||
onOpenChange={setShowMarkAllConfirm}
|
||||
title="Mark Season as Watched"
|
||||
description={`This will mark all ${episodes.filter((ep) => !ep.date_first_seen && (!ep.episodeSeens || ep.episodeSeens.length === 0)).length} unwatched episodes as seen on ${markAllDate}. Continue?`}
|
||||
confirmLabel="Mark All"
|
||||
isLoading={markingAll}
|
||||
onConfirm={async () => {
|
||||
setMarkingAll(true);
|
||||
const unwatched = episodes.filter(
|
||||
(ep) => !ep.date_first_seen && (!ep.episodeSeens || ep.episodeSeens.length === 0)
|
||||
);
|
||||
for (const ep of unwatched) {
|
||||
await createEpisodeSeen.mutateAsync({
|
||||
entry_id: parseInt(entryId!, 10),
|
||||
episode_id: ep.id,
|
||||
date_seen: markAllDate,
|
||||
seen_with: markAllSeenWith || undefined,
|
||||
season_id: parseInt(seasonId!, 10),
|
||||
});
|
||||
}
|
||||
setMarkingAll(false);
|
||||
setShowMarkAllConfirm(false);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user