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 Actions from './components/Actions';
|
||||
import Airing from './components/Airing';
|
||||
import Availability from './components/Availability';
|
||||
|
||||
interface Props {
|
||||
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 })}>
|
||||
<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>
|
||||
{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) && (
|
||||
<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;
|
||||
Reference in new issue
Block a user