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 (