diff --git a/src/App.jsx b/src/App.jsx index d98e9cb..e2450e3 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -14,7 +14,6 @@ import MainRouter from "./controllers/MainRouter"; export const App = () => { const { loading } = useAuth0(); const [searchString, setSearchString] = useState(""); - const [searchResults, setSearchResults] = useState({ meals: [] }); // Default meal object. TODO: Find a better alternative … const mealDef = { @@ -93,8 +92,8 @@ export const App = () => { : getData(searchString, setSearchResults, "search"); }; - const handleChange = (ev) => { - const { value } = ev.target; + const handleChange = (e) => { + const { value } = e.target; setSearchString(value); }; diff --git a/src/components/ContactForm.jsx b/src/components/ContactForm.jsx index 6c449f5..a85fda0 100644 --- a/src/components/ContactForm.jsx +++ b/src/components/ContactForm.jsx @@ -8,8 +8,8 @@ export const ContactForm = ({ setIsSubmitted }) => { const [phone, setPhone] = useState(""); const [message, setMessage] = useState(""); - const handleSubmit = (ev) => { - ev.preventDefault(); + const handleSubmit = (e) => { + e.preventDefault(); // confirmationMail(email); // const body = `Sender: ${firstName} ${lastName}\nPhone: ${phone}\nMessage: ${message}`; // notificationMail(email, `New message from ${firstName} ${lastName}`, body); diff --git a/src/controllers/ProfileController.jsx b/src/controllers/ProfileController.jsx index 03394ed..c1b0fe9 100644 --- a/src/controllers/ProfileController.jsx +++ b/src/controllers/ProfileController.jsx @@ -1,18 +1,23 @@ -import React from "react"; +import React, { useEffect, useState } from "react"; import { useAuth0 } from "../utils/auth0-spa"; import { PreLoader } from "../components/PreLoader"; import { ProfilePage } from "../pages/ProfilePage"; +import { useFirebase } from "../services/Firebase"; export const ProfileController = () => { const { loading, user } = useAuth0(); + const [data, setData] = useState(); + const db = useFirebase(); - // const fn = async () => await fire.getByEmail(user.email); + useEffect(() => { + db.get(user.email).then((res) => setData(res)); + }, [db, user.email]); return loading || !user ? ( // is catched by PrivateRoute
) : ( - + ); }; diff --git a/src/layouts/MainLayout.jsx b/src/layouts/MainLayout.jsx index 5844a25..7e3a5f0 100644 --- a/src/layouts/MainLayout.jsx +++ b/src/layouts/MainLayout.jsx @@ -1,5 +1,4 @@ import React, { useState } from "react"; - import { Navbar } from "../components/Navbar"; import { SearchBar } from "../components/SearchBar"; import { Footer } from "../components/Footer"; @@ -19,26 +18,26 @@ const MainLayout = ({ const links = ["categories", "contact"]; - const openNavClick = (ev) => { - ev.preventDefault(); + const openNavClick = (e) => { + e.preventDefault(); setShowNav(true); document.addEventListener("keydown", handleEscKey); // document.addEventListener("click", handleOutsideClick); }; - const closeNavClick = (ev) => { - ev.preventDefault(); + const closeNavClick = (e) => { + e.preventDefault(); setShowNav(false); document.removeEventListener("keydown", handleEscKey); }; - const handleEscKey = (ev) => { - if (ev.key === "Escape") { + const handleEscKey = (e) => { + if (e.key === "Escape") { setShowNav(false); } }; - // const handleOutsideClick = ev => { - // console.log(ev); + // const handleOutsideClick = e => { + // console.log(e); // }; return ( diff --git a/src/pages/ProfilePage.jsx b/src/pages/ProfilePage.jsx index b5c3986..0d5edbf 100644 --- a/src/pages/ProfilePage.jsx +++ b/src/pages/ProfilePage.jsx @@ -1,6 +1,6 @@ import React from "react"; -export const ProfilePage = ({ user }) => { +export const ProfilePage = ({ user, data }) => { return (
@@ -14,9 +14,8 @@ export const ProfilePage = ({ user }) => {

Email: {user.email} - {/* {user.email} */} + {JSON.stringify(data, null, 2)}

- {/* {JSON.stringify(user, null, 2)} */}
); diff --git a/src/services/Firebase/firebase.js b/src/services/Firebase/firebase.js index 5d1740e..0fa31ac 100644 --- a/src/services/Firebase/firebase.js +++ b/src/services/Firebase/firebase.js @@ -20,7 +20,7 @@ export default class Firebase { app.initializeApp(CONFIG); this.db = app.firestore(); } - + // this should put email, idMeal, strMeal and isFav add = async (email, id, fav) => { await this.db .collection("MealPlannerFavs") @@ -39,4 +39,15 @@ export default class Firebase { const snapshot = query.docs[0]; return snapshot.data(); }; + + // get all favs for user 'email' + get = async (email) => { + const query = await this.db + .collection("mealPlannerUsers") + .where("email", "==", email) + .get(); + // .then((doc) => doc.data()); + const snapshot = query.docs[0]; + return snapshot.data(); + }; } diff --git a/src/utils/inputHook.js b/src/utils/inputHook.js index 77b8781..b777e7d 100644 --- a/src/utils/inputHook.js +++ b/src/utils/inputHook.js @@ -1,6 +1,6 @@ import { useState } from "react"; -export const useInput = initialValue => { +export const useInput = (initialValue) => { const [value, setValue] = useState(initialValue); return { @@ -9,9 +9,9 @@ export const useInput = initialValue => { reset: () => setValue(""), bind: { value, - onChange: ev => { - setValue(ev.target.value); - } - } + onChange: (e) => { + setValue(e.target.value); + }, + }, }; };