mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
Closes: https://github.com/vercel/next.js/issues/96204 The fix to manage rewrites introduced in https://github.com/vercel/next.js/pull/82236 PR made it so that, push/replace without explicit pathname broke the `as` pattern, for example in `with-vercel-blob`. Also documents the resolution rule in the `useRouter` API reference.
86 lines
1.9 KiB
TypeScript
86 lines
1.9 KiB
TypeScript
import { Dialog } from "@headlessui/react";
|
|
import { motion } from "framer-motion";
|
|
import { useRouter } from "next/router";
|
|
import { useRef, useState } from "react";
|
|
import useKeypress from "react-use-keypress";
|
|
import type { ImageProps } from "../utils/types";
|
|
import SharedModal from "./SharedModal";
|
|
|
|
export default function Modal({
|
|
images,
|
|
onClose,
|
|
}: {
|
|
images: ImageProps[];
|
|
onClose?: () => void;
|
|
}) {
|
|
let overlayRef = useRef();
|
|
const router = useRouter();
|
|
|
|
const { photoId } = router.query;
|
|
let index = Number(photoId);
|
|
|
|
const [direction, setDirection] = useState(0);
|
|
const [curIndex, setCurIndex] = useState(index);
|
|
|
|
function handleClose() {
|
|
router.push("/", undefined, { shallow: true });
|
|
onClose();
|
|
}
|
|
|
|
function changePhotoId(newVal: number) {
|
|
if (newVal > index) {
|
|
setDirection(1);
|
|
} else {
|
|
setDirection(-1);
|
|
}
|
|
setCurIndex(newVal);
|
|
router.push(
|
|
{
|
|
pathname: "/",
|
|
query: { photoId: newVal },
|
|
},
|
|
`/p/${newVal}`,
|
|
{ shallow: true },
|
|
);
|
|
}
|
|
|
|
useKeypress("ArrowRight", () => {
|
|
if (index + 1 < images.length) {
|
|
changePhotoId(index + 1);
|
|
}
|
|
});
|
|
|
|
useKeypress("ArrowLeft", () => {
|
|
if (index > 0) {
|
|
changePhotoId(index - 1);
|
|
}
|
|
});
|
|
|
|
return (
|
|
<Dialog
|
|
static
|
|
open={true}
|
|
onClose={handleClose}
|
|
initialFocus={overlayRef}
|
|
className="fixed inset-0 z-10 flex items-center justify-center"
|
|
>
|
|
<Dialog.Overlay
|
|
ref={overlayRef}
|
|
as={motion.div}
|
|
key="backdrop"
|
|
className="fixed inset-0 z-30 bg-black/70 backdrop-blur-2xl"
|
|
initial={{ opacity: 0 }}
|
|
animate={{ opacity: 1 }}
|
|
/>
|
|
<SharedModal
|
|
index={curIndex}
|
|
direction={direction}
|
|
images={images}
|
|
changePhotoId={changePhotoId}
|
|
closeModal={handleClose}
|
|
navigation={true}
|
|
/>
|
|
</Dialog>
|
|
);
|
|
}
|