From 716c5f79a43b389f24b3df2469e30a35d8dd61d7 Mon Sep 17 00:00:00 2001 From: HyunJinNo Date: Sun, 21 Jul 2024 17:09:22 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EB=B7=B0?= =?UTF-8?q?=EC=96=B4=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../informations/detail/ImageList.tsx | 81 +++++++++++++++++++ .../informations/detail/ImageViewer.tsx | 71 ++++------------ .../informations/detail/InformationViewer.tsx | 4 +- .../detail/ImageListContainer.tsx | 31 +++++++ .../detail/ImageViewerContainer.tsx | 25 ------ 5 files changed, 131 insertions(+), 81 deletions(-) create mode 100644 src/components/informations/detail/ImageList.tsx create mode 100644 src/containers/informations/detail/ImageListContainer.tsx delete mode 100644 src/containers/informations/detail/ImageViewerContainer.tsx diff --git a/src/components/informations/detail/ImageList.tsx b/src/components/informations/detail/ImageList.tsx new file mode 100644 index 00000000..5fc19940 --- /dev/null +++ b/src/components/informations/detail/ImageList.tsx @@ -0,0 +1,81 @@ +import { useDragScrollType } from "@/hooks/useDragScroll"; +import Image from "next/image"; +import { Dispatch, SetStateAction } from "react"; +import ImageViewer from "./ImageViewer"; + +interface Props { + scrollHook: useDragScrollType; + images: Array>; + mainImageUrl: string; + viewerVisible: boolean; + setMainImageUrl: Dispatch>; + openViewer: () => void; + closeViewer: () => void; +} + +const ImageList = ({ + scrollHook, + images, + mainImageUrl, + viewerVisible, + setMainImageUrl, + openViewer, + closeViewer, +}: Props) => { + return ( +
+ {viewerVisible && ( + + )} +
+ {"/background"} openViewer()} + /> +
+
{ + e.preventDefault(); + scrollHook.onDragStart(e); + }} + onMouseMove={scrollHook.onDragMove} + onMouseUp={scrollHook.onDragEnd} + onMouseLeave={scrollHook.onDragEnd} + onTouchStart={scrollHook.onTouchStart} + onTouchMove={scrollHook.onTouchMove} + onTouchEnd={scrollHook.onTouchEnd} + > + {images.map((image, index) => ( +
{ + setMainImageUrl(image.address); + }} + onTouchEnd={() => { + setMainImageUrl(image.address); + }} + > + {"/background"} +
+ ))} +
+
+ ); +}; + +export default ImageList; diff --git a/src/components/informations/detail/ImageViewer.tsx b/src/components/informations/detail/ImageViewer.tsx index 55521143..adeae07a 100644 --- a/src/components/informations/detail/ImageViewer.tsx +++ b/src/components/informations/detail/ImageViewer.tsx @@ -1,63 +1,26 @@ -import { useDragScrollType } from "@/hooks/useDragScroll"; import Image from "next/image"; +import { MdClose } from "react-icons/md"; interface Props { - images: Array>; - mainImageIndex: number; - scrollHook: useDragScrollType; - setMainImageIndex: (index: number) => void; + imageUrl: string; + closeViewer: () => void; } -const ImageViewer = ({ images, scrollHook, setMainImageIndex }: Props) => { +const ImageViewer = ({ imageUrl, closeViewer }: Props) => { return ( -
-
- image.imageStatus === "썸네일")[0].address - } - alt={"/background"} - fill={true} - style={{ - objectFit: "cover", - }} - /> -
-
{ - e.preventDefault(); - scrollHook.onDragStart(e); - }} - onMouseMove={scrollHook.onDragMove} - onMouseUp={scrollHook.onDragEnd} - onMouseLeave={scrollHook.onDragEnd} - onTouchStart={scrollHook.onTouchStart} - onTouchMove={scrollHook.onTouchMove} - onTouchEnd={scrollHook.onTouchEnd} - > - {images.map((image, index) => ( -
{ - setMainImageIndex(index); - }} - onTouchEnd={() => { - setMainImageIndex(index); - }} - > - {"/background"} -
- ))} +
+
+
+ closeViewer()} /> +
+
+ image +
); diff --git a/src/components/informations/detail/InformationViewer.tsx b/src/components/informations/detail/InformationViewer.tsx index 6059019b..fc8e4e9a 100644 --- a/src/components/informations/detail/InformationViewer.tsx +++ b/src/components/informations/detail/InformationViewer.tsx @@ -3,10 +3,10 @@ import Image from "next/image"; import { FaRegHeart } from "react-icons/fa"; import { TiLocation } from "react-icons/ti"; import KakaoMapLinkContainer from "@/containers/common/KakaoMapLinkContainer"; -import ImageViewerContainer from "@/containers/informations/detail/ImageViewerContainer"; import { LuEye } from "react-icons/lu"; import { InformationDetailDto } from "@/types/InformationDto"; import ButtonListContainer from "@/containers/informations/detail/ButtonListContainer"; +import ImageListContainer from "@/containers/informations/detail/ImageListContainer"; async function getInformation(id: number) { const response = await fetch( @@ -70,7 +70,7 @@ const InformationViewer = async ({ informationId }: Props) => {
- +
diff --git a/src/containers/informations/detail/ImageListContainer.tsx b/src/containers/informations/detail/ImageListContainer.tsx new file mode 100644 index 00000000..4d507245 --- /dev/null +++ b/src/containers/informations/detail/ImageListContainer.tsx @@ -0,0 +1,31 @@ +"use client"; + +import ImageList from "@/components/informations/detail/ImageList"; +import useDragScroll from "@/hooks/useDragScroll"; +import { useState } from "react"; + +interface Props { + images: Array>; +} + +const ImageListContainer = ({ images }: Props) => { + const scrollHook = useDragScroll(); + const [mainImageUrl, setMainImageUrl] = useState( + images.find((image) => image.imageStatus === "썸네일")?.address ?? "", + ); + const [viewerVisible, setViewerVisible] = useState(false); + + return ( + setViewerVisible(true)} + closeViewer={() => setViewerVisible(false)} + /> + ); +}; + +export default ImageListContainer; diff --git a/src/containers/informations/detail/ImageViewerContainer.tsx b/src/containers/informations/detail/ImageViewerContainer.tsx deleted file mode 100644 index 6e80d07b..00000000 --- a/src/containers/informations/detail/ImageViewerContainer.tsx +++ /dev/null @@ -1,25 +0,0 @@ -"use client"; - -import ImageViewer from "@/components/informations/detail/ImageViewer"; -import useDragScroll from "@/hooks/useDragScroll"; -import { useState } from "react"; - -interface Props { - images: Array>; -} - -const ImageViewerContainer = ({ images }: Props) => { - const [mainImageIndex, setMainImageIndex] = useState(0); - const scrollHook = useDragScroll(); - - return ( - - ); -}; - -export default ImageViewerContainer;