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
+64
-128
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}
|
||||
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}
|
||||
/>
|
||||
))
|
||||
)}
|
||||
|
||||
@@ -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'
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
@@ -1,3 +0,0 @@
|
||||
import { atom } from 'jotai';
|
||||
|
||||
export const previewSeedAtom = atom<Show | null>(null);
|
||||
@@ -1,42 +1,37 @@
|
||||
'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 (
|
||||
<ScrollNavigation<HTMLUListElement>>
|
||||
{({ setScrollElement }) => (
|
||||
<ul
|
||||
ref={setScrollElement}
|
||||
className='no-scrollbar flex animate-fade-aside-slide-in snap-x snap-mandatory gap-2 overflow-auto rounded-lg opacity-0'
|
||||
>
|
||||
{shows
|
||||
.filter((show) => show.poster['1x'])
|
||||
.map((show) => (
|
||||
<li key={show.id} className='snap-start'>
|
||||
<Poster
|
||||
className='!h-[350px] !w-[230px] text-sm'
|
||||
show={show}
|
||||
href={`/${show.type}/${show.id}`}
|
||||
onClick={() => setPreviewSeed(show)}
|
||||
/>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</ScrollNavigation>
|
||||
);
|
||||
};
|
||||
const Gallery: FC<Props> = ({ shows }) => (
|
||||
<ScrollNavigation<HTMLUListElement>>
|
||||
{({ setScrollElement }) => (
|
||||
<ul
|
||||
ref={setScrollElement}
|
||||
className='no-scrollbar flex animate-fade-aside-slide-in snap-x snap-mandatory gap-2 overflow-auto rounded-lg opacity-0'
|
||||
>
|
||||
{shows
|
||||
.filter((show) => show.poster['1x'])
|
||||
.map((show) => (
|
||||
<li key={show.id} className='snap-start'>
|
||||
<Poster
|
||||
className='!h-[350px] !w-[230px] text-sm'
|
||||
show={show}
|
||||
href={`/${show.type}/${show.id}`}
|
||||
onClick={() => showPreviewModal({ show })}
|
||||
/>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</ScrollNavigation>
|
||||
);
|
||||
|
||||
export default Gallery;
|
||||
Reference in new issue
Block a user