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,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];
|
||||
|
||||
return (
|
||||
<Hint
|
||||
lines={getLabels(availability, state)}
|
||||
className={className}
|
||||
triggerClassName='text-muted-foreground transition-colors hover:text-foreground'
|
||||
>
|
||||
<Hint lines={getLabels(availability, state)} className={className}>
|
||||
<Icon size={16} />
|
||||
</Hint>
|
||||
);
|
||||
|
||||
@@ -52,11 +52,7 @@ const components: VirtuosoProps<Actor, Context>['components'] = {
|
||||
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'
|
||||
>
|
||||
<Link
|
||||
prefetch={false}
|
||||
href={`/starring?actorId=${actor.id}&title=${encodeURIComponent(actor.name)}`}
|
||||
onClick={() => context?.onClick?.(actor.id.toString())}
|
||||
>
|
||||
<Link prefetch={false} href={`/person/${actor.id}`} onClick={() => context?.onClick?.(actor.id.toString())}>
|
||||
<div className='overflow-hidden rounded-lg'>
|
||||
<img height={180} width={120} loading='lazy' src={actor.photoUrl} alt={actor.name} />
|
||||
</div>
|
||||
|
||||
@@ -8,21 +8,17 @@ interface Props {
|
||||
lines: string[];
|
||||
children: ReactNode;
|
||||
className?: string;
|
||||
triggerClassName?: string;
|
||||
}
|
||||
|
||||
const Hint: FC<Props> = ({ lines, children, className, triggerClassName }) => {
|
||||
const Hint: FC<Props> = ({ lines, children, className }) => {
|
||||
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
|
||||
className='inline-flex cursor-help items-center'
|
||||
onPointerEnter={({ pointerType }) => pointerType === 'mouse' && setOpen(true)}
|
||||
onPointerLeave={({ pointerType }) => pointerType === 'mouse' && setOpen(false)}
|
||||
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 };
|
||||
Reference in new issue
Block a user