feat: surface availability, airing progress and the director in preview
Movies get a theatre/stream/blu-ray icon in the info row, series get the latest aired episode as S03 E07. Both reveal the relevant dates on hover or tap through a shared Hint tooltip. Release dates ride along on the details request via append_to_response and the series fields are already in the tv payload, so neither indicator costs an extra call. Theatre state is only claimed while the run can still be current, otherwise a classic with no digital entry would read as in cinemas. The credits carousel now opens with the director, read from the crew array that the credits response already carries. A series has no single director, so the one behind most episodes stands in. Drop with_cast from the starring query: TMDB ANDs it with with_people, so every director link would have resolved to an empty list. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a25252c66d
commit
6fc41c0901
11 files changed
+310
-10
No files matched your search
@@ -0,0 +1,30 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { FC } from 'react';
|
||||||
|
|
||||||
|
import Hint from '@/components/ui/hint';
|
||||||
|
import { formatDate } from '@/lib/utils';
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
airing: Airing;
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const pad = (value: number) => String(value).padStart(2, '0');
|
||||||
|
|
||||||
|
const getLabels = ({ season, episode, seasons, ended, next }: Airing) => [
|
||||||
|
`Season ${season}, episode ${episode}`,
|
||||||
|
next
|
||||||
|
? `Next episode ${formatDate(next)}`
|
||||||
|
: ended
|
||||||
|
? `Ended after ${seasons} season${seasons === 1 ? '' : 's'}`
|
||||||
|
: 'Next episode date to be announced'
|
||||||
|
];
|
||||||
|
|
||||||
|
const Airing: FC<Props> = ({ airing, className }) => (
|
||||||
|
<Hint lines={getLabels(airing)} className={className}>
|
||||||
|
S{pad(airing.season)} E{pad(airing.episode)}
|
||||||
|
</Hint>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default Airing;
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { FC } from 'react';
|
||||||
|
import { Disc, MonitorPlay, Popcorn } from 'lucide-react';
|
||||||
|
|
||||||
|
import Hint from '@/components/ui/hint';
|
||||||
|
import { getAvailabilityState, isUpcoming } from '@/data/dto/Availability';
|
||||||
|
import { formatDate } from '@/lib/utils';
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
availability: Availability;
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ICONS = {
|
||||||
|
theatre: Popcorn,
|
||||||
|
stream: MonitorPlay,
|
||||||
|
bluray: Disc
|
||||||
|
};
|
||||||
|
|
||||||
|
const getLabels = ({ theatre, stream, bluray }: Availability, state: AvailabilityState) => {
|
||||||
|
if (state === 'bluray') return [bluray ? `On Blu-ray since ${formatDate(bluray)}` : 'On Blu-ray'];
|
||||||
|
if (state === 'stream') return [stream ? `Streaming since ${formatDate(stream)}` : 'Streaming'];
|
||||||
|
if (theatre && isUpcoming(theatre)) return [`In theatres from ${formatDate(theatre)}`];
|
||||||
|
|
||||||
|
const announced = [
|
||||||
|
stream && isUpcoming(stream) && `Streaming from ${formatDate(stream)}`,
|
||||||
|
bluray && isUpcoming(bluray) && `Blu-ray from ${formatDate(bluray)}`
|
||||||
|
].filter(Boolean) as string[];
|
||||||
|
|
||||||
|
return ['In theatres only', ...(announced.length ? announced : ['Streaming date to be announced'])];
|
||||||
|
};
|
||||||
|
|
||||||
|
const Availability: FC<Props> = ({ availability, className }) => {
|
||||||
|
const state = getAvailabilityState(availability);
|
||||||
|
|
||||||
|
if (!state) return null;
|
||||||
|
|
||||||
|
const Icon = ICONS[state];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Hint
|
||||||
|
lines={getLabels(availability, state)}
|
||||||
|
className={className}
|
||||||
|
triggerClassName='text-muted-foreground transition-colors hover:text-foreground'
|
||||||
|
>
|
||||||
|
<Icon size={16} />
|
||||||
|
</Hint>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Availability;
|
||||||
@@ -10,6 +10,8 @@ import { Modal } from '@/components/ui/dialog';
|
|||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
import Actions from './components/Actions';
|
import Actions from './components/Actions';
|
||||||
|
import Airing from './components/Airing';
|
||||||
|
import Availability from './components/Availability';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
show?: Show & Partial<Details>;
|
show?: Show & Partial<Details>;
|
||||||
@@ -52,8 +54,12 @@ const Preview: FC<Props> = ({
|
|||||||
<div className={cn('flex grow flex-col bg-background', { 'p-0 pt-2 md:p-2': isModal })}>
|
<div className={cn('flex grow flex-col bg-background', { 'p-0 pt-2 md:p-2': isModal })}>
|
||||||
<span className='order-3 mb-4 text-3xl md:order-1 md:line-clamp-2'>{show.title}</span>
|
<span className='order-3 mb-4 text-3xl md:order-1 md:line-clamp-2'>{show.title}</span>
|
||||||
|
|
||||||
<div className='order-3 mb-4 flex w-full flex-wrap gap-5 whitespace-nowrap text-sm md:order-2'>
|
<div className='order-3 mb-4 flex w-full flex-wrap items-center gap-5 whitespace-nowrap text-sm md:order-2'>
|
||||||
<span>{new Date(show.release).getFullYear()}</span>
|
<span>{new Date(show.release).getFullYear()}</span>
|
||||||
|
{Boolean(show.availability) && (
|
||||||
|
<Availability availability={show.availability!} className='animate-fade-aside-slide-in opacity-0' />
|
||||||
|
)}
|
||||||
|
{Boolean(show.airing) && <Airing airing={show.airing!} className='animate-fade-aside-slide-in opacity-0' />}
|
||||||
{Boolean(show.runtime) && (
|
{Boolean(show.runtime) && (
|
||||||
<span className='animate-fade-aside-slide-in opacity-0'>{show.runtime} minutes</span>
|
<span className='animate-fade-aside-slide-in opacity-0'>{show.runtime} minutes</span>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { FC, ReactNode, useState } from 'react';
|
||||||
|
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
lines: string[];
|
||||||
|
children: ReactNode;
|
||||||
|
className?: string;
|
||||||
|
triggerClassName?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Hint: FC<Props> = ({ lines, children, className, triggerClassName }) => {
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
|
||||||
|
// an animation that lands on a transform turns this wrapper into a stacking context,
|
||||||
|
// so the tooltip can only reach above the following rows by raising the wrapper itself
|
||||||
|
return (
|
||||||
|
<span className={cn('relative z-10 inline-flex', className)}>
|
||||||
|
<button
|
||||||
|
type='button'
|
||||||
|
aria-label={lines.join('. ')}
|
||||||
|
className={cn('inline-flex cursor-help items-center', triggerClassName)}
|
||||||
|
// a tap fires pointerenter too, opening what the click would then toggle shut
|
||||||
|
onPointerEnter={({ pointerType }) => pointerType === 'mouse' && setOpen(true)}
|
||||||
|
onPointerLeave={({ pointerType }) => pointerType === 'mouse' && setOpen(false)}
|
||||||
|
onClick={() => setOpen((value) => !value)}
|
||||||
|
onBlur={() => setOpen(false)}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</button>
|
||||||
|
<span
|
||||||
|
role='tooltip'
|
||||||
|
aria-hidden={!open}
|
||||||
|
className={cn(
|
||||||
|
'pointer-events-none absolute left-1/2 top-full z-10 mt-1.5 -translate-x-1/2 whitespace-nowrap rounded-md border bg-popover px-2 py-1 text-xs text-popover-foreground shadow-md transition-opacity',
|
||||||
|
open ? 'opacity-100' : 'opacity-0'
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{lines.map((line) => (
|
||||||
|
<span key={line} className='block'>
|
||||||
|
{line}
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Hint;
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
const ENDED_STATUSES = ['Ended', 'Canceled'];
|
||||||
|
|
||||||
|
export const mapDetailsToAiring = ({
|
||||||
|
last_episode_to_air,
|
||||||
|
next_episode_to_air,
|
||||||
|
number_of_seasons,
|
||||||
|
status
|
||||||
|
}: TMDBSeriesDetails): Airing | undefined => {
|
||||||
|
// before a premiere there is nothing aired yet, the upcoming episode is the only position we have
|
||||||
|
const current = last_episode_to_air || next_episode_to_air;
|
||||||
|
|
||||||
|
if (!current) return undefined;
|
||||||
|
|
||||||
|
return {
|
||||||
|
season: current.season_number,
|
||||||
|
episode: current.episode_number,
|
||||||
|
seasons: number_of_seasons || current.season_number,
|
||||||
|
ended: ENDED_STATUSES.includes(status || ''),
|
||||||
|
next: next_episode_to_air?.air_date || undefined
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default mapDetailsToAiring;
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
// TMDB release types: 1 premiere, 2 limited theatrical, 3 theatrical, 4 digital, 5 physical, 6 TV
|
||||||
|
const STATE_BY_RELEASE_TYPE: Record<number, AvailabilityState> = {
|
||||||
|
1: 'theatre',
|
||||||
|
2: 'theatre',
|
||||||
|
3: 'theatre',
|
||||||
|
4: 'stream',
|
||||||
|
5: 'bluray'
|
||||||
|
};
|
||||||
|
|
||||||
|
/** How long a movie is assumed to still be running in theatres when TMDB has no digital/physical date yet */
|
||||||
|
const THEATRICAL_WINDOW = 120 * 24 * 60 * 60 * 1000;
|
||||||
|
|
||||||
|
export const mapReleaseDatesToAvailability = (results?: TMDBCountryReleaseDates[]): Availability | undefined => {
|
||||||
|
// TMDB reports dates per country, it doesn't matter where a window opened first — only when
|
||||||
|
const availability = (results || []).reduce<Availability>((dates, { release_dates }) => {
|
||||||
|
(release_dates || []).forEach(({ type, release_date }) => {
|
||||||
|
const state = STATE_BY_RELEASE_TYPE[type];
|
||||||
|
const earliest = state && dates[state];
|
||||||
|
|
||||||
|
if (!state || !release_date) return;
|
||||||
|
if (!earliest || release_date < earliest) dates[state] = release_date;
|
||||||
|
});
|
||||||
|
|
||||||
|
return dates;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
return Object.keys(availability).length ? availability : undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const isUpcoming = (date?: string) => Boolean(date && Date.parse(date) > Date.now());
|
||||||
|
|
||||||
|
const isReleased = (date?: string) => Boolean(date && Date.parse(date) <= Date.now());
|
||||||
|
|
||||||
|
export const getAvailabilityState = ({ theatre, stream, bluray }: Availability): AvailabilityState | undefined => {
|
||||||
|
if (isReleased(bluray)) return 'bluray';
|
||||||
|
if (isReleased(stream)) return 'stream';
|
||||||
|
if (isUpcoming(theatre)) return 'theatre';
|
||||||
|
if (!theatre) return undefined;
|
||||||
|
|
||||||
|
// Still in theatres only while the run lasts or while a digital/physical date is announced but not reached,
|
||||||
|
// otherwise TMDB simply never got the digital entry and the movie is long out of cinemas
|
||||||
|
const isRunning = Date.now() - Date.parse(theatre) < THEATRICAL_WINDOW;
|
||||||
|
|
||||||
|
return isRunning || isUpcoming(stream) || isUpcoming(bluray) ? 'theatre' : 'stream';
|
||||||
|
};
|
||||||
+22
-4
@@ -5,6 +5,17 @@ export type CreditsQueryProps = {
|
|||||||
showType?: Show['type'];
|
showType?: Show['type'];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const photo = (path: string) => `https://image.tmdb.org/t/p/w185${path}`;
|
||||||
|
|
||||||
|
// a series has no single director, so the one behind most episodes stands in for it
|
||||||
|
const findDirector = (crew: Crew[] = []) =>
|
||||||
|
crew
|
||||||
|
.filter(
|
||||||
|
({ profile_path, job, jobs }) =>
|
||||||
|
profile_path && (job === 'Director' || jobs?.some((entry) => entry.job === 'Director'))
|
||||||
|
)
|
||||||
|
.sort((a, b) => (b.total_episode_count || 0) - (a.total_episode_count || 0))[0];
|
||||||
|
|
||||||
const creditsQuery = ({ showId, showType }: CreditsQueryProps) => ({
|
const creditsQuery = ({ showId, showType }: CreditsQueryProps) => ({
|
||||||
enabled: Boolean(showId),
|
enabled: Boolean(showId),
|
||||||
queryKey: ['credits', showId, showType],
|
queryKey: ['credits', showId, showType],
|
||||||
@@ -12,12 +23,15 @@ const creditsQuery = ({ showId, showType }: CreditsQueryProps) => ({
|
|||||||
movieAdvisor
|
movieAdvisor
|
||||||
.get<{
|
.get<{
|
||||||
cast: Array<Actor | AggregatedActor>;
|
cast: Array<Actor | AggregatedActor>;
|
||||||
|
crew: Crew[];
|
||||||
}>(`/${showType}/${showId}/${showType === 'tv' ? 'aggregate_credits' : 'credits'}`)
|
}>(`/${showType}/${showId}/${showType === 'tv' ? 'aggregate_credits' : 'credits'}`)
|
||||||
.then(({ cast }) => {
|
.then(({ cast, crew }) => {
|
||||||
return cast
|
const director = findDirector(crew);
|
||||||
.filter((person) => person.profile_path)
|
|
||||||
|
const actors: Actor[] = cast
|
||||||
|
.filter((person) => person.profile_path && person.id !== director?.id)
|
||||||
.map((actor) => {
|
.map((actor) => {
|
||||||
const photoUrl = `https://image.tmdb.org/t/p/w185${actor.profile_path}`;
|
const photoUrl = photo(actor.profile_path);
|
||||||
|
|
||||||
if ('character' in actor) return { ...actor, photoUrl };
|
if ('character' in actor) return { ...actor, photoUrl };
|
||||||
|
|
||||||
@@ -25,6 +39,10 @@ const creditsQuery = ({ showId, showType }: CreditsQueryProps) => ({
|
|||||||
|
|
||||||
return { ...actor, character, photoUrl };
|
return { ...actor, character, photoUrl };
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!director) return actors;
|
||||||
|
|
||||||
|
return [{ ...director, character: 'Director', photoUrl: photo(director.profile_path) }, ...actors];
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+18
-2
@@ -1,4 +1,6 @@
|
|||||||
import movieAdvisor from '../clients/movieAdvisor';
|
import movieAdvisor from '../clients/movieAdvisor';
|
||||||
|
import { mapDetailsToAiring } from '../dto/Airing';
|
||||||
|
import { mapReleaseDatesToAvailability } from '../dto/Availability';
|
||||||
import { mapMovieSeriesToShow } from '../dto/Show';
|
import { mapMovieSeriesToShow } from '../dto/Show';
|
||||||
|
|
||||||
export type DetailsQueryProps = {
|
export type DetailsQueryProps = {
|
||||||
@@ -6,13 +8,27 @@ export type DetailsQueryProps = {
|
|||||||
showType?: Show['type'];
|
showType?: Show['type'];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type DetailsResponse = (Movie | Series) &
|
||||||
|
Details &
|
||||||
|
TMDBSeriesDetails & {
|
||||||
|
release_dates?: { results: TMDBCountryReleaseDates[] };
|
||||||
|
};
|
||||||
|
|
||||||
const detailsQuery = ({ showId, showType }: DetailsQueryProps) => ({
|
const detailsQuery = ({ showId, showType }: DetailsQueryProps) => ({
|
||||||
enabled: Boolean(showId),
|
enabled: Boolean(showId),
|
||||||
queryKey: ['details', showId, showType],
|
queryKey: ['details', showId, showType],
|
||||||
queryFn: () =>
|
queryFn: () =>
|
||||||
movieAdvisor
|
movieAdvisor
|
||||||
.get<(Movie | Series) & Details>(`/${showType}/${showId}`)
|
.get<DetailsResponse>(
|
||||||
.then((response) => ({ ...response, ...mapMovieSeriesToShow(response, showType) }))
|
`/${showType}/${showId}`,
|
||||||
|
showType === 'movie' ? { params: { append_to_response: 'release_dates' } } : undefined
|
||||||
|
)
|
||||||
|
.then(({ release_dates, ...response }) => ({
|
||||||
|
...response,
|
||||||
|
...mapMovieSeriesToShow(response, showType),
|
||||||
|
availability: mapReleaseDatesToAvailability(release_dates?.results),
|
||||||
|
airing: showType === 'tv' ? mapDetailsToAiring(response) : undefined
|
||||||
|
}))
|
||||||
.catch((error) => Promise.reject(error))
|
.catch((error) => Promise.reject(error))
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const popularQuery = ({ sortBy = 'popularity.desc', starring }: PopularQueryProp
|
|||||||
params: {
|
params: {
|
||||||
page: pageParam,
|
page: pageParam,
|
||||||
sort_by: sortBy,
|
sort_by: sortBy,
|
||||||
with_cast: starring,
|
// with_people covers cast and crew, with_cast on top of it would AND directors away
|
||||||
with_people: starring,
|
with_people: starring,
|
||||||
'vote_count.gte': 300,
|
'vote_count.gte': 300,
|
||||||
'vote_average.lte': 10,
|
'vote_average.lte': 10,
|
||||||
|
|||||||
@@ -3,6 +3,12 @@ import { twMerge } from 'tailwind-merge';
|
|||||||
|
|
||||||
export const cn = (...inputs: ClassValue[]) => twMerge(clsx(inputs));
|
export const cn = (...inputs: ClassValue[]) => twMerge(clsx(inputs));
|
||||||
|
|
||||||
|
// TMDB dates are UTC midnight, formatting them in the local zone would shift them a day back
|
||||||
|
export const formatDate = (date: string) =>
|
||||||
|
new Intl.DateTimeFormat('en-GB', { day: '2-digit', month: '2-digit', year: 'numeric', timeZone: 'UTC' })
|
||||||
|
.format(new Date(date))
|
||||||
|
.replace(/\//g, '.');
|
||||||
|
|
||||||
export const createUniqueRandomGenerator = (max: number) => {
|
export const createUniqueRandomGenerator = (max: number) => {
|
||||||
const numbers = Array.from({ length: max }, (_, i) => i + 1);
|
const numbers = Array.from({ length: max }, (_, i) => i + 1);
|
||||||
|
|
||||||
|
|||||||
Vendored
+55
-2
@@ -18,8 +18,52 @@ interface Details {
|
|||||||
imdb_id: string;
|
imdb_id: string;
|
||||||
runtime: number;
|
runtime: number;
|
||||||
tagline: string;
|
tagline: string;
|
||||||
|
availability?: Availability;
|
||||||
|
airing?: Airing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface TMDBEpisode {
|
||||||
|
air_date: string | null;
|
||||||
|
episode_number: number;
|
||||||
|
season_number: number;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TMDBSeriesDetails {
|
||||||
|
last_episode_to_air?: TMDBEpisode | null;
|
||||||
|
next_episode_to_air?: TMDBEpisode | null;
|
||||||
|
number_of_seasons?: number;
|
||||||
|
status?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Where a series currently stands — the latest aired episode plus what follows it */
|
||||||
|
interface Airing {
|
||||||
|
season: number;
|
||||||
|
episode: number;
|
||||||
|
seasons: number;
|
||||||
|
ended: boolean;
|
||||||
|
/** air date of the next episode, ISO string, only when TMDB knows one */
|
||||||
|
next?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TMDBReleaseDate {
|
||||||
|
certification: string;
|
||||||
|
iso_639_1: string;
|
||||||
|
note: string;
|
||||||
|
release_date: string;
|
||||||
|
type: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TMDBCountryReleaseDates {
|
||||||
|
iso_3166_1: string;
|
||||||
|
release_dates: TMDBReleaseDate[];
|
||||||
|
}
|
||||||
|
|
||||||
|
type AvailabilityState = 'theatre' | 'stream' | 'bluray';
|
||||||
|
|
||||||
|
/** Earliest worldwide release date per window, ISO strings */
|
||||||
|
type Availability = Partial<Record<AvailabilityState, string>>;
|
||||||
|
|
||||||
interface Movie {
|
interface Movie {
|
||||||
adult: boolean;
|
adult: boolean;
|
||||||
backdrop_path: string;
|
backdrop_path: string;
|
||||||
@@ -82,9 +126,18 @@ interface Person {
|
|||||||
original_name: string;
|
original_name: string;
|
||||||
popularity: number;
|
popularity: number;
|
||||||
profile_path: string;
|
profile_path: string;
|
||||||
cast_id: number;
|
|
||||||
credit_id: string;
|
credit_id: string;
|
||||||
order: number;
|
// crew members carry neither
|
||||||
|
cast_id?: number;
|
||||||
|
order?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Crew extends Person {
|
||||||
|
department: string;
|
||||||
|
/** movie credits carry a single job, tv aggregate credits carry one entry per job */
|
||||||
|
job?: string;
|
||||||
|
jobs?: Array<{ credit_id: string; job: string; episode_count: number }>;
|
||||||
|
total_episode_count?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Actor extends Person {
|
interface Actor extends Person {
|
||||||
|
|||||||
Reference in new issue
Block a user