From 09b6b0ad864c62d4b4140e45a031c905553fc2f5 Mon Sep 17 00:00:00 2001 From: QkoSad Date: Fri, 2 Dec 2022 22:21:43 +0200 Subject: [PATCH] added map to listings --- package-lock.json | 49 +++++++++++++++++ package.json | 2 + public/index.html | 26 ++------- src/App.js | 7 +++ src/pages/Contact.jsx | 67 +++++++++++++++++++++++ src/pages/Listing.jsx | 120 ++++++++++++++++++++++++++++++++++++++++++ src/pages/Profile.jsx | 43 ++++++++------- 7 files changed, 270 insertions(+), 44 deletions(-) create mode 100644 src/pages/Contact.jsx create mode 100644 src/pages/Listing.jsx diff --git a/package-lock.json b/package-lock.json index c3248bc..39e7cd8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,8 +12,10 @@ "@testing-library/react": "^13.4.0", "@testing-library/user-event": "^13.5.0", "firebase": "^9.14.0", + "leaflet": "^1.9.3", "react": "^18.2.0", "react-dom": "^18.2.0", + "react-leaflet": "^4.2.0", "react-router-dom": "^6.4.3", "react-scripts": "5.0.1", "react-toastify": "^9.1.1", @@ -3718,6 +3720,16 @@ "resolved": "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.0.tgz", "integrity": "sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==" }, + "node_modules/@react-leaflet/core": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@react-leaflet/core/-/core-2.1.0.tgz", + "integrity": "sha512-Qk7Pfu8BSarKGqILj4x7bCSZ1pjuAPZ+qmRwH5S7mDS91VSbVVsJSrW4qA+GPrro8t69gFYVMWb1Zc4yFmPiVg==", + "peerDependencies": { + "leaflet": "^1.9.0", + "react": "^18.0.0", + "react-dom": "^18.0.0" + } + }, "node_modules/@remix-run/router": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.0.3.tgz", @@ -12281,6 +12293,11 @@ "language-subtag-registry": "~0.3.2" } }, + "node_modules/leaflet": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/leaflet/-/leaflet-1.9.3.tgz", + "integrity": "sha512-iB2cR9vAkDOu5l3HAay2obcUHZ7xwUBBjph8+PGtmW/2lYhbLizWtG7nTeYht36WfOslixQF9D/uSIzhZgGMfQ==" + }, "node_modules/leven": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/leven/-/leven-3.1.0.tgz", @@ -14981,6 +14998,19 @@ "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==" }, + "node_modules/react-leaflet": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/react-leaflet/-/react-leaflet-4.2.0.tgz", + "integrity": "sha512-9d8T7hzYrQA5GLe3vn0qtRLJzQKgjr080NKa45yArGwuSl1nH/6aK9gp7DeYdktpdO1vKGSUTGW5AsUS064X0A==", + "dependencies": { + "@react-leaflet/core": "^2.1.0" + }, + "peerDependencies": { + "leaflet": "^1.9.0", + "react": "^18.0.0", + "react-dom": "^18.0.0" + } + }, "node_modules/react-refresh": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.11.0.tgz", @@ -20518,6 +20548,12 @@ "resolved": "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.0.tgz", "integrity": "sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==" }, + "@react-leaflet/core": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@react-leaflet/core/-/core-2.1.0.tgz", + "integrity": "sha512-Qk7Pfu8BSarKGqILj4x7bCSZ1pjuAPZ+qmRwH5S7mDS91VSbVVsJSrW4qA+GPrro8t69gFYVMWb1Zc4yFmPiVg==", + "requires": {} + }, "@remix-run/router": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.0.3.tgz", @@ -26806,6 +26842,11 @@ "language-subtag-registry": "~0.3.2" } }, + "leaflet": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/leaflet/-/leaflet-1.9.3.tgz", + "integrity": "sha512-iB2cR9vAkDOu5l3HAay2obcUHZ7xwUBBjph8+PGtmW/2lYhbLizWtG7nTeYht36WfOslixQF9D/uSIzhZgGMfQ==" + }, "leven": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/leven/-/leven-3.1.0.tgz", @@ -28585,6 +28626,14 @@ "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==" }, + "react-leaflet": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/react-leaflet/-/react-leaflet-4.2.0.tgz", + "integrity": "sha512-9d8T7hzYrQA5GLe3vn0qtRLJzQKgjr080NKa45yArGwuSl1nH/6aK9gp7DeYdktpdO1vKGSUTGW5AsUS064X0A==", + "requires": { + "@react-leaflet/core": "^2.1.0" + } + }, "react-refresh": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.11.0.tgz", diff --git a/package.json b/package.json index 5d7f428..a94eb92 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,10 @@ "@testing-library/react": "^13.4.0", "@testing-library/user-event": "^13.5.0", "firebase": "^9.14.0", + "leaflet": "^1.9.3", "react": "^18.2.0", "react-dom": "^18.2.0", + "react-leaflet": "^4.2.0", "react-router-dom": "^6.4.3", "react-scripts": "5.0.1", "react-toastify": "^9.1.1", diff --git a/public/index.html b/public/index.html index aa069f2..208a942 100644 --- a/public/index.html +++ b/public/index.html @@ -10,34 +10,16 @@ content="Web site created using create-react-app" /> - + - + React App
- diff --git a/src/App.js b/src/App.js index 1f38123..27e02b4 100644 --- a/src/App.js +++ b/src/App.js @@ -11,6 +11,8 @@ import Signin from "./pages/Signin"; import Signup from "./pages/Signup"; import Category from "./pages/Category"; import CreateLising from "./pages/CreateListing"; +import Listing from "./pages/Listing"; +import Contact from "./pages/Contact"; function App() { return ( @@ -28,6 +30,11 @@ function App() { } /> } /> } /> + } + /> + }/> diff --git a/src/pages/Contact.jsx b/src/pages/Contact.jsx new file mode 100644 index 0000000..ab00a60 --- /dev/null +++ b/src/pages/Contact.jsx @@ -0,0 +1,67 @@ +import { useState, useEffect } from "react"; +import { useParams, useSearchParams } from "react-router-dom"; +import { doc, getDoc } from "firebase/firestore"; +import { db } from "../firebase.config"; +import { toast } from "react-toastify"; + +function Contact() { + const [message, setMassage] = useState(""); + const [landlord, setLandlord] = useState(null); + const [searchParams, setSearchParams] = useSearchParams(); + + const params = useParams(); + + useEffect(() => { + const getLandlord = async () => { + const docRef = doc(db, "users", params.landlordId); + const docSnap = await getDoc(docRef); + + if (docSnap.exists()) { + setLandlord(docSnap.data()); + } else { + toast.error("Landlord does not exist"); + } + }; + getLandlord(); + }, [params.landlordId]); + const onChange = (e) => setMassage(e.target.value); + + return ( +
+
+

Contact Landlord

+
+ {landlord !== null && ( +
+
+

Contact {landlord?.name}

+
+
+
+ +