refactor(preview): restore in-place modal, keep crawlable links

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
nerandClaude Fable 5 committed 2026-08-07 16:48:11 +03:00
1 parent 70b825c2dc
commit 8b56268430
13 files changed
+44 -108

No files matched your search

-11
View File
@@ -1,11 +0,0 @@
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;
-11
View File
@@ -1,11 +0,0 @@
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;
-5
View File
@@ -1,5 +0,0 @@
// 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;
-3
View File
@@ -1,3 +0,0 @@
const Default = () => null;
export default Default;
-4
View File
@@ -1,4 +0,0 @@
// Matches the root route so the preview modal unmounts when navigating home.
const Empty = () => null;
export default Empty;
-29
View File
@@ -1,29 +0,0 @@
'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;
-10
View File
@@ -1,10 +0,0 @@
import { ReactNode } from 'react';
const SiteLayout = ({ children, modal }: { children: ReactNode; modal: ReactNode }) => (
<>
{children}
{modal}
</>
);
export default SiteLayout;
@@ -84,7 +84,7 @@ export const showSearchModal = create(({ onResolve }) => {
shows={shows}
customScrollParent={scrollRef.current}
fetchNextPage={fetchNextPage}
onNavigate={onResolve}
onPreviewClose={onResolve}
/>
</TabsContent>
))}
@@ -96,7 +96,7 @@ export const showSearchModal = create(({ onResolve }) => {
shows={shows}
customScrollParent={scrollRef.current}
fetchNextPage={fetchNextPage}
onNavigate={onResolve}
onPreviewClose={onResolve}
/>
))
)}
+7 -15
View File
@@ -1,41 +1,33 @@
'use client';
import { FC } from 'react';
import { VirtuosoGrid, VirtuosoGridProps } from 'react-virtuoso';
import { useSetAtom } from 'jotai';
import Poster from '@/components/Poster';
import { previewSeedAtom } from '@/components/Preview/seed';
import { showPreviewModal } from '@/components/Preview';
interface Props {
shows: Show[];
customScrollParent?: HTMLElement;
fetchNextPage?: () => void;
onNavigate?: () => void;
onPreviewClose?: () => void;
}
const components: VirtuosoGridProps<Movie, { shows: Show[]; onNavigate: (show: Show) => void }>['components'] = {
const components: VirtuosoGridProps<Movie, { shows: Show[]; onClick: (show: Show) => void }>['components'] = {
Item: ({ context, 'data-index': index }) => {
const { shows, onNavigate } = context!;
const { shows, onClick } = context!;
const show = shows?.[index];
if (!show) return null;
return <Poster show={show} href={`/${show.type}/${show.id}`} onClick={() => onNavigate(show)} />;
return <Poster show={show} href={`/${show.type}/${show.id}`} onClick={() => onClick?.(show)} />;
}
};
const List: FC<Props> = ({ shows, fetchNextPage, onNavigate, customScrollParent }) => {
const setPreviewSeed = useSetAtom(previewSeedAtom);
const List: FC<Props> = ({ shows, fetchNextPage, onPreviewClose, customScrollParent }) => {
if (!shows.length) return null;
const context = {
shows,
onNavigate: (show: Show) => {
setPreviewSeed(show);
onNavigate?.();
}
onClick: (show: Show) => showPreviewModal({ show, onClose: onPreviewClose })
};
const handleFetchMore = () => fetchNextPage?.();
@@ -1,6 +1,6 @@
'use client';
import { FC } from 'react';
import { FC, MouseEvent } from 'react';
import Link from 'next/link';
import { useMutateShowState } from '@/hooks/useShowState';
@@ -14,8 +14,18 @@ interface Props {
const Handlers: FC<Props> = ({ href, onClick, show }) => {
const { mutate } = useMutateShowState(show);
// The link exists for crawlers and new-tab clicks; a plain click opens the preview modal in place
const handleClick = (event: MouseEvent<HTMLElement>) => {
if (!onClick) return;
if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
event.preventDefault();
onClick();
};
const handlers = {
onClick,
onClick: handleClick,
onDoubleClick: () => mutate({ list: 'favorite', value: true }),
className: 'absolute left-0 top-0 size-full'
};
+19 -4
View File
@@ -1,10 +1,12 @@
'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';
@@ -17,7 +19,7 @@ interface Props {
showId?: Show['id'];
className?: string;
posterClassName?: string;
modal?: boolean;
onClose?: () => void;
poster?: ReactNode;
externalLink?: boolean;
}
@@ -28,7 +30,7 @@ const Preview: FC<Props> = ({
showId,
className,
posterClassName,
modal,
onClose,
poster,
externalLink = true
}) => {
@@ -38,7 +40,7 @@ const Preview: FC<Props> = ({
const show: Show & Partial<Details> = (detailedShow || baseShow)!;
const isModal = Boolean(modal);
const isModal = Boolean(onClose);
return (
<div
@@ -74,11 +76,24 @@ 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} />
<Credits showType={show.type} showId={show.id} onClick={onClose} />
</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;
-3
View File
@@ -1,3 +0,0 @@
import { atom } from 'jotai';
export const previewSeedAtom = atom<Show | null>(null);
@@ -1,20 +1,16 @@
'use client';
import { FC } from 'react';
import { useSetAtom } from 'jotai';
import Poster from '@/components/Poster';
import { previewSeedAtom } from '@/components/Preview/seed';
import { showPreviewModal } from '@/components/Preview';
import ScrollNavigation from '@/components/ScrollNavigation';
interface Props {
shows: Show[];
}
const Gallery: FC<Props> = ({ shows }) => {
const setPreviewSeed = useSetAtom(previewSeedAtom);
return (
const Gallery: FC<Props> = ({ shows }) => (
<ScrollNavigation<HTMLUListElement>>
{({ setScrollElement }) => (
<ul
@@ -29,14 +25,13 @@ const Gallery: FC<Props> = ({ shows }) => {
className='!h-[350px] !w-[230px] text-sm'
show={show}
href={`/${show.type}/${show.id}`}
onClick={() => setPreviewSeed(show)}
onClick={() => showPreviewModal({ show })}
/>
</li>
))}
</ul>
)}
</ScrollNavigation>
);
};
);
export default Gallery;