Buckets:
| 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( | |
| { | |
| 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> | |
| ); | |
| } | |
Xet Storage Details
- Size:
- 1.91 kB
- Xet hash:
- 3e0ee3f8484c3d1342bcc3dde4c4e7cc28ed691292697a3c40e23d5efc778287
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.