Implemented the new react version of the frontend
This commit is contained in:
1 parent
236e6e06fb
commit
ffe7e52527
65 files changed
+5228
-177
No files matched your search
@@ -0,0 +1,139 @@
|
||||
import { useState, useMemo } from 'react';
|
||||
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 { getTmdbPosterUrl } from '@/lib/media-utils';
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
|
||||
|
||||
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="space-y-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<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-[140px] 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 */}
|
||||
<div className="rounded-lg border border-border overflow-hidden">
|
||||
{/* Day headers */}
|
||||
<div className="grid grid-cols-7 bg-muted/50">
|
||||
{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">
|
||||
{/* Empty cells for offset */}
|
||||
{Array.from({ length: startDayOfWeek }).map((_, i) => (
|
||||
<div key={`empty-${i}`} className="min-h-24 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={`min-h-24 border-t border-r border-border p-1 ${
|
||||
isToday ? 'bg-primary/5' : ''
|
||||
}`}
|
||||
>
|
||||
<span
|
||||
className={`inline-flex h-6 w-6 items-center justify-center rounded-full text-xs ${
|
||||
isToday
|
||||
? 'bg-primary text-primary-foreground font-bold'
|
||||
: 'text-muted-foreground'
|
||||
}`}
|
||||
>
|
||||
{format(day, 'd')}
|
||||
</span>
|
||||
<div className="mt-1 space-y-0.5">
|
||||
{dayEpisodes.slice(0, 3).map((ep) => (
|
||||
<Tooltip key={ep.id}>
|
||||
<TooltipTrigger asChild>
|
||||
<div className="flex items-center gap-1 rounded bg-accent/50 px-1 py-0.5">
|
||||
{ep.still_path && (
|
||||
<img
|
||||
src={getTmdbPosterUrl(ep.still_path, 'w92')}
|
||||
alt=""
|
||||
className="h-4 w-6 rounded object-cover"
|
||||
/>
|
||||
)}
|
||||
<span className="text-[10px] truncate">
|
||||
S{ep.season_id} E{ep.episode_number}
|
||||
</span>
|
||||
</div>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>
|
||||
<p className="text-xs font-medium">{ep.name}</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Episode {ep.episode_number}
|
||||
</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
))}
|
||||
{dayEpisodes.length > 3 && (
|
||||
<span className="text-[10px] text-muted-foreground pl-1">
|
||||
+{dayEpisodes.length - 3} more
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user