refactor(preview): restore in-place modal, keep crawlable links
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
70b825c2dc
commit
8b56268430
13 files changed
+44
-108
No files matched your search
@@ -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;
|
|
||||||
@@ -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;
|
|
||||||
@@ -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;
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
const Default = () => null;
|
|
||||||
|
|
||||||
export default Default;
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
// Matches the root route so the preview modal unmounts when navigating home.
|
|
||||||
const Empty = () => null;
|
|
||||||
|
|
||||||
export default Empty;
|
|
||||||
@@ -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;
|
|
||||||
@@ -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}
|
shows={shows}
|
||||||
customScrollParent={scrollRef.current}
|
customScrollParent={scrollRef.current}
|
||||||
fetchNextPage={fetchNextPage}
|
fetchNextPage={fetchNextPage}
|
||||||
onNavigate={onResolve}
|
onPreviewClose={onResolve}
|
||||||
/>
|
/>
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
))}
|
))}
|
||||||
@@ -96,7 +96,7 @@ export const showSearchModal = create(({ onResolve }) => {
|
|||||||
shows={shows}
|
shows={shows}
|
||||||
customScrollParent={scrollRef.current}
|
customScrollParent={scrollRef.current}
|
||||||
fetchNextPage={fetchNextPage}
|
fetchNextPage={fetchNextPage}
|
||||||
onNavigate={onResolve}
|
onPreviewClose={onResolve}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,41 +1,33 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { FC } from 'react';
|
import { FC } from 'react';
|
||||||
import { VirtuosoGrid, VirtuosoGridProps } from 'react-virtuoso';
|
import { VirtuosoGrid, VirtuosoGridProps } from 'react-virtuoso';
|
||||||
import { useSetAtom } from 'jotai';
|
|
||||||
|
|
||||||
import Poster from '@/components/Poster';
|
import Poster from '@/components/Poster';
|
||||||
import { previewSeedAtom } from '@/components/Preview/seed';
|
import { showPreviewModal } from '@/components/Preview';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
shows: Show[];
|
shows: Show[];
|
||||||
customScrollParent?: HTMLElement;
|
customScrollParent?: HTMLElement;
|
||||||
fetchNextPage?: () => void;
|
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 }) => {
|
Item: ({ context, 'data-index': index }) => {
|
||||||
const { shows, onNavigate } = context!;
|
const { shows, onClick } = context!;
|
||||||
const show = shows?.[index];
|
const show = shows?.[index];
|
||||||
|
|
||||||
if (!show) return null;
|
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 List: FC<Props> = ({ shows, fetchNextPage, onPreviewClose, customScrollParent }) => {
|
||||||
const setPreviewSeed = useSetAtom(previewSeedAtom);
|
|
||||||
|
|
||||||
if (!shows.length) return null;
|
if (!shows.length) return null;
|
||||||
|
|
||||||
const context = {
|
const context = {
|
||||||
shows,
|
shows,
|
||||||
onNavigate: (show: Show) => {
|
onClick: (show: Show) => showPreviewModal({ show, onClose: onPreviewClose })
|
||||||
setPreviewSeed(show);
|
|
||||||
onNavigate?.();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleFetchMore = () => fetchNextPage?.();
|
const handleFetchMore = () => fetchNextPage?.();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { FC } from 'react';
|
import { FC, MouseEvent } from 'react';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
|
|
||||||
import { useMutateShowState } from '@/hooks/useShowState';
|
import { useMutateShowState } from '@/hooks/useShowState';
|
||||||
@@ -14,8 +14,18 @@ interface Props {
|
|||||||
const Handlers: FC<Props> = ({ href, onClick, show }) => {
|
const Handlers: FC<Props> = ({ href, onClick, show }) => {
|
||||||
const { mutate } = useMutateShowState(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 = {
|
const handlers = {
|
||||||
onClick,
|
onClick: handleClick,
|
||||||
onDoubleClick: () => mutate({ list: 'favorite', value: true }),
|
onDoubleClick: () => mutate({ list: 'favorite', value: true }),
|
||||||
className: 'absolute left-0 top-0 size-full'
|
className: 'absolute left-0 top-0 size-full'
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { FC, ReactNode } from 'react';
|
import { FC, ReactNode } from 'react';
|
||||||
|
import { create, InstanceProps } from 'react-modal-promise';
|
||||||
|
|
||||||
import Poster from '@/components/Poster';
|
import Poster from '@/components/Poster';
|
||||||
import Credits from '@/components/Preview/components/Credits';
|
import Credits from '@/components/Preview/components/Credits';
|
||||||
import useDetails from '@/components/Preview/useDetails';
|
import useDetails from '@/components/Preview/useDetails';
|
||||||
|
import { Modal } from '@/components/ui/dialog';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
import Actions from './components/Actions';
|
import Actions from './components/Actions';
|
||||||
@@ -17,7 +19,7 @@ interface Props {
|
|||||||
showId?: Show['id'];
|
showId?: Show['id'];
|
||||||
className?: string;
|
className?: string;
|
||||||
posterClassName?: string;
|
posterClassName?: string;
|
||||||
modal?: boolean;
|
onClose?: () => void;
|
||||||
poster?: ReactNode;
|
poster?: ReactNode;
|
||||||
externalLink?: boolean;
|
externalLink?: boolean;
|
||||||
}
|
}
|
||||||
@@ -28,7 +30,7 @@ const Preview: FC<Props> = ({
|
|||||||
showId,
|
showId,
|
||||||
className,
|
className,
|
||||||
posterClassName,
|
posterClassName,
|
||||||
modal,
|
onClose,
|
||||||
poster,
|
poster,
|
||||||
externalLink = true
|
externalLink = true
|
||||||
}) => {
|
}) => {
|
||||||
@@ -38,7 +40,7 @@ const Preview: FC<Props> = ({
|
|||||||
|
|
||||||
const show: Show & Partial<Details> = (detailedShow || baseShow)!;
|
const show: Show & Partial<Details> = (detailedShow || baseShow)!;
|
||||||
|
|
||||||
const isModal = Boolean(modal);
|
const isModal = Boolean(onClose);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@@ -74,11 +76,24 @@ const Preview: FC<Props> = ({
|
|||||||
{show.overview}
|
{show.overview}
|
||||||
</p>
|
</p>
|
||||||
<div className='order-5 mt-5 grid grid-cols-1 rounded-lg md:order-5 md:mt-auto'>
|
<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>
|
</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;
|
export default Preview;
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
import { atom } from 'jotai';
|
|
||||||
|
|
||||||
export const previewSeedAtom = atom<Show | null>(null);
|
|
||||||
@@ -1,20 +1,16 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { FC } from 'react';
|
import { FC } from 'react';
|
||||||
import { useSetAtom } from 'jotai';
|
|
||||||
|
|
||||||
import Poster from '@/components/Poster';
|
import Poster from '@/components/Poster';
|
||||||
import { previewSeedAtom } from '@/components/Preview/seed';
|
import { showPreviewModal } from '@/components/Preview';
|
||||||
import ScrollNavigation from '@/components/ScrollNavigation';
|
import ScrollNavigation from '@/components/ScrollNavigation';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
shows: Show[];
|
shows: Show[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const Gallery: FC<Props> = ({ shows }) => {
|
const Gallery: FC<Props> = ({ shows }) => (
|
||||||
const setPreviewSeed = useSetAtom(previewSeedAtom);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ScrollNavigation<HTMLUListElement>>
|
<ScrollNavigation<HTMLUListElement>>
|
||||||
{({ setScrollElement }) => (
|
{({ setScrollElement }) => (
|
||||||
<ul
|
<ul
|
||||||
@@ -29,14 +25,13 @@ const Gallery: FC<Props> = ({ shows }) => {
|
|||||||
className='!h-[350px] !w-[230px] text-sm'
|
className='!h-[350px] !w-[230px] text-sm'
|
||||||
show={show}
|
show={show}
|
||||||
href={`/${show.type}/${show.id}`}
|
href={`/${show.type}/${show.id}`}
|
||||||
onClick={() => setPreviewSeed(show)}
|
onClick={() => showPreviewModal({ show })}
|
||||||
/>
|
/>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
)}
|
)}
|
||||||
</ScrollNavigation>
|
</ScrollNavigation>
|
||||||
);
|
);
|
||||||
};
|
|
||||||
|
|
||||||
export default Gallery;
|
export default Gallery;
|
||||||
Reference in new issue
Block a user