feat: replace the starring page with a person page
A credit now opens /person/{id}: portrait, name, department, life dates and
birthplace, the biography, and the full filmography ranked by vote count.
One request carries all of it — combined_credits rides along on the person
call — so the discover based starring query and its with_people filter go.
The biography fills whatever height the portrait leaves and fades where it
is cut, with the whole text in a tooltip on hover; a phone has no height to
respect there, so it simply runs on.
Route level and query level skeletons stand in while it loads, built from
the shadcn primitive.
Development server side fetches go over the loopback rather than SITE_URL,
which is a LAN address meant for other devices: once that address moves the
fetch hangs until undici times out, ten seconds per navigation.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6fc41c0901
commit
3dc2ebfe53
22 files changed
+342
-108
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
import PersonSkeleton from '@/components/Person/components/Skeleton';
|
||||||
|
|
||||||
|
const Loading = () => <PersonSkeleton />;
|
||||||
|
|
||||||
|
export default Loading;
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
import { FC } from 'react';
|
||||||
|
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
||||||
|
import { Metadata } from 'next';
|
||||||
|
import { redirect } from 'next/navigation';
|
||||||
|
|
||||||
|
import Person from '@/components/Person';
|
||||||
|
import personQuery from '@/data/queries/person';
|
||||||
|
import { SITE_URL, TITLE } from '@/env';
|
||||||
|
import getQueryClient from '@/lib/queryClient';
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
params: { id: string };
|
||||||
|
}
|
||||||
|
|
||||||
|
export const generateMetadata = async ({ params: { id } }: Props): Promise<Metadata> => {
|
||||||
|
const queryClient = getQueryClient();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { name, biography, photo } = await queryClient.fetchQuery(personQuery({ personId: id }));
|
||||||
|
|
||||||
|
const description = biography || `Movies and series starring ${name}.`;
|
||||||
|
|
||||||
|
return {
|
||||||
|
title: `${name} | ${TITLE}`,
|
||||||
|
description,
|
||||||
|
openGraph: {
|
||||||
|
title: name,
|
||||||
|
description,
|
||||||
|
images: photo ? [photo] : [],
|
||||||
|
type: 'profile',
|
||||||
|
url: `${SITE_URL}/person/${id}`
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} catch (_) {
|
||||||
|
return { title: TITLE };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const PersonPage: FC<Props> = async ({ params: { id } }) => {
|
||||||
|
const queryClient = getQueryClient();
|
||||||
|
|
||||||
|
if (!id) return redirect('/');
|
||||||
|
|
||||||
|
await queryClient.prefetchQuery(personQuery({ personId: id }));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||||
|
<Person personId={id} />
|
||||||
|
</HydrationBoundary>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PersonPage;
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { useSearchParams } from 'next/navigation';
|
|
||||||
|
|
||||||
import List from '@/components/List';
|
|
||||||
import NoResults from '@/components/NoResults';
|
|
||||||
|
|
||||||
import useStarring from './useStarring';
|
|
||||||
|
|
||||||
const Container = () => {
|
|
||||||
const params = useSearchParams();
|
|
||||||
|
|
||||||
const title = params.get('title') as string;
|
|
||||||
const actorId = params.get('actorId') as string;
|
|
||||||
|
|
||||||
const { shows, fetchNextPage, isFetched } = useStarring({ actorId });
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{Boolean(title) && (
|
|
||||||
<span className='mb-2 inline-flex h-10 w-full items-center justify-center rounded-md bg-muted p-1 text-muted-foreground'>
|
|
||||||
Starring: {decodeURIComponent(title || '')}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
<List shows={shows} fetchNextPage={fetchNextPage} />
|
|
||||||
{isFetched && !shows.length && <NoResults />}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Container;
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
import { FC } from 'react';
|
|
||||||
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
|
||||||
|
|
||||||
import popularQuery from '@/data/queries/popular';
|
|
||||||
import getQueryClient from '@/lib/queryClient';
|
|
||||||
|
|
||||||
import Container from './container';
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
searchParams: Record<string, string>;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Starring: FC<Props> = ({ searchParams }) => {
|
|
||||||
const queryClient = getQueryClient();
|
|
||||||
|
|
||||||
const { actorId } = searchParams || {};
|
|
||||||
|
|
||||||
queryClient.prefetchInfiniteQuery(
|
|
||||||
popularQuery({
|
|
||||||
sortBy: 'vote_average.desc',
|
|
||||||
starring: actorId
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
|
||||||
<Container />
|
|
||||||
</HydrationBoundary>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Starring;
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import popularQuery from '@/data/queries/popular';
|
|
||||||
import useInfiniteList from '@/hooks/useInfiniteList';
|
|
||||||
|
|
||||||
const useStarring = ({ actorId }: { actorId?: string }) =>
|
|
||||||
useInfiniteList(popularQuery({ sortBy: 'vote_average.desc', starring: actorId }));
|
|
||||||
|
|
||||||
export default useStarring;
|
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { FC, useEffect, useRef, useState } from 'react';
|
||||||
|
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
text: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Biography: FC<Props> = ({ text }) => {
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
const [overflows, setOverflows] = useState(false);
|
||||||
|
|
||||||
|
const textRef = useRef<HTMLParagraphElement>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const element = textRef.current;
|
||||||
|
|
||||||
|
if (!element) return;
|
||||||
|
|
||||||
|
const measure = () => setOverflows(element.scrollHeight > element.clientHeight + 1);
|
||||||
|
|
||||||
|
measure();
|
||||||
|
|
||||||
|
const observer = new ResizeObserver(measure);
|
||||||
|
|
||||||
|
observer.observe(element);
|
||||||
|
|
||||||
|
return () => observer.disconnect();
|
||||||
|
}, [text]);
|
||||||
|
|
||||||
|
if (!text) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className='relative z-10 grow animate-fade-aside-slide-in opacity-0 md:min-h-0'
|
||||||
|
onPointerEnter={({ pointerType }) => pointerType === 'mouse' && overflows && setOpen(true)}
|
||||||
|
onPointerLeave={({ pointerType }) => pointerType === 'mouse' && setOpen(false)}
|
||||||
|
>
|
||||||
|
<div className='flex flex-col md:absolute md:inset-0'>
|
||||||
|
<p ref={textRef} className='min-h-0 grow whitespace-pre-line md:overflow-hidden'>
|
||||||
|
{text}
|
||||||
|
</p>
|
||||||
|
{overflows && (
|
||||||
|
<span className='pointer-events-none absolute inset-x-0 bottom-0 h-16 bg-gradient-to-b from-transparent to-background' />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{overflows && (
|
||||||
|
<div
|
||||||
|
role='tooltip'
|
||||||
|
aria-hidden={!open}
|
||||||
|
className={cn(
|
||||||
|
'absolute inset-x-0 top-0 hidden max-h-[70vh] overflow-y-auto rounded-lg border bg-popover p-3 text-popover-foreground shadow-md transition-opacity md:block',
|
||||||
|
open ? 'opacity-100' : 'pointer-events-none opacity-0'
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<p className='whitespace-pre-line'>{text}</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Biography;
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import { FC } from 'react';
|
||||||
|
|
||||||
|
import { Skeleton } from '@/components/ui/skeleton';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
const PARAGRAPHS = [
|
||||||
|
['w-full', 'w-full', 'w-10/12'],
|
||||||
|
['w-full', 'w-full', 'w-full', 'w-4/5'],
|
||||||
|
['w-full', 'w-full', 'w-3/4'],
|
||||||
|
['w-full', 'w-2/3']
|
||||||
|
];
|
||||||
|
|
||||||
|
const POSTERS = Array.from({ length: 8 }, (_, index) => index);
|
||||||
|
|
||||||
|
const PersonSkeleton: FC = () => (
|
||||||
|
<div className='flex flex-1 flex-col'>
|
||||||
|
<div className='flex flex-col gap-2 md:flex-row'>
|
||||||
|
<Skeleton className='card-aspect-ratio static-aspect-ratio mx-auto rounded-lg' />
|
||||||
|
|
||||||
|
<div className='flex grow flex-col'>
|
||||||
|
<Skeleton className='mb-4 h-9 w-72 max-w-full' />
|
||||||
|
|
||||||
|
<div className='mb-4 flex w-full flex-wrap gap-5'>
|
||||||
|
<Skeleton className='h-5 w-20' />
|
||||||
|
<Skeleton className='h-5 w-28' />
|
||||||
|
<Skeleton className='h-5 w-56 max-w-full' />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='flex grow flex-col gap-5 overflow-hidden md:min-h-0'>
|
||||||
|
{PARAGRAPHS.map((lines, paragraph) => (
|
||||||
|
<div key={paragraph} className='flex shrink-0 flex-col gap-2'>
|
||||||
|
{lines.map((width, line) => (
|
||||||
|
<Skeleton key={line} className={cn('h-4', width)} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className='mt-5'>
|
||||||
|
<Skeleton className='mb-3 h-7 w-36' />
|
||||||
|
<div className='flex flex-wrap justify-center gap-2'>
|
||||||
|
{POSTERS.map((index) => (
|
||||||
|
<Skeleton key={index} className={cn('card-aspect-ratio rounded-lg', { 'hidden md:block': index >= 2 })} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default PersonSkeleton;
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { FC } from 'react';
|
||||||
|
|
||||||
|
import List from '@/components/List';
|
||||||
|
import NoResults from '@/components/NoResults';
|
||||||
|
import { formatDate } from '@/lib/utils';
|
||||||
|
|
||||||
|
import Biography from './components/Biography';
|
||||||
|
import PersonSkeleton from './components/Skeleton';
|
||||||
|
import useProfile from './useProfile';
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
personId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const lifespan = ({ birthday, deathday }: Profile) => {
|
||||||
|
if (!birthday) return '';
|
||||||
|
|
||||||
|
return deathday ? `${formatDate(birthday)} — ${formatDate(deathday)}` : formatDate(birthday);
|
||||||
|
};
|
||||||
|
|
||||||
|
const Person: FC<Props> = ({ personId }) => {
|
||||||
|
const { data: profile, isError } = useProfile({ personId });
|
||||||
|
|
||||||
|
if (isError) return <NoResults />;
|
||||||
|
|
||||||
|
if (!profile) return <PersonSkeleton />;
|
||||||
|
|
||||||
|
const dates = lifespan(profile);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='flex flex-1 flex-col'>
|
||||||
|
<div className='flex flex-col gap-2 md:flex-row'>
|
||||||
|
{Boolean(profile.photo) && (
|
||||||
|
<div className='card-aspect-ratio static-aspect-ratio relative mx-auto overflow-hidden rounded-lg bg-black'>
|
||||||
|
<img className='size-full object-cover' src={profile.photo} alt={profile.name} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div className='flex grow flex-col bg-background'>
|
||||||
|
<span className='mb-4 text-3xl'>{profile.name}</span>
|
||||||
|
|
||||||
|
<div className='mb-4 flex w-full flex-wrap gap-5 whitespace-nowrap text-sm'>
|
||||||
|
{Boolean(profile.department) && <span>{profile.department}</span>}
|
||||||
|
{Boolean(dates) && <span>{dates}</span>}
|
||||||
|
{Boolean(profile.birthplace) && <span className='whitespace-normal'>{profile.birthplace}</span>}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Biography text={profile.biography} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{Boolean(profile.shows.length) && (
|
||||||
|
<div className='mt-5'>
|
||||||
|
<span className='mb-3 inline-block text-lg'>Filmography</span>
|
||||||
|
<List shows={profile.shows} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!profile.shows.length && <NoResults />}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Person;
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
|
||||||
|
import personQuery, { PersonQueryProps } from '@/data/queries/person';
|
||||||
|
|
||||||
|
const useProfile = ({ personId }: PersonQueryProps) => useQuery(personQuery({ personId }));
|
||||||
|
|
||||||
|
export default useProfile;
|
||||||
@@ -39,11 +39,7 @@ const Availability: FC<Props> = ({ availability, className }) => {
|
|||||||
const Icon = ICONS[state];
|
const Icon = ICONS[state];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Hint
|
<Hint lines={getLabels(availability, state)} className={className}>
|
||||||
lines={getLabels(availability, state)}
|
|
||||||
className={className}
|
|
||||||
triggerClassName='text-muted-foreground transition-colors hover:text-foreground'
|
|
||||||
>
|
|
||||||
<Icon size={16} />
|
<Icon size={16} />
|
||||||
</Hint>
|
</Hint>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -52,11 +52,7 @@ const components: VirtuosoProps<Actor, Context>['components'] = {
|
|||||||
style={{ width: context?.width, height: context?.height }}
|
style={{ width: context?.width, height: context?.height }}
|
||||||
className='relative shrink-0 cursor-pointer snap-start self-end bg-card text-card-foreground transition-shadow hover:shadow-lg'
|
className='relative shrink-0 cursor-pointer snap-start self-end bg-card text-card-foreground transition-shadow hover:shadow-lg'
|
||||||
>
|
>
|
||||||
<Link
|
<Link prefetch={false} href={`/person/${actor.id}`} onClick={() => context?.onClick?.(actor.id.toString())}>
|
||||||
prefetch={false}
|
|
||||||
href={`/starring?actorId=${actor.id}&title=${encodeURIComponent(actor.name)}`}
|
|
||||||
onClick={() => context?.onClick?.(actor.id.toString())}
|
|
||||||
>
|
|
||||||
<div className='overflow-hidden rounded-lg'>
|
<div className='overflow-hidden rounded-lg'>
|
||||||
<img height={180} width={120} loading='lazy' src={actor.photoUrl} alt={actor.name} />
|
<img height={180} width={120} loading='lazy' src={actor.photoUrl} alt={actor.name} />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -8,21 +8,17 @@ interface Props {
|
|||||||
lines: string[];
|
lines: string[];
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
className?: string;
|
className?: string;
|
||||||
triggerClassName?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Hint: FC<Props> = ({ lines, children, className, triggerClassName }) => {
|
const Hint: FC<Props> = ({ lines, children, className }) => {
|
||||||
const [open, setOpen] = useState(false);
|
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 (
|
return (
|
||||||
<span className={cn('relative z-10 inline-flex', className)}>
|
<span className={cn('relative z-10 inline-flex', className)}>
|
||||||
<button
|
<button
|
||||||
type='button'
|
type='button'
|
||||||
aria-label={lines.join('. ')}
|
aria-label={lines.join('. ')}
|
||||||
className={cn('inline-flex cursor-help items-center', triggerClassName)}
|
className='inline-flex cursor-help items-center'
|
||||||
// a tap fires pointerenter too, opening what the click would then toggle shut
|
|
||||||
onPointerEnter={({ pointerType }) => pointerType === 'mouse' && setOpen(true)}
|
onPointerEnter={({ pointerType }) => pointerType === 'mouse' && setOpen(true)}
|
||||||
onPointerLeave={({ pointerType }) => pointerType === 'mouse' && setOpen(false)}
|
onPointerLeave={({ pointerType }) => pointerType === 'mouse' && setOpen(false)}
|
||||||
onClick={() => setOpen((value) => !value)}
|
onClick={() => setOpen((value) => !value)}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
function Skeleton({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {
|
||||||
|
return <div className={cn('animate-pulse rounded-md bg-muted', className)} {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Skeleton };
|
||||||
@@ -4,8 +4,10 @@ import { SITE_URL } from '@/env';
|
|||||||
|
|
||||||
import Http from './Http';
|
import Http from './Http';
|
||||||
|
|
||||||
const ROOT = isServer ? `${SITE_URL?.startsWith('http') ? SITE_URL : `https://${SITE_URL}`}` : '';
|
const PUBLIC_ORIGIN = `${SITE_URL?.startsWith('http') ? SITE_URL : `https://${SITE_URL}`}`;
|
||||||
|
|
||||||
const movieAdvisor = new Http(`${ROOT}/api/tmdb`);
|
const ROOT = process.env.NODE_ENV === 'development' ? `http://127.0.0.1:${process.env.PORT || 3000}` : PUBLIC_ORIGIN;
|
||||||
|
|
||||||
|
const movieAdvisor = new Http(`${isServer ? ROOT : ''}/api/tmdb`);
|
||||||
|
|
||||||
export default movieAdvisor;
|
export default movieAdvisor;
|
||||||
@@ -6,7 +6,6 @@ export const mapDetailsToAiring = ({
|
|||||||
number_of_seasons,
|
number_of_seasons,
|
||||||
status
|
status
|
||||||
}: TMDBSeriesDetails): Airing | undefined => {
|
}: 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;
|
const current = last_episode_to_air || next_episode_to_air;
|
||||||
|
|
||||||
if (!current) return undefined;
|
if (!current) return undefined;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// TMDB release types: 1 premiere, 2 limited theatrical, 3 theatrical, 4 digital, 5 physical, 6 TV
|
|
||||||
const STATE_BY_RELEASE_TYPE: Record<number, AvailabilityState> = {
|
const STATE_BY_RELEASE_TYPE: Record<number, AvailabilityState> = {
|
||||||
1: 'theatre',
|
1: 'theatre',
|
||||||
2: 'theatre',
|
2: 'theatre',
|
||||||
@@ -7,11 +6,9 @@ const STATE_BY_RELEASE_TYPE: Record<number, AvailabilityState> = {
|
|||||||
5: 'bluray'
|
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;
|
const THEATRICAL_WINDOW = 120 * 24 * 60 * 60 * 1000;
|
||||||
|
|
||||||
export const mapReleaseDatesToAvailability = (results?: TMDBCountryReleaseDates[]): Availability | undefined => {
|
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 }) => {
|
const availability = (results || []).reduce<Availability>((dates, { release_dates }) => {
|
||||||
(release_dates || []).forEach(({ type, release_date }) => {
|
(release_dates || []).forEach(({ type, release_date }) => {
|
||||||
const state = STATE_BY_RELEASE_TYPE[type];
|
const state = STATE_BY_RELEASE_TYPE[type];
|
||||||
@@ -37,8 +34,6 @@ export const getAvailabilityState = ({ theatre, stream, bluray }: Availability):
|
|||||||
if (isUpcoming(theatre)) return 'theatre';
|
if (isUpcoming(theatre)) return 'theatre';
|
||||||
if (!theatre) return undefined;
|
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;
|
const isRunning = Date.now() - Date.parse(theatre) < THEATRICAL_WINDOW;
|
||||||
|
|
||||||
return isRunning || isUpcoming(stream) || isUpcoming(bluray) ? 'theatre' : 'stream';
|
return isRunning || isUpcoming(stream) || isUpcoming(bluray) ? 'theatre' : 'stream';
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import { mapMovieSeriesToShow } from './Show';
|
||||||
|
|
||||||
|
const unique = (credits: TMDBPersonCredit[]) => {
|
||||||
|
const titles = new Map<string, TMDBPersonCredit>();
|
||||||
|
|
||||||
|
credits.forEach((credit) => {
|
||||||
|
const key = `${credit.media_type}-${credit.id}`;
|
||||||
|
|
||||||
|
if (credit.poster_path && ['movie', 'tv'].includes(credit.media_type) && !titles.has(key)) {
|
||||||
|
titles.set(key, credit);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return Array.from(titles.values());
|
||||||
|
};
|
||||||
|
|
||||||
|
const mapPersonToProfile = ({ combined_credits, ...person }: TMDBPersonDetails): Profile => ({
|
||||||
|
id: person.id,
|
||||||
|
name: person.name,
|
||||||
|
photo: person.profile_path ? `https://image.tmdb.org/t/p/w500${person.profile_path}` : '',
|
||||||
|
biography: person.biography || '',
|
||||||
|
department: person.known_for_department || '',
|
||||||
|
birthday: person.birthday || undefined,
|
||||||
|
deathday: person.deathday || undefined,
|
||||||
|
birthplace: person.place_of_birth || undefined,
|
||||||
|
shows: unique([...(combined_credits?.cast || []), ...(combined_credits?.crew || [])])
|
||||||
|
.sort((a, b) => b.vote_count - a.vote_count)
|
||||||
|
.map((credit) => mapMovieSeriesToShow(credit, credit.media_type))
|
||||||
|
});
|
||||||
|
|
||||||
|
export default mapPersonToProfile;
|
||||||
@@ -7,7 +7,6 @@ export type CreditsQueryProps = {
|
|||||||
|
|
||||||
const photo = (path: string) => `https://image.tmdb.org/t/p/w185${path}`;
|
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[] = []) =>
|
const findDirector = (crew: Crew[] = []) =>
|
||||||
crew
|
crew
|
||||||
.filter(
|
.filter(
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import movieAdvisor from '../clients/movieAdvisor';
|
||||||
|
import mapPersonToProfile from '../dto/Person';
|
||||||
|
|
||||||
|
export type PersonQueryProps = {
|
||||||
|
personId?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const personQuery = ({ personId }: PersonQueryProps) => ({
|
||||||
|
enabled: Boolean(personId),
|
||||||
|
queryKey: ['person', personId],
|
||||||
|
queryFn: () =>
|
||||||
|
movieAdvisor
|
||||||
|
.get<TMDBPersonDetails>(`/person/${personId}`, {
|
||||||
|
params: { append_to_response: 'combined_credits' },
|
||||||
|
preventCache: false
|
||||||
|
})
|
||||||
|
.then(mapPersonToProfile)
|
||||||
|
.catch((error) => Promise.reject(error))
|
||||||
|
});
|
||||||
|
|
||||||
|
export default personQuery;
|
||||||
@@ -3,11 +3,10 @@ import mapMoviesSeriesResponseToShows from '../dto/Show';
|
|||||||
|
|
||||||
export type PopularQueryProps = {
|
export type PopularQueryProps = {
|
||||||
sortBy?: string;
|
sortBy?: string;
|
||||||
starring?: string;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const popularQuery = ({ sortBy = 'popularity.desc', starring }: PopularQueryProps = {}) => ({
|
const popularQuery = ({ sortBy = 'popularity.desc' }: PopularQueryProps = {}) => ({
|
||||||
queryKey: ['popular', sortBy, starring],
|
queryKey: ['popular', sortBy],
|
||||||
initialPageParam: '1',
|
initialPageParam: '1',
|
||||||
queryFn: ({ pageParam = '1' }: { pageParam?: string }) =>
|
queryFn: ({ pageParam = '1' }: { pageParam?: string }) =>
|
||||||
movieAdvisor
|
movieAdvisor
|
||||||
@@ -15,8 +14,6 @@ const popularQuery = ({ sortBy = 'popularity.desc', starring }: PopularQueryProp
|
|||||||
params: {
|
params: {
|
||||||
page: pageParam,
|
page: pageParam,
|
||||||
sort_by: sortBy,
|
sort_by: sortBy,
|
||||||
// with_people covers cast and crew, with_cast on top of it would AND directors away
|
|
||||||
with_people: starring,
|
|
||||||
'vote_count.gte': 300,
|
'vote_count.gte': 300,
|
||||||
'vote_average.lte': 10,
|
'vote_average.lte': 10,
|
||||||
'vote_average.gte': 5
|
'vote_average.gte': 5
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ 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) =>
|
export const formatDate = (date: string) =>
|
||||||
new Intl.DateTimeFormat('en-GB', { day: '2-digit', month: '2-digit', year: 'numeric', timeZone: 'UTC' })
|
new Intl.DateTimeFormat('en-GB', { day: '2-digit', month: '2-digit', year: 'numeric', timeZone: 'UTC' })
|
||||||
.format(new Date(date))
|
.format(new Date(date))
|
||||||
|
|||||||
Vendored
+26
-5
@@ -36,13 +36,11 @@ interface TMDBSeriesDetails {
|
|||||||
status?: string;
|
status?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Where a series currently stands — the latest aired episode plus what follows it */
|
|
||||||
interface Airing {
|
interface Airing {
|
||||||
season: number;
|
season: number;
|
||||||
episode: number;
|
episode: number;
|
||||||
seasons: number;
|
seasons: number;
|
||||||
ended: boolean;
|
ended: boolean;
|
||||||
/** air date of the next episode, ISO string, only when TMDB knows one */
|
|
||||||
next?: string;
|
next?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +59,6 @@ interface TMDBCountryReleaseDates {
|
|||||||
|
|
||||||
type AvailabilityState = 'theatre' | 'stream' | 'bluray';
|
type AvailabilityState = 'theatre' | 'stream' | 'bluray';
|
||||||
|
|
||||||
/** Earliest worldwide release date per window, ISO strings */
|
|
||||||
type Availability = Partial<Record<AvailabilityState, string>>;
|
type Availability = Partial<Record<AvailabilityState, string>>;
|
||||||
|
|
||||||
interface Movie {
|
interface Movie {
|
||||||
@@ -127,14 +124,12 @@ interface Person {
|
|||||||
popularity: number;
|
popularity: number;
|
||||||
profile_path: string;
|
profile_path: string;
|
||||||
credit_id: string;
|
credit_id: string;
|
||||||
// crew members carry neither
|
|
||||||
cast_id?: number;
|
cast_id?: number;
|
||||||
order?: number;
|
order?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Crew extends Person {
|
interface Crew extends Person {
|
||||||
department: string;
|
department: string;
|
||||||
/** movie credits carry a single job, tv aggregate credits carry one entry per job */
|
|
||||||
job?: string;
|
job?: string;
|
||||||
jobs?: Array<{ credit_id: string; job: string; episode_count: number }>;
|
jobs?: Array<{ credit_id: string; job: string; episode_count: number }>;
|
||||||
total_episode_count?: number;
|
total_episode_count?: number;
|
||||||
@@ -145,6 +140,32 @@ interface Actor extends Person {
|
|||||||
photoUrl: string;
|
photoUrl: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TMDBPersonCredit = (Movie | Series) & { media_type: Show['type'] };
|
||||||
|
|
||||||
|
interface TMDBPersonDetails {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
biography: string;
|
||||||
|
birthday: string | null;
|
||||||
|
deathday: string | null;
|
||||||
|
place_of_birth: string | null;
|
||||||
|
known_for_department: string;
|
||||||
|
profile_path: string | null;
|
||||||
|
combined_credits?: { cast: TMDBPersonCredit[]; crew: TMDBPersonCredit[] };
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Profile {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
photo: string;
|
||||||
|
biography: string;
|
||||||
|
department: string;
|
||||||
|
birthday?: string;
|
||||||
|
deathday?: string;
|
||||||
|
birthplace?: string;
|
||||||
|
shows: Show[];
|
||||||
|
}
|
||||||
|
|
||||||
interface AggregatedActor extends Person {
|
interface AggregatedActor extends Person {
|
||||||
roles: Role[];
|
roles: Role[];
|
||||||
total_episode_count: number;
|
total_episode_count: number;
|
||||||
|
|||||||
Reference in new issue
Block a user