Files
Showy/react_frontend/src/pages/CalendarPage.tsx
T
Mohammed Abad ab20a5e64f feat: multi-page improvements, bug fixes, and new features
Library:
- Exclude hidden entries from all/movies/tv/favorites tabs (only show in hidden tab)

Entry Details:
- Move favorite, mark watched, and more actions to top-right as icon-only buttons with tooltips
- Fix season card play button — marks next unwatched episode as seen

Seasons Page:
- Fix episode watch button (was a TODO stub, now calls createEpisodeSeen)

Episode Page:
- Fix UI not updating after deleting the last watch record — invalidate season episodes query on delete

Dashboard:
- Fix Top Genres 404 — was calling non-existent GET /statistics, now uses /statistics/watch-time
- Fix TopGenresChart genre counting (Genre objects were wrongly cast as strings)
- Add LibraryGrowthChart (cumulative titles added over time)
- Add MediaTypeChart (Movies vs TV Series donut chart)

Home Page:
- Add TrendingSlider hero at top of page with auto-advance, dots, and prev/next nav
- Fix slider prev/next buttons (stable callbacks via ref, plain buttons, reactive library state)
- Add debounce (400ms) to search input
- Add Top Rated section (movies & TV)
- Add Upcoming section (movies)
- Replace inline "More" expand with link to /discover/:category

Discover Page (new):
- Full-page TMDB browser per category (trending/popular/top-rated/upcoming)
- Movie/TV tab toggle
- IntersectionObserver infinite scroll

Calendar:
- Fix large season numbers — use season.season_number instead of season_id (DB primary key)

Backend:
- Add fetchTopRated() and fetchUpcoming() to tmdbService
- Add GET /entries/tmdb/top-rated/:type and /entries/tmdb/upcoming/movie routes
2026-04-02 03:29:54 +01:00

194 lines
6.7 KiB
TypeScript

import { useState, useMemo } from 'react';
import { Link } from 'react-router-dom';
import { format, startOfMonth, endOfMonth, eachDayOfInterval, getDay, addMonths, subMonths, isSameDay } from 'date-fns';
import { ChevronLeft, ChevronRight } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { useEpisodesByMonth } from '@/hooks/useEpisodes';
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'];
export function CalendarPage() {
const [currentDate, setCurrentDate] = useState(new Date());
const monthStart = startOfMonth(currentDate);
const monthEnd = endOfMonth(currentDate);
const startDateStr = format(monthStart, 'yyyy-MM-dd');
const endDateStr = format(monthEnd, 'yyyy-MM-dd');
const { data: episodes = [] } = useEpisodesByMonth(startDateStr, endDateStr);
const days = useMemo(() => eachDayOfInterval({ start: monthStart, end: monthEnd }), [monthStart, monthEnd]);
const startDayOfWeek = getDay(monthStart);
// Group episodes by date
const episodesByDate = useMemo(() => {
const map = new Map<string, typeof episodes>();
episodes.forEach((ep) => {
if (!ep.air_date) return;
const key = format(new Date(ep.air_date), 'yyyy-MM-dd');
const existing = map.get(key) || [];
existing.push(ep);
map.set(key, existing);
});
return map;
}, [episodes]);
return (
<div className="flex flex-col h-[calc(100vh-7rem)]">
<div className="flex items-center justify-between mb-4 shrink-0">
<h1 className="text-2xl font-bold">Calendar</h1>
<div className="flex items-center gap-2">
<Button
variant="outline"
size="icon"
onClick={() => setCurrentDate(subMonths(currentDate, 1))}
>
<ChevronLeft className="h-4 w-4" />
</Button>
<span className="min-w-35 text-center font-medium">
{format(currentDate, 'MMMM yyyy')}
</span>
<Button
variant="outline"
size="icon"
onClick={() => setCurrentDate(addMonths(currentDate, 1))}
>
<ChevronRight className="h-4 w-4" />
</Button>
</div>
</div>
{/* Calendar Grid — fills remaining height */}
<TooltipProvider>
<div className="flex flex-col flex-1 rounded-lg border border-border overflow-hidden min-h-0">
{/* Day headers */}
<div className="grid grid-cols-7 bg-muted/50 shrink-0">
{DAYS.map((day) => (
<div key={day} className="px-2 py-2 text-center text-xs font-medium text-muted-foreground">
{day}
</div>
))}
</div>
{/* Day cells */}
<div className="grid grid-cols-7 flex-1 overflow-y-auto">
{/* Empty cells for offset */}
{Array.from({ length: startDayOfWeek }).map((_, i) => (
<div key={`empty-${i}`} className="border-t border-r border-border bg-muted/20" />
))}
{days.map((day) => {
const key = format(day, 'yyyy-MM-dd');
const dayEpisodes = episodesByDate.get(key) || [];
const isToday = isSameDay(day, new Date());
return (
<div
key={key}
className={`border-t border-r border-border p-1.5 ${
isToday ? 'bg-primary/5' : ''
}`}
>
<span
className={`inline-flex h-6 w-6 items-center justify-center rounded-full text-xs mb-1 ${
isToday
? 'bg-primary text-primary-foreground font-bold'
: 'text-muted-foreground'
}`}
>
{format(day, 'd')}
</span>
<div className="space-y-1">
{dayEpisodes.slice(0, 4).map((ep) => (
<EpisodeCalendarItem key={ep.id} episode={ep} />
))}
{dayEpisodes.length > 4 && (
<span className="text-[10px] text-muted-foreground pl-1">
+{dayEpisodes.length - 4} more
</span>
)}
</div>
</div>
);
})}
</div>
</div>
</TooltipProvider>
</div>
);
}
function EpisodeCalendarItem({ episode }: { episode: Episode }) {
type EpisodeWithEntry = Episode & {
entry?: { id: number; title?: string; poster_path?: string | null };
};
const ep = episode as EpisodeWithEntry;
const entry = ep.entry;
const entryId = entry?.id;
const entryTitle = entry?.title ?? '';
const seasonId = episode.season_id;
const seasonNumber = episode.season?.season_number ?? null;
const seasonLabel = seasonNumber != null
? `S${String(seasonNumber).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 = (
<div className="flex items-stretch gap-1 rounded bg-primary/10 hover:bg-primary/20 px-1 py-0.5 transition-colors cursor-pointer overflow-hidden">
{thumbSrc && (
<img
src={thumbSrc}
alt=""
className="h-8 w-5 rounded-sm object-cover shrink-0"
/>
)}
<div className="min-w-0 flex flex-col justify-center">
<p className="text-[10px] font-medium truncate leading-tight">
{entryTitle || 'Unknown'}
</p>
<p className="text-[9px] text-muted-foreground tabular-nums leading-tight">
{seasonLabel} {episodeLabel}
</p>
</div>
</div>
);
return (
<Tooltip>
<TooltipTrigger asChild>
{entryId ? (
<Link
to={`/entry/${entryId}/season/${seasonId}/episode/${episode.id}`}
className="block"
>
{content}
</Link>
) : (
<div>{content}</div>
)}
</TooltipTrigger>
<TooltipContent side="right" className="max-w-50">
<div className="space-y-0.5">
<p className="text-xs font-semibold">{entryTitle}</p>
{episode.name && (
<p className="text-xs text-muted-foreground">{episode.name}</p>
)}
<p className="text-xs text-muted-foreground tabular-nums">
{seasonLabel} {episodeLabel}
</p>
</div>
</TooltipContent>
</Tooltip>
);
}