From 3dc2ebfe5326730790e4f3b63cd452c7226b9a41 Mon Sep 17 00:00:00 2001 From: ner Date: Tue, 4 Aug 2026 22:09:33 +0300 Subject: [PATCH] feat: replace the starring page with a person page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- app/(site)/person/[id]/loading.tsx | 5 ++ app/(site)/person/[id]/page.tsx | 53 +++++++++++++++ app/(site)/starring/container.tsx | 31 --------- app/(site)/starring/page.tsx | 32 --------- app/(site)/starring/useStarring.ts | 9 --- .../Person/components/Biography/index.tsx | 65 +++++++++++++++++++ .../Person/components/Skeleton/index.tsx | 52 +++++++++++++++ components/Person/index.tsx | 65 +++++++++++++++++++ components/Person/useProfile.ts | 7 ++ .../Preview/components/Availability/index.tsx | 6 +- .../Preview/components/Credits/index.tsx | 6 +- components/ui/hint.tsx | 8 +-- components/ui/skeleton.tsx | 7 ++ data/clients/movieAdvisor.ts | 6 +- data/dto/Airing.ts | 1 - data/dto/Availability.ts | 5 -- data/dto/Person.ts | 31 +++++++++ data/queries/credits.ts | 1 - data/queries/person.ts | 21 ++++++ data/queries/popular.ts | 7 +- lib/utils.ts | 1 - types.d.ts | 31 +++++++-- 22 files changed, 342 insertions(+), 108 deletions(-) create mode 100644 app/(site)/person/[id]/loading.tsx create mode 100644 app/(site)/person/[id]/page.tsx delete mode 100644 app/(site)/starring/container.tsx delete mode 100644 app/(site)/starring/page.tsx delete mode 100644 app/(site)/starring/useStarring.ts create mode 100644 components/Person/components/Biography/index.tsx create mode 100644 components/Person/components/Skeleton/index.tsx create mode 100644 components/Person/index.tsx create mode 100644 components/Person/useProfile.ts create mode 100644 components/ui/skeleton.tsx create mode 100644 data/dto/Person.ts create mode 100644 data/queries/person.ts diff --git a/app/(site)/person/[id]/loading.tsx b/app/(site)/person/[id]/loading.tsx new file mode 100644 index 0000000..8aec056 --- /dev/null +++ b/app/(site)/person/[id]/loading.tsx @@ -0,0 +1,5 @@ +import PersonSkeleton from '@/components/Person/components/Skeleton'; + +const Loading = () => ; + +export default Loading; diff --git a/app/(site)/person/[id]/page.tsx b/app/(site)/person/[id]/page.tsx new file mode 100644 index 0000000..617ce1e --- /dev/null +++ b/app/(site)/person/[id]/page.tsx @@ -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 => { + 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 = async ({ params: { id } }) => { + const queryClient = getQueryClient(); + + if (!id) return redirect('/'); + + await queryClient.prefetchQuery(personQuery({ personId: id })); + + return ( + + + + ); +}; + +export default PersonPage; diff --git a/app/(site)/starring/container.tsx b/app/(site)/starring/container.tsx deleted file mode 100644 index 758f95f..0000000 --- a/app/(site)/starring/container.tsx +++ /dev/null @@ -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) && ( - - Starring: {decodeURIComponent(title || '')} - - )} - - {isFetched && !shows.length && } - - ); -}; - -export default Container; diff --git a/app/(site)/starring/page.tsx b/app/(site)/starring/page.tsx deleted file mode 100644 index add1fd0..0000000 --- a/app/(site)/starring/page.tsx +++ /dev/null @@ -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; -} - -const Starring: FC = ({ searchParams }) => { - const queryClient = getQueryClient(); - - const { actorId } = searchParams || {}; - - queryClient.prefetchInfiniteQuery( - popularQuery({ - sortBy: 'vote_average.desc', - starring: actorId - }) - ); - - return ( - - - - ); -}; - -export default Starring; diff --git a/app/(site)/starring/useStarring.ts b/app/(site)/starring/useStarring.ts deleted file mode 100644 index be79129..0000000 --- a/app/(site)/starring/useStarring.ts +++ /dev/null @@ -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; diff --git a/components/Person/components/Biography/index.tsx b/components/Person/components/Biography/index.tsx new file mode 100644 index 0000000..4707184 --- /dev/null +++ b/components/Person/components/Biography/index.tsx @@ -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 = ({ text }) => { + const [open, setOpen] = useState(false); + const [overflows, setOverflows] = useState(false); + + const textRef = useRef(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 ( +
pointerType === 'mouse' && overflows && setOpen(true)} + onPointerLeave={({ pointerType }) => pointerType === 'mouse' && setOpen(false)} + > +
+

+ {text} +

+ {overflows && ( + + )} +
+ {overflows && ( + + )} +
+ ); +}; + +export default Biography; diff --git a/components/Person/components/Skeleton/index.tsx b/components/Person/components/Skeleton/index.tsx new file mode 100644 index 0000000..d47544d --- /dev/null +++ b/components/Person/components/Skeleton/index.tsx @@ -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 = () => ( +
+
+ + +
+ + +
+ + + +
+ +
+ {PARAGRAPHS.map((lines, paragraph) => ( +
+ {lines.map((width, line) => ( + + ))} +
+ ))} +
+
+
+ +
+ +
+ {POSTERS.map((index) => ( + = 2 })} /> + ))} +
+
+
+); + +export default PersonSkeleton; diff --git a/components/Person/index.tsx b/components/Person/index.tsx new file mode 100644 index 0000000..57ccb77 --- /dev/null +++ b/components/Person/index.tsx @@ -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 = ({ personId }) => { + const { data: profile, isError } = useProfile({ personId }); + + if (isError) return ; + + if (!profile) return ; + + const dates = lifespan(profile); + + return ( +
+
+ {Boolean(profile.photo) && ( +
+ {profile.name} +
+ )} +
+ {profile.name} + +
+ {Boolean(profile.department) && {profile.department}} + {Boolean(dates) && {dates}} + {Boolean(profile.birthplace) && {profile.birthplace}} +
+ + +
+
+ + {Boolean(profile.shows.length) && ( +
+ Filmography + +
+ )} + + {!profile.shows.length && } +
+ ); +}; + +export default Person; diff --git a/components/Person/useProfile.ts b/components/Person/useProfile.ts new file mode 100644 index 0000000..fc0e1ec --- /dev/null +++ b/components/Person/useProfile.ts @@ -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; diff --git a/components/Preview/components/Availability/index.tsx b/components/Preview/components/Availability/index.tsx index 0a4ab6d..2266687 100644 --- a/components/Preview/components/Availability/index.tsx +++ b/components/Preview/components/Availability/index.tsx @@ -39,11 +39,7 @@ const Availability: FC = ({ availability, className }) => { const Icon = ICONS[state]; return ( - + ); diff --git a/components/Preview/components/Credits/index.tsx b/components/Preview/components/Credits/index.tsx index a3f40d1..59949ab 100644 --- a/components/Preview/components/Credits/index.tsx +++ b/components/Preview/components/Credits/index.tsx @@ -52,11 +52,7 @@ const components: VirtuosoProps['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' > - context?.onClick?.(actor.id.toString())} - > + context?.onClick?.(actor.id.toString())}>
{actor.name}
diff --git a/components/ui/hint.tsx b/components/ui/hint.tsx index ca88da0..37bf270 100644 --- a/components/ui/hint.tsx +++ b/components/ui/hint.tsx @@ -8,21 +8,17 @@ interface Props { lines: string[]; children: ReactNode; className?: string; - triggerClassName?: string; } -const Hint: FC = ({ lines, children, className, triggerClassName }) => { +const Hint: FC = ({ 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 (