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,146 @@
|
||||
import { useState } from 'react';
|
||||
import { useParams, Link } from 'react-router-dom';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { seasonsApi } from '@/api/seasons';
|
||||
import { useEpisodeSeenByEpisode, useCreateEpisodeSeen } 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 { 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';
|
||||
|
||||
export function EpisodePage() {
|
||||
const { entryId, seasonId, episodeId } = useParams<{
|
||||
entryId: string;
|
||||
seasonId: string;
|
||||
episodeId: string;
|
||||
}>();
|
||||
|
||||
const { data: episodes = [] } = useQuery({
|
||||
queryKey: ['seasons', parseInt(seasonId!, 10), 'episodes'],
|
||||
queryFn: () => seasonsApi.getEpisodes(parseInt(seasonId!, 10)),
|
||||
});
|
||||
|
||||
const epId = parseInt(episodeId!, 10);
|
||||
const episode: Episode | undefined = episodes.find((ep: Episode) => ep.id === epId);
|
||||
const { data: watchHistory = [] } = useEpisodeSeenByEpisode(epId);
|
||||
const createEpisodeSeen = useCreateEpisodeSeen();
|
||||
|
||||
// Find prev/next episode
|
||||
const currentIndex = episodes.findIndex((ep: Episode) => ep.id === epId);
|
||||
const prevEpisode: Episode | undefined = currentIndex > 0 ? episodes[currentIndex - 1] : undefined;
|
||||
const nextEpisode: Episode | undefined =
|
||||
currentIndex < episodes.length - 1 ? episodes[currentIndex + 1] : undefined;
|
||||
|
||||
if (!episode) {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<Skeleton className="h-48 w-full rounded-lg" />
|
||||
<Skeleton className="h-6 w-48" />
|
||||
<Skeleton className="h-4 w-80" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const handleMarkWatched = () => {
|
||||
createEpisodeSeen.mutate({
|
||||
entry_id: parseInt(entryId!, 10),
|
||||
episode_id: episode.id,
|
||||
date_seen: new Date().toISOString().split('T')[0],
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-8">
|
||||
{/* Thumbnail */}
|
||||
{episode.still_path && (
|
||||
<div className="overflow-hidden rounded-lg">
|
||||
<img
|
||||
src={getTmdbPosterUrl(episode.still_path, 'w780')}
|
||||
alt={episode.name}
|
||||
className="w-full max-h-80 object-cover"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Info */}
|
||||
<div className="space-y-3">
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="text-sm text-muted-foreground">
|
||||
Episode {episode.episode_number}
|
||||
</span>
|
||||
<h1 className="text-2xl font-bold">{episode.name}</h1>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-3 text-sm text-muted-foreground">
|
||||
{episode.air_date && <span>{formatDate(episode.air_date)}</span>}
|
||||
{episode.runtime && (
|
||||
<span className="flex items-center gap-1">
|
||||
<Clock className="h-3 w-3" />
|
||||
{formatRuntime(episode.runtime)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{episode.overview && (
|
||||
<p className="text-sm text-muted-foreground leading-relaxed max-w-2xl">
|
||||
{episode.overview}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<Button size="sm" onClick={handleMarkWatched}>
|
||||
<Eye className="mr-1 h-4 w-4" />
|
||||
Mark as Watched
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Guest Stars */}
|
||||
{episode.guest_stars && episode.guest_stars.length > 0 && (
|
||||
<>
|
||||
<Separator />
|
||||
<CastList credits={episode.guest_stars} />
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Watch History */}
|
||||
{watchHistory.length > 0 && (
|
||||
<>
|
||||
<Separator />
|
||||
<EpisodeWatchHistory watchHistory={watchHistory} />
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Navigation */}
|
||||
<Separator />
|
||||
<div className="flex justify-between">
|
||||
{prevEpisode ? (
|
||||
<Button variant="outline" asChild>
|
||||
<Link
|
||||
to={`/entry/${entryId}/season/${seasonId}/episode/${prevEpisode.id}`}
|
||||
>
|
||||
<ChevronLeft className="mr-1 h-4 w-4" />
|
||||
E{prevEpisode.episode_number}: {prevEpisode.name}
|
||||
</Link>
|
||||
</Button>
|
||||
) : (
|
||||
<div />
|
||||
)}
|
||||
{nextEpisode ? (
|
||||
<Button variant="outline" asChild>
|
||||
<Link
|
||||
to={`/entry/${entryId}/season/${seasonId}/episode/${nextEpisode.id}`}
|
||||
>
|
||||
E{nextEpisode.episode_number}: {nextEpisode.name}
|
||||
<ChevronRight className="ml-1 h-4 w-4" />
|
||||
</Link>
|
||||
</Button>
|
||||
) : (
|
||||
<div />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user