From 2a6f843d36b2aef09308e346e7d58bd487173596 Mon Sep 17 00:00:00 2001 From: Ruidy Nemausat Date: Wed, 15 Apr 2020 09:34:41 +0200 Subject: [PATCH] refactoring. Add MainLayout and MainRouter --- TODO.md | 7 +- src/App.jsx | 149 +++++------------------ src/components/CardEntry.jsx | 4 +- src/components/CategoryEntry.jsx | 6 +- src/components/Footer.jsx | 4 +- src/components/IngredientList.jsx | 3 +- src/components/Logo.jsx | 22 ++-- src/components/MealPresentation.jsx | 4 +- src/components/Recipe.jsx | 4 +- src/components/SearchBar.jsx | 3 +- src/components/SearchResult.jsx | 3 +- src/components/SideNav.jsx | 156 ++++++++++++------------- src/controllers/CategoryController.jsx | 14 +-- src/controllers/HomeController.jsx | 1 - src/controllers/MainRouter.jsx | 80 +++++++++++++ src/controllers/MealController.jsx | 1 - src/controllers/SearchController.jsx | 1 - src/layouts/MainLayout.jsx | 75 ++++++++++++ src/pages/CategoryPage.jsx | 1 - src/services/Firebase/context.js | 2 + src/services/Firebase/firebase.js | 2 + src/services/Firebase/index.js | 2 + src/utils/mail.js | 14 +-- 23 files changed, 309 insertions(+), 249 deletions(-) create mode 100644 src/controllers/MainRouter.jsx create mode 100644 src/layouts/MainLayout.jsx diff --git a/TODO.md b/TODO.md index 85bd842..04dd657 100644 --- a/TODO.md +++ b/TODO.md @@ -1,11 +1,14 @@ # TO DO - [ ] send message after contact form validation (confirm to sender and msg+info to admin) -- [ ] Local storage of prefeernces -- [ ] Firebase +- [ ] Local storage of preferences +- [ ] Firebase firestore and functions - [ ] Breadcrumb - [ ] Cookie bar - [ ] code cleanup (props and refactoring) - [ ] Back to top button - [ ] Close Sidebar at outside click - [ ] Take a look at some components [here](http://react-materialize.github.io/react-materialize/?path=/story/css-grid--default) +- [ ] Decoupled application and data layers. Abstract such that the front end does not know where the data comes from. +- [ ] Create PageLayout component +- [ ] Use Css-in-Js diff --git a/src/App.jsx b/src/App.jsx index cf4f725..d98e9cb 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,24 +1,15 @@ import React, { useState } from "react"; import { Router } from "./utils/router"; -import { Switch, Route, Redirect } from "react-router-dom"; + +import { PreLoader } from "./components/PreLoader"; + import { useAuth0 } from "./utils/auth0-spa"; -import { SearchController } from "./controllers/SearchController"; -import { ContactPage } from "./pages/Contact"; -import { NotFoundPage } from "./pages/NotFoundPage"; -import { Navbar } from "./components/Navbar"; -import { SearchBar } from "./components/SearchBar"; -import { Footer } from "./components/Footer"; import { getData } from "./utils/methods"; import history from "./utils/history"; -import { ProfileController } from "./controllers/ProfileController"; -import { PrivateRoute } from "./components/PrivateRoute"; -import { PreLoader } from "./components/PreLoader"; -import { SideNav } from "./components/SideNav"; + import "./index.css"; -import { HomeController } from "./controllers/HomeController"; -import { MealController } from "./controllers/MealController"; -import { CategoryListController } from "./controllers/CategoryListController"; -import { CategoryController } from "./controllers/CategoryController"; +import MainLayout from "./layouts/MainLayout"; +import MainRouter from "./controllers/MainRouter"; export const App = () => { const { loading } = useAuth0(); @@ -85,6 +76,7 @@ export const App = () => { }, ], }; + const [meal, setMeal] = useState(mealDef); const getMeal = (id) => { @@ -108,114 +100,33 @@ export const App = () => { const buttonUrl = "/random"; - const [showNav, setShowNav] = useState(false); - const openNavClick = (ev) => { - ev.preventDefault(); - setShowNav(true); - document.addEventListener("keydown", handleEscKey); - // document.addEventListener("click", handleOutsideClick); - }; - const closeNavClick = (ev) => { - ev.preventDefault(); - setShowNav(false); - document.removeEventListener("keydown", handleEscKey); - }; - const handleEscKey = (ev) => { - if (ev.key === "Escape") { - setShowNav(false); - } - }; - // const handleOutsideClick = ev => { - // console.log(ev); - // }; - - const links = ["categories", "contact"]; - return loading ? (
) : ( - <> - -
- - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -