From 191f4d6aae4ff97f2fe0a4cba4681a927581611d Mon Sep 17 00:00:00 2001 From: Mohammed Abad Date: Wed, 1 Apr 2026 00:59:09 +0100 Subject: [PATCH] fix(frontend): calendar thumbnail, episode delete confirm, mark-as-watched dialog - CalendarPage: restore poster/still thumbnail (h-8 w-5) in episode items; add getTmdbPosterUrl import; extend EpisodeWithEntry type with poster_path - EpisodeSeenEditDialog: add mode 'create'|'edit' support; record prop is now optional; create mode uses useCreateEpisodeSeen with today as default date - EpisodePage: Mark as Watched button now opens EpisodeSeenEditDialog (create mode) instead of firing mutation directly; delete shows ConfirmDialog before deleting; remove unused useCreateEpisodeSeen import --- backend/routes/episode-seen.routes.js | 10 +- react_frontend/src/api/people.ts | 1 + .../dialogs/EpisodeSeenEditDialog.tsx | 100 ++++++++++++ react_frontend/src/hooks/useEpisodeSeen.ts | 22 +++ react_frontend/src/pages/CalendarPage.tsx | 52 +++---- react_frontend/src/pages/EntryDetailsPage.tsx | 4 +- react_frontend/src/pages/EpisodePage.tsx | 144 +++++++++++++----- .../src/pages/PersonDetailsPage.tsx | 118 +++++++++++--- 8 files changed, 350 insertions(+), 101 deletions(-) create mode 100644 react_frontend/src/components/dialogs/EpisodeSeenEditDialog.tsx diff --git a/backend/routes/episode-seen.routes.js b/backend/routes/episode-seen.routes.js index 293f4d4..86bc747 100644 --- a/backend/routes/episode-seen.routes.js +++ b/backend/routes/episode-seen.routes.js @@ -10,15 +10,15 @@ episodeSeenRouter.post('/', episodeSeenController.createEpisodeSeen); // * GET - ALL EPISODE SEEN episodeSeenRouter.get('/', episodeSeenController.getEpisodesSeen); -// * GET - EPISODE SEEN BY ID -episodeSeenRouter.get('/:id', episodeSeenController.getEpisodeSeenById); - -// * GET - EPISODE SEEN BY EPISODE ID +// * GET - EPISODE SEEN BY EPISODE ID (must come before /:id) episodeSeenRouter.get('/by-episode/:episodeId', episodeSeenController.getEpisodeSeensByEpisodeId); -// * GET - EPISODE SEEN BY ENTRY ID +// * GET - EPISODE SEEN BY ENTRY ID (must come before /:id) episodeSeenRouter.get('/by-entry/:entryId', episodeSeenController.getEpisodeSeensByEntryId); +// * GET - EPISODE SEEN BY ID +episodeSeenRouter.get('/:id', episodeSeenController.getEpisodeSeenById); + // * PUT - UPDATE EPISODE SEEN episodeSeenRouter.put('/:id', episodeSeenController.updateEpisodeSeen); diff --git a/react_frontend/src/api/people.ts b/react_frontend/src/api/people.ts index 6ed1d8d..5f33bf2 100644 --- a/react_frontend/src/api/people.ts +++ b/react_frontend/src/api/people.ts @@ -13,6 +13,7 @@ export interface TmdbFilmographyItem { job?: string; department?: string; credit_id?: string; + popularity?: number; } export interface TmdbFilmographyResponse { diff --git a/react_frontend/src/components/dialogs/EpisodeSeenEditDialog.tsx b/react_frontend/src/components/dialogs/EpisodeSeenEditDialog.tsx new file mode 100644 index 0000000..22affc5 --- /dev/null +++ b/react_frontend/src/components/dialogs/EpisodeSeenEditDialog.tsx @@ -0,0 +1,100 @@ +import { useState } from 'react'; +import { + Dialog, + DialogContent, + DialogFooter, + DialogHeader, + DialogTitle, +} from '@/components/ui/dialog'; +import { Button } from '@/components/ui/button'; +import { Input } from '@/components/ui/input'; +import { Label } from '@/components/ui/label'; +import { useUpdateEpisodeSeen, useCreateEpisodeSeen } from '@/hooks/useEpisodeSeen'; +import type { EpisodeSeen } from '@/types'; + +interface EpisodeSeenEditDialogProps { + open: boolean; + onOpenChange: (open: boolean) => void; + /** Pass for edit mode */ + record?: EpisodeSeen; + /** Required for create mode */ + episodeId?: number; + entryId: number; + mode?: 'create' | 'edit'; +} + +export function EpisodeSeenEditDialog({ + open, + onOpenChange, + record, + episodeId, + entryId, + mode = record ? 'edit' : 'create', +}: EpisodeSeenEditDialogProps) { + const today = new Date().toISOString().split('T')[0]; + const [date, setDate] = useState(record?.date_seen?.split('T')[0] ?? today); + const [seenWith, setSeenWith] = useState(record?.seen_with ?? ''); + + const updateEpisodeSeen = useUpdateEpisodeSeen(); + const createEpisodeSeen = useCreateEpisodeSeen(); + + const handleSave = () => { + if (mode === 'edit' && record) { + updateEpisodeSeen.mutate({ + id: record.id, + data: { + episode_id: record.episode_id, + entry_id: entryId, + date_seen: date, + seen_with: seenWith || null, + }, + }); + } else { + const epId = episodeId ?? record?.episode_id; + if (!epId) return; + createEpisodeSeen.mutate({ + entry_id: entryId, + episode_id: epId, + date_seen: date, + seen_with: seenWith || undefined, + }); + } + onOpenChange(false); + }; + + return ( + + + + {mode === 'edit' ? 'Edit Watch Record' : 'Mark as Watched'} + +
+
+ + setDate(e.target.value)} + /> +
+
+ + setSeenWith(e.target.value)} + placeholder="Optional" + /> +
+
+ + + + +
+
+ ); +} diff --git a/react_frontend/src/hooks/useEpisodeSeen.ts b/react_frontend/src/hooks/useEpisodeSeen.ts index 1b3134a..ac330ea 100644 --- a/react_frontend/src/hooks/useEpisodeSeen.ts +++ b/react_frontend/src/hooks/useEpisodeSeen.ts @@ -40,6 +40,28 @@ export function useCreateEpisodeSeen() { }); } +export function useUpdateEpisodeSeen() { + const queryClient = useQueryClient(); + + return useMutation({ + mutationFn: ({ + id, + data, + }: { + id: number; + data: { episode_id: number; entry_id: number; date_seen?: string; seen_with?: string | null }; + }) => episodeSeenApi.update(id, data), + onSuccess: (_data, variables) => { + queryClient.invalidateQueries({ + queryKey: episodeSeenKeys.byEpisode(variables.data.episode_id), + }); + queryClient.invalidateQueries({ + queryKey: entryKeys.detail(variables.data.entry_id), + }); + }, + }); +} + export function useDeleteEpisodeSeen() { const queryClient = useQueryClient(); diff --git a/react_frontend/src/pages/CalendarPage.tsx b/react_frontend/src/pages/CalendarPage.tsx index 6d3fdd7..9de9827 100644 --- a/react_frontend/src/pages/CalendarPage.tsx +++ b/react_frontend/src/pages/CalendarPage.tsx @@ -4,8 +4,8 @@ import { format, startOfMonth, endOfMonth, eachDayOfInterval, getDay, addMonths, import { ChevronLeft, ChevronRight } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { useEpisodesByMonth } from '@/hooks/useEpisodes'; -import { getTmdbPosterUrl, getPosterUrl } from '@/lib/media-utils'; import { Tooltip, TooltipContent, TooltipTrigger, TooltipProvider } from '@/components/ui/tooltip'; +import { getTmdbPosterUrl } from '@/lib/media-utils'; import type { Episode } from '@/types'; const DAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; @@ -123,13 +123,7 @@ export function CalendarPage() { function EpisodeCalendarItem({ episode }: { episode: Episode }) { type EpisodeWithEntry = Episode & { - entry?: { - id: number; - title?: string; - poster_path?: string | null; - medias?: unknown[]; - isInLibrary?: boolean; - }; + entry?: { id: number; title?: string; poster_path?: string | null }; }; const ep = episode as EpisodeWithEntry; const entry = ep.entry; @@ -137,29 +131,29 @@ function EpisodeCalendarItem({ episode }: { episode: Episode }) { const entryTitle = entry?.title ?? ''; const seasonId = episode.season_id; - const posterSrc = episode.still_path - ? getTmdbPosterUrl(episode.still_path, 'w92') - : entry - ? getPosterUrl({ ...(entry as Parameters[0]), isInLibrary: false }) - : undefined; - const seasonLabel = `S${String(seasonId).padStart(2, '0')}`; const episodeLabel = `E${String(episode.episode_number).padStart(2, '0')}`; + const thumbSrc = episode.still_path + ? getTmdbPosterUrl(episode.still_path, 'w92') + : entry?.poster_path + ? getTmdbPosterUrl(entry.poster_path, 'w92') + : undefined; + const content = ( -
- {posterSrc && ( +
+ {thumbSrc && ( )} -
+

- {entryTitle} + {entryTitle || 'Unknown'}

-

+

{seasonLabel} {episodeLabel}

@@ -181,13 +175,15 @@ function EpisodeCalendarItem({ episode }: { episode: Episode }) { )} -

{entryTitle}

- {episode.name && ( -

{episode.name}

- )} -

- {seasonLabel} {episodeLabel} -

+
+

{entryTitle}

+ {episode.name && ( +

{episode.name}

+ )} +

+ {seasonLabel} {episodeLabel} +

+
); diff --git a/react_frontend/src/pages/EntryDetailsPage.tsx b/react_frontend/src/pages/EntryDetailsPage.tsx index 7fd1317..a5ad767 100644 --- a/react_frontend/src/pages/EntryDetailsPage.tsx +++ b/react_frontend/src/pages/EntryDetailsPage.tsx @@ -189,14 +189,14 @@ export function EntryDetailsPage() { )}
- {director && ( + {director?.people?.name && (

by{' '} - {director.people?.name} + {director.people.name}

)} diff --git a/react_frontend/src/pages/EpisodePage.tsx b/react_frontend/src/pages/EpisodePage.tsx index 6e4d644..8a588e7 100644 --- a/react_frontend/src/pages/EpisodePage.tsx +++ b/react_frontend/src/pages/EpisodePage.tsx @@ -1,16 +1,21 @@ import { useState } from 'react'; -import { useParams, Link } from 'react-router-dom'; +import { useParams, useNavigate } from 'react-router-dom'; import { useQuery } from '@tanstack/react-query'; import { seasonsApi } from '@/api/seasons'; -import { useEpisodeSeenByEpisode, useCreateEpisodeSeen } from '@/hooks/useEpisodeSeen'; +import { + useEpisodeSeenByEpisode, + useDeleteEpisodeSeen, +} from '@/hooks/useEpisodeSeen'; import { Skeleton } from '@/components/ui/skeleton'; import { Button } from '@/components/ui/button'; import { Separator } from '@/components/ui/separator'; import { EpisodeWatchHistory } from '@/components/entries/EpisodeWatchHistory'; +import { EpisodeSeenEditDialog } from '@/components/dialogs/EpisodeSeenEditDialog'; +import { ConfirmDialog } from '@/components/dialogs/ConfirmDialog'; import { CastList } from '@/components/entries/CastList'; import { Eye, ChevronLeft, ChevronRight, Clock } from 'lucide-react'; import { getTmdbPosterUrl, formatDate, formatRuntime } from '@/lib/media-utils'; -import type { Episode } from '@/types'; +import type { Episode, EpisodeSeen } from '@/types'; export function EpisodePage() { const { entryId, seasonId, episodeId } = useParams<{ @@ -18,6 +23,7 @@ export function EpisodePage() { seasonId: string; episodeId: string; }>(); + const navigate = useNavigate(); const { data: episodes = [] } = useQuery({ queryKey: ['seasons', parseInt(seasonId!, 10), 'episodes'], @@ -25,9 +31,15 @@ export function EpisodePage() { }); const epId = parseInt(episodeId!, 10); + const entryIdNum = parseInt(entryId!, 10); const episode: Episode | undefined = episodes.find((ep: Episode) => ep.id === epId); const { data: watchHistory = [] } = useEpisodeSeenByEpisode(epId); const createEpisodeSeen = useCreateEpisodeSeen(); + const deleteEpisodeSeen = useDeleteEpisodeSeen(); + + const [editRecord, setEditRecord] = useState(null); + const [deleteTarget, setDeleteTarget] = useState(null); + const [showAddDialog, setShowAddDialog] = useState(false); // Find prev/next episode const currentIndex = episodes.findIndex((ep: Episode) => ep.id === epId); @@ -45,35 +57,35 @@ export function EpisodePage() { ); } - const handleMarkWatched = () => { - createEpisodeSeen.mutate({ - entry_id: parseInt(entryId!, 10), - episode_id: episode.id, - date_seen: new Date().toISOString().split('T')[0], - }); - }; - return (
- {/* Thumbnail */} + {/* Top bar: nav breadcrumb + Mark Watched */} +
+
+ + S{String(parseInt(seasonId!, 10)).padStart(2, '0')} E{String(episode.episode_number).padStart(2, '0')} + +
+ +
+ + {/* High-quality thumbnail */} {episode.still_path && ( -
+
{episode.name}
)} {/* Info */}
-
- - Episode {episode.episode_number} - -

{episode.name}

-
+

{episode.name}

{episode.air_date && {formatDate(episode.air_date)}} @@ -90,11 +102,6 @@ export function EpisodePage() { {episode.overview}

)} - -
{/* Guest Stars */} @@ -109,38 +116,93 @@ export function EpisodePage() { {watchHistory.length > 0 && ( <> - + { + const rec = watchHistory.find((r) => r.id === id) as EpisodeSeen | undefined; + if (rec) setEditRecord(rec); + }} + onDelete={(id) => setDeleteTarget(id)} + /> )} - {/* Navigation */} + {/* Prev / Next navigation */} -
+
{prevEpisode ? ( - ) : (
)} {nextEpisode ? ( - ) : (
)}
+ + {/* Add watch record dialog */} + {showAddDialog && ( + + )} + + {/* Edit dialog */} + {editRecord && ( + { if (!open) setEditRecord(null); }} + mode="edit" + record={editRecord} + entryId={entryIdNum} + /> + )} + + {/* Delete confirm dialog */} + { if (!open) setDeleteTarget(null); }} + title="Delete Watch Record" + description="Are you sure you want to remove this watch record? This cannot be undone." + confirmLabel="Delete" + variant="destructive" + onConfirm={() => { + if (deleteTarget !== null) { + deleteEpisodeSeen.mutate({ id: deleteTarget, entryId: entryIdNum, episodeId: epId }); + setDeleteTarget(null); + } + }} + />
); } diff --git a/react_frontend/src/pages/PersonDetailsPage.tsx b/react_frontend/src/pages/PersonDetailsPage.tsx index 8a86508..de399da 100644 --- a/react_frontend/src/pages/PersonDetailsPage.tsx +++ b/react_frontend/src/pages/PersonDetailsPage.tsx @@ -1,14 +1,16 @@ import { useParams } from 'react-router-dom'; +import { useState } from 'react'; import { usePerson, usePersonTmdbFilmography } from '@/hooks/usePeople'; import { useLibrary } from '@/hooks/useEntries'; import { useLibraryStore } from '@/stores/useLibraryStore'; import { Skeleton } from '@/components/ui/skeleton'; import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'; import { Separator } from '@/components/ui/separator'; -import { Badge } from '@/components/ui/badge'; +import { Button } from '@/components/ui/button'; import { EntryCard } from '@/components/entries/EntryCard'; import { getProfileUrl, formatDate } from '@/lib/media-utils'; -import { getTmdbImageUrl } from '@/lib/api'; +import { ChevronLeft, ChevronRight } from 'lucide-react'; +import type { TmdbEntry } from '@/types'; import type { TmdbFilmographyItem } from '@/api/people'; export function PersonDetailsPage() { @@ -80,12 +82,17 @@ interface FilmographySectionProps { } function FilmographySection({ libraryMap, libraryLoaded, tmdbFilmography, tmdbLoading }: FilmographySectionProps) { + const [libraryPage, setLibraryPage] = useState(0); + const [otherPage, setOtherPage] = useState(0); + const PAGE_SIZE = 6; // 6 cols × 1 row + const GRID = 'grid grid-cols-3 gap-3 sm:grid-cols-4 md:grid-cols-5 lg:grid-cols-6'; + if (tmdbLoading || !libraryLoaded) { return (

Filmography

-
- {Array.from({ length: 10 }).map((_, i) => ( +
+ {Array.from({ length: 6 }).map((_, i) => ( ))}
@@ -111,10 +118,12 @@ function FilmographySection({ libraryMap, libraryLoaded, tmdbFilmography, tmdbLo } } - const libraryCredits = dedupedCredits.filter((c) => tmdbIdToLibraryEntry.has(c.id)); - const otherCredits = dedupedCredits.filter((c) => !tmdbIdToLibraryEntry.has(c.id)); + // Sort by popularity descending + const sorted = [...dedupedCredits].sort((a, b) => (b.popularity ?? 0) - (a.popularity ?? 0)); + const libraryCredits = sorted.filter((c) => tmdbIdToLibraryEntry.has(c.id)); + const otherCredits = sorted.filter((c) => !tmdbIdToLibraryEntry.has(c.id)); - if (dedupedCredits.length === 0) { + if (sorted.length === 0) { return (

Filmography

@@ -123,15 +132,45 @@ function FilmographySection({ libraryMap, libraryLoaded, tmdbFilmography, tmdbLo ); } + const librarySlice = libraryCredits.slice(libraryPage * PAGE_SIZE, (libraryPage + 1) * PAGE_SIZE); + const otherSlice = otherCredits.slice(otherPage * PAGE_SIZE, (otherPage + 1) * PAGE_SIZE); + const libraryTotalPages = Math.ceil(libraryCredits.length / PAGE_SIZE); + const otherTotalPages = Math.ceil(otherCredits.length / PAGE_SIZE); + return (

Filmography

{libraryCredits.length > 0 && (
-

In Your Library

-
- {libraryCredits.map((credit) => { +
+

+ In Your Library ({libraryCredits.length}) +

+ {libraryTotalPages > 1 && ( +
+ + + {libraryPage + 1}/{libraryTotalPages} + + +
+ )} +
+
+ {librarySlice.map((credit) => { const entry = tmdbIdToLibraryEntry.get(credit.id)!; return (
@@ -148,23 +187,52 @@ function FilmographySection({ libraryMap, libraryLoaded, tmdbFilmography, tmdbLo {otherCredits.length > 0 && (
-

Not in Library

-
- {otherCredits.map((credit) => { - const title = credit.title ?? credit.name ?? 'Unknown'; - const posterSrc = credit.poster_path - ? getTmdbImageUrl(credit.poster_path, 'w342') - : '/images/default-poster.png'; +
+

+ Not in Library ({otherCredits.length}) +

+ {otherTotalPages > 1 && ( +
+ + + {otherPage + 1}/{otherTotalPages} + + +
+ )} +
+
+ {otherSlice.map((credit) => { + const tmdbEntry: TmdbEntry = { + id: credit.id, + title: credit.title, + name: credit.name, + poster_path: credit.poster_path, + backdrop_path: null, + release_date: credit.release_date, + first_air_date: credit.first_air_date, + media_type: credit.media_type, + overview: '', + vote_average: 0, + vote_count: 0, + genre_ids: [], + popularity: credit.popularity ?? 0, + }; return (
-
- {title} -
-

{title}

- - {credit.media_type === 'tv' ? 'TV' : 'Movie'} - -
+ {credit.character && (

{credit.character}

)}