From 904f77fe7396556b8b6026e5838bbfd1e42e66c2 Mon Sep 17 00:00:00 2001 From: Dang Nguyen Nguyen Date: Wed, 30 Aug 2023 19:31:16 -0700 Subject: [PATCH] add click to place marker --- src/components/Home/Home.jsx | 208 ++++++++++++++++++--------------- src/components/Map/Map.jsx | 38 +++++- src/components/Map/MapIcons.js | 4 +- 3 files changed, 151 insertions(+), 99 deletions(-) diff --git a/src/components/Home/Home.jsx b/src/components/Home/Home.jsx index 051a4f2..ddeb496 100644 --- a/src/components/Home/Home.jsx +++ b/src/components/Home/Home.jsx @@ -32,6 +32,10 @@ import { DrawerOverlay, DrawerContent, DrawerCloseButton, + Alert, + AlertIcon, + AlertTitle, + AlertDescription, } from "@chakra-ui/react"; import { SettingsIcon, ChevronDownIcon, StarIcon } from "@chakra-ui/icons"; import logo from "../../assets/images/small_logo.png"; @@ -91,7 +95,6 @@ export default function Home() { const [focusLocation, setFocusLocation] = useState(); const [screenWidth, setScreenWidth] = useState(window.screen.width); const [uploadImg, setUploadImg] = useState(""); - console.log("In parent, setUploadImg type:", typeof setUploadImg); // LOGIN MODAL const { @@ -333,6 +336,7 @@ export default function Home() { + - - - + {isEdit ? ( + + + + Click on the Map to place your item 📍 + + + ) : ( + <> + + + - - - - - - {isFilterOff() ? ( - All Posts - ) : ( - - - Filter: ON - - - - )} - - - - - - - setSearch(e.target.value)} - /> - + + + + + + {isFilterOff() ? ( + All Posts + ) : ( + + + Filter: ON + + + + )} + + + + + + + setSearch(e.target.value)} + /> + - - + + - - - - - - + + + + + + + + )} { return ( @@ -172,7 +172,7 @@ export default function Map({ itemDate: "", }); setIsCreate(!isCreate); - setUploadImg("") + setUploadImg(""); }) .catch((err) => console.log(err)); @@ -214,6 +214,33 @@ export default function Map({ ); } + const NewItemMarker = () => { + const map = useMapEvents({ + click(event) { + const { lat, lng } = event.latlng; + setPosition([lat, lng]); + }, + }); + + return position[0] !== centerPosition[0] && + position[1] !== centerPosition[1] ? ( + + + toggleDraggable()}> + Click to Confirm Location 🤔 + + + + ) : null; + }; + return (
} {!isEdit} {!isEdit && allMarkers} - {isEdit && ( + {/* {isEdit && ( - )} + )} */} + {isEdit && } {showDonut && focusLocation && ( <>