feat(seo): crawlable show links, intercepted preview modal, real 404s
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
919dcf9a42
commit
25a5d535a4
21 files changed
+211
-107
No files matched your search
File renamed without changes.
@@ -0,0 +1,7 @@
|
||||
import { createShowMetadata, createShowPage } from '../../showPage';
|
||||
|
||||
export const generateMetadata = createShowMetadata('movie');
|
||||
|
||||
const MoviePage = createShowPage('movie');
|
||||
|
||||
export default MoviePage;
|
||||
@@ -0,0 +1,59 @@
|
||||
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
||||
import { Metadata } from 'next';
|
||||
import { notFound } from 'next/navigation';
|
||||
|
||||
import detailsQuery from '@/data/queries/details';
|
||||
import { SITE_URL, TITLE } from '@/env';
|
||||
import getQueryClient from '@/lib/queryClient';
|
||||
|
||||
import Container from './container';
|
||||
|
||||
interface Props {
|
||||
params: { id: string };
|
||||
}
|
||||
|
||||
export const createShowMetadata =
|
||||
(showType: Show['type']) =>
|
||||
async ({ params: { id } }: Props): Promise<Metadata> => {
|
||||
const queryClient = getQueryClient();
|
||||
|
||||
try {
|
||||
const { title, overview, poster } = await queryClient.fetchQuery(detailsQuery({ showId: Number(id), showType }));
|
||||
|
||||
return {
|
||||
title: `${title} | ${TITLE}`,
|
||||
description: overview,
|
||||
openGraph: {
|
||||
title,
|
||||
description: overview,
|
||||
images: [poster['2x']],
|
||||
type: 'website',
|
||||
url: `${SITE_URL}/${showType}/${id}`
|
||||
}
|
||||
};
|
||||
} catch (_) {
|
||||
return notFound();
|
||||
}
|
||||
};
|
||||
|
||||
export const createShowPage = (showType: Show['type']) => {
|
||||
const ShowPage = async ({ params: { id } }: Props) => {
|
||||
const queryClient = getQueryClient();
|
||||
|
||||
const showId = Number(id);
|
||||
|
||||
try {
|
||||
await queryClient.fetchQuery(detailsQuery({ showId, showType }));
|
||||
} catch (_) {
|
||||
return notFound();
|
||||
}
|
||||
|
||||
return (
|
||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||
<Container showId={showId} showType={showType} />
|
||||
</HydrationBoundary>
|
||||
);
|
||||
};
|
||||
|
||||
return ShowPage;
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
import { createShowMetadata, createShowPage } from '../../showPage';
|
||||
|
||||
export const generateMetadata = createShowMetadata('tv');
|
||||
|
||||
const SeriesPage = createShowPage('tv');
|
||||
|
||||
export default SeriesPage;
|
||||
@@ -0,0 +1,11 @@
|
||||
import { FC } from 'react';
|
||||
|
||||
import PreviewModal from '../../preview';
|
||||
|
||||
interface Props {
|
||||
params: { id: string };
|
||||
}
|
||||
|
||||
const MovieModal: FC<Props> = ({ params: { id } }) => <PreviewModal showId={Number(id)} showType='movie' />;
|
||||
|
||||
export default MovieModal;
|
||||
@@ -0,0 +1,11 @@
|
||||
import { FC } from 'react';
|
||||
|
||||
import PreviewModal from '../../preview';
|
||||
|
||||
interface Props {
|
||||
params: { id: string };
|
||||
}
|
||||
|
||||
const SeriesModal: FC<Props> = ({ params: { id } }) => <PreviewModal showId={Number(id)} showType='tv' />;
|
||||
|
||||
export default SeriesModal;
|
||||
@@ -0,0 +1,5 @@
|
||||
// Matches every non-intercepted route so the preview modal unmounts
|
||||
// when navigating elsewhere (e.g. to a person page from the credits).
|
||||
const CatchAll = () => null;
|
||||
|
||||
export default CatchAll;
|
||||
@@ -0,0 +1,3 @@
|
||||
const Default = () => null;
|
||||
|
||||
export default Default;
|
||||
@@ -0,0 +1,4 @@
|
||||
// Matches the root route so the preview modal unmounts when navigating home.
|
||||
const Empty = () => null;
|
||||
|
||||
export default Empty;
|
||||
@@ -0,0 +1,29 @@
|
||||
'use client';
|
||||
|
||||
import { FC } from 'react';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
import Preview from '@/components/Preview';
|
||||
import { previewSeedAtom } from '@/components/Preview/seed';
|
||||
import { Modal } from '@/components/ui/dialog';
|
||||
|
||||
interface Props {
|
||||
showId: Show['id'];
|
||||
showType: Show['type'];
|
||||
}
|
||||
|
||||
const PreviewModal: FC<Props> = ({ showId, showType }) => {
|
||||
const router = useRouter();
|
||||
const seed = useAtomValue(previewSeedAtom);
|
||||
|
||||
const show = seed?.id === showId && seed?.type === showType ? seed : undefined;
|
||||
|
||||
return (
|
||||
<Modal className='block bg-background p-0 md:bg-black' onClose={() => router.back()}>
|
||||
<Preview modal show={show} showId={showId} showType={showType} />
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default PreviewModal;
|
||||
@@ -1,62 +0,0 @@
|
||||
import { FC } from 'react';
|
||||
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
||||
import { Metadata } from 'next';
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
import detailsQuery from '@/data/queries/details';
|
||||
import { SITE_URL, TITLE } from '@/env';
|
||||
import getQueryClient from '@/lib/queryClient';
|
||||
|
||||
import Container from './container';
|
||||
|
||||
interface Props {
|
||||
params: { show: [Show['type'], Show['id']] };
|
||||
}
|
||||
|
||||
export const generateMetadata = async ({ params: { show } }: Props): Promise<Metadata> => {
|
||||
const queryClient = getQueryClient();
|
||||
|
||||
const [showType, showId] = show as [Show['type'], Show['id']];
|
||||
|
||||
if (!showType || !showId) return redirect('/');
|
||||
|
||||
try {
|
||||
const { title, overview, poster } = await queryClient.fetchQuery(detailsQuery({ showId, showType }));
|
||||
|
||||
return {
|
||||
title: `${title} | ${TITLE}`,
|
||||
description: overview,
|
||||
openGraph: {
|
||||
title,
|
||||
description: overview,
|
||||
images: [poster['2x']],
|
||||
type: 'website',
|
||||
url: `${SITE_URL}/${showType}/${showId}`
|
||||
}
|
||||
};
|
||||
} catch (_) {
|
||||
return redirect('/');
|
||||
}
|
||||
};
|
||||
|
||||
const ShowPage: FC<Props> = async ({ params: { show } }) => {
|
||||
const queryClient = getQueryClient();
|
||||
|
||||
const [showType, showId] = show as [Show['type'], Show['id']];
|
||||
|
||||
if (!showType || !showId) return redirect('/');
|
||||
|
||||
try {
|
||||
await queryClient.fetchQuery(detailsQuery({ showId, showType }));
|
||||
} catch (_) {
|
||||
return redirect('/');
|
||||
}
|
||||
|
||||
return (
|
||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||
<Container showId={showId} showType={showType} />
|
||||
</HydrationBoundary>
|
||||
);
|
||||
};
|
||||
|
||||
export default ShowPage;
|
||||
@@ -0,0 +1,10 @@
|
||||
import { ReactNode } from 'react';
|
||||
|
||||
const SiteLayout = ({ children, modal }: { children: ReactNode; modal: ReactNode }) => (
|
||||
<>
|
||||
{children}
|
||||
{modal}
|
||||
</>
|
||||
);
|
||||
|
||||
export default SiteLayout;
|
||||
@@ -1,7 +1,7 @@
|
||||
import { FC } from 'react';
|
||||
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
||||
import { Metadata } from 'next';
|
||||
import { redirect } from 'next/navigation';
|
||||
import { notFound } from 'next/navigation';
|
||||
|
||||
import Person from '@/components/Person';
|
||||
import personQuery from '@/data/queries/person';
|
||||
@@ -32,15 +32,13 @@ export const generateMetadata = async ({ params: { id } }: Props): Promise<Metad
|
||||
}
|
||||
};
|
||||
} catch (_) {
|
||||
return { title: TITLE };
|
||||
return notFound();
|
||||
}
|
||||
};
|
||||
|
||||
const PersonPage: FC<Props> = async ({ params: { id } }) => {
|
||||
const queryClient = getQueryClient();
|
||||
|
||||
if (!id) return redirect('/');
|
||||
|
||||
queryClient.prefetchQuery(personQuery({ personId: id }));
|
||||
|
||||
return (
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import Link from 'next/link';
|
||||
|
||||
import { Button } from '@/components/ui/button';
|
||||
|
||||
const NotFound = () => (
|
||||
<div className='flex flex-1 flex-col items-center justify-center gap-4 py-24 text-center'>
|
||||
<span className='text-6xl'>404</span>
|
||||
<p className='text-muted-foreground'>We couldn’t find that page, movie, or series.</p>
|
||||
<Button asChild variant='outline'>
|
||||
<Link href='/'>Back to home</Link>
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
|
||||
export default NotFound;
|
||||
@@ -84,7 +84,7 @@ export const showSearchModal = create(({ onResolve }) => {
|
||||
shows={shows}
|
||||
customScrollParent={scrollRef.current}
|
||||
fetchNextPage={fetchNextPage}
|
||||
onPreviewClose={onResolve}
|
||||
onNavigate={onResolve}
|
||||
/>
|
||||
</TabsContent>
|
||||
))}
|
||||
@@ -96,7 +96,7 @@ export const showSearchModal = create(({ onResolve }) => {
|
||||
shows={shows}
|
||||
customScrollParent={scrollRef.current}
|
||||
fetchNextPage={fetchNextPage}
|
||||
onPreviewClose={onResolve}
|
||||
onNavigate={onResolve}
|
||||
/>
|
||||
))
|
||||
)}
|
||||
|
||||
@@ -1,33 +1,41 @@
|
||||
'use client';
|
||||
|
||||
import { FC } from 'react';
|
||||
import { VirtuosoGrid, VirtuosoGridProps } from 'react-virtuoso';
|
||||
import { useSetAtom } from 'jotai';
|
||||
|
||||
import Poster from '@/components/Poster';
|
||||
import { showPreviewModal } from '@/components/Preview';
|
||||
import { previewSeedAtom } from '@/components/Preview/seed';
|
||||
|
||||
interface Props {
|
||||
shows: Show[];
|
||||
customScrollParent?: HTMLElement;
|
||||
fetchNextPage?: () => void;
|
||||
onPreviewClose?: () => void;
|
||||
onNavigate?: () => void;
|
||||
}
|
||||
|
||||
const components: VirtuosoGridProps<Movie, { shows: Show[]; onClick: (show: Show) => void }>['components'] = {
|
||||
const components: VirtuosoGridProps<Movie, { shows: Show[]; onNavigate: (show: Show) => void }>['components'] = {
|
||||
Item: ({ context, 'data-index': index }) => {
|
||||
const { shows, onClick } = context!;
|
||||
const { shows, onNavigate } = context!;
|
||||
const show = shows?.[index];
|
||||
|
||||
if (!show) return null;
|
||||
|
||||
return <Poster show={show} onClick={() => onClick?.(show)} />;
|
||||
return <Poster show={show} href={`/${show.type}/${show.id}`} onClick={() => onNavigate(show)} />;
|
||||
}
|
||||
};
|
||||
|
||||
const List: FC<Props> = ({ shows, fetchNextPage, onPreviewClose, customScrollParent }) => {
|
||||
const List: FC<Props> = ({ shows, fetchNextPage, onNavigate, customScrollParent }) => {
|
||||
const setPreviewSeed = useSetAtom(previewSeedAtom);
|
||||
|
||||
if (!shows.length) return null;
|
||||
|
||||
const context = {
|
||||
shows,
|
||||
onClick: (show: Show) => showPreviewModal({ show, onClose: onPreviewClose })
|
||||
onNavigate: (show: Show) => {
|
||||
setPreviewSeed(show);
|
||||
onNavigate?.();
|
||||
}
|
||||
};
|
||||
|
||||
const handleFetchMore = () => fetchNextPage?.();
|
||||
|
||||
@@ -1,24 +1,28 @@
|
||||
'use client';
|
||||
|
||||
import { FC } from 'react';
|
||||
import Link from 'next/link';
|
||||
|
||||
import { useMutateShowState } from '@/hooks/useShowState';
|
||||
|
||||
interface Props {
|
||||
show: Show;
|
||||
href?: string;
|
||||
onClick?: () => void;
|
||||
}
|
||||
|
||||
const Handlers: FC<Props> = ({ onClick, show }) => {
|
||||
const Handlers: FC<Props> = ({ href, onClick, show }) => {
|
||||
const { mutate } = useMutateShowState(show);
|
||||
|
||||
return (
|
||||
<div
|
||||
onClick={onClick}
|
||||
onDoubleClick={() => mutate({ list: 'favorite', value: true })}
|
||||
className='absolute left-0 top-0 size-full'
|
||||
/>
|
||||
);
|
||||
const handlers = {
|
||||
onClick,
|
||||
onDoubleClick: () => mutate({ list: 'favorite', value: true }),
|
||||
className: 'absolute left-0 top-0 size-full'
|
||||
};
|
||||
|
||||
if (!href) return <div {...handlers} />;
|
||||
|
||||
return <Link {...handlers} href={href} prefetch={false} aria-label={show.title} />;
|
||||
};
|
||||
|
||||
export default Handlers;
|
||||
@@ -6,6 +6,7 @@ import Handlers from './components/Handlers';
|
||||
|
||||
interface Props {
|
||||
show: Show;
|
||||
href?: string;
|
||||
onClick?: () => void;
|
||||
className?: string;
|
||||
lazy?: boolean;
|
||||
@@ -14,7 +15,7 @@ interface Props {
|
||||
|
||||
type FetchPriorityProps = ImgHTMLAttributes<HTMLImageElement> & { fetchPriority?: 'high' | 'low' | 'auto' };
|
||||
|
||||
const Poster: FC<Props> = ({ show, onClick, className, lazy = true, priority = false }) => {
|
||||
const Poster: FC<Props> = ({ show, href, onClick, className, lazy = true, priority = false }) => {
|
||||
const fetchPriorityProps: FetchPriorityProps = priority ? { fetchPriority: 'high' } : {};
|
||||
|
||||
return (
|
||||
@@ -38,7 +39,7 @@ const Poster: FC<Props> = ({ show, onClick, className, lazy = true, priority = f
|
||||
{...fetchPriorityProps}
|
||||
/>
|
||||
</picture>
|
||||
<Handlers show={show} onClick={onClick} />
|
||||
<Handlers show={show} href={href} onClick={onClick} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
'use client';
|
||||
|
||||
import { FC, ReactNode } from 'react';
|
||||
import { create, InstanceProps } from 'react-modal-promise';
|
||||
|
||||
import Poster from '@/components/Poster';
|
||||
import Credits from '@/components/Preview/components/Credits';
|
||||
import useDetails from '@/components/Preview/useDetails';
|
||||
import { Modal } from '@/components/ui/dialog';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
import Actions from './components/Actions';
|
||||
@@ -19,7 +17,7 @@ interface Props {
|
||||
showId?: Show['id'];
|
||||
className?: string;
|
||||
posterClassName?: string;
|
||||
onClose?: () => void;
|
||||
modal?: boolean;
|
||||
poster?: ReactNode;
|
||||
externalLink?: boolean;
|
||||
}
|
||||
@@ -30,7 +28,7 @@ const Preview: FC<Props> = ({
|
||||
showId,
|
||||
className,
|
||||
posterClassName,
|
||||
onClose,
|
||||
modal,
|
||||
poster,
|
||||
externalLink = true
|
||||
}) => {
|
||||
@@ -40,7 +38,7 @@ const Preview: FC<Props> = ({
|
||||
|
||||
const show: Show & Partial<Details> = (detailedShow || baseShow)!;
|
||||
|
||||
const isModal = Boolean(onClose);
|
||||
const isModal = Boolean(modal);
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -76,24 +74,11 @@ const Preview: FC<Props> = ({
|
||||
{show.overview}
|
||||
</p>
|
||||
<div className='order-5 mt-5 grid grid-cols-1 rounded-lg md:order-5 md:mt-auto'>
|
||||
<Credits showType={show.type} showId={show.id} onClick={onClose} />
|
||||
<Credits showType={show.type} showId={show.id} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const showPreviewModal = create(({ onResolve, onClose, show }: Props & InstanceProps<void>) => (
|
||||
<Modal className='block bg-background p-0 md:bg-black' onClose={onResolve}>
|
||||
<Preview
|
||||
show={show}
|
||||
onClose={() => {
|
||||
onClose?.();
|
||||
onResolve();
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
}}
|
||||
/>
|
||||
</Modal>
|
||||
));
|
||||
|
||||
export default Preview;
|
||||
@@ -0,0 +1,3 @@
|
||||
import { atom } from 'jotai';
|
||||
|
||||
export const previewSeedAtom = atom<Show | null>(null);
|
||||
@@ -1,16 +1,20 @@
|
||||
'use client';
|
||||
|
||||
import { FC } from 'react';
|
||||
import { useSetAtom } from 'jotai';
|
||||
|
||||
import Poster from '@/components/Poster';
|
||||
import { showPreviewModal } from '@/components/Preview';
|
||||
import { previewSeedAtom } from '@/components/Preview/seed';
|
||||
import ScrollNavigation from '@/components/ScrollNavigation';
|
||||
|
||||
interface Props {
|
||||
shows: Show[];
|
||||
}
|
||||
|
||||
const Gallery: FC<Props> = ({ shows }) => (
|
||||
const Gallery: FC<Props> = ({ shows }) => {
|
||||
const setPreviewSeed = useSetAtom(previewSeedAtom);
|
||||
|
||||
return (
|
||||
<ScrollNavigation<HTMLUListElement>>
|
||||
{({ setScrollElement }) => (
|
||||
<ul
|
||||
@@ -24,7 +28,8 @@ const Gallery: FC<Props> = ({ shows }) => (
|
||||
<Poster
|
||||
className='!h-[350px] !w-[230px] text-sm'
|
||||
show={show}
|
||||
onClick={() => showPreviewModal({ show })}
|
||||
href={`/${show.type}/${show.id}`}
|
||||
onClick={() => setPreviewSeed(show)}
|
||||
/>
|
||||
</li>
|
||||
))}
|
||||
@@ -32,5 +37,6 @@ const Gallery: FC<Props> = ({ shows }) => (
|
||||
)}
|
||||
</ScrollNavigation>
|
||||
);
|
||||
};
|
||||
|
||||
export default Gallery;
|
||||
Reference in new issue
Block a user