From 162857407d63869aeb8c570b186893a3c60acaf8 Mon Sep 17 00:00:00 2001 From: Ruidy Nemausat Date: Tue, 28 Jan 2020 12:19:44 +0100 Subject: [PATCH] error Handling --- README.md | 2 +- src/App.js | 28 ++++++++------- src/components/Logo.js | 4 +-- src/index.css | 2 +- src/index.js | 2 +- src/pages/Category.js | 46 ++++++++++++------------ src/pages/Home.js | 6 +--- src/pages/Meal.js | 82 ++++++++++++++++++++++-------------------- src/pages/Search.js | 19 ++++++---- 9 files changed, 101 insertions(+), 90 deletions(-) diff --git a/README.md b/README.md index 4724399..ee6ae25 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,6 @@ Free meal planner for cooks short on ideas! (like me …) ## TO DO - put a preloader -- visual styling - route bad request to notFOund (exple: /categories/string, when search results is null) - add sidenav on mobile +- contact form diff --git a/src/App.js b/src/App.js index c5c790a..1220610 100644 --- a/src/App.js +++ b/src/App.js @@ -1,5 +1,10 @@ import React, { useState } from "react"; -import { BrowserRouter as Router, Switch, Route } from "react-router-dom"; +import { + BrowserRouter as Router, + Switch, + Route, + Redirect +} from "react-router-dom"; import HomePage from "./pages/Home"; import MealPage from "./pages/Meal"; import SearchPage from "./pages/Search"; @@ -12,11 +17,10 @@ import Footer from "./components/Footer"; import "./index.css"; const App = () => { - // State Hooks const [searchString, setSearchString] = useState(""); const [categories, setCategories] = useState({ categories: [] }); const [searchResults, setSearchResults] = useState({ meals: [] }); - // const [isLoading, setIsLoading] = useState(true); For Preloader + // const [isLoading, setIsLoading] = useState(true); //For Preloader // Default meal object. TODO: Find a better alternative … const mealDef = { meals: [ @@ -79,7 +83,6 @@ const App = () => { }; const [meal, setMeal] = useState(mealDef); - // Fetch API functions const createURI = (keyword, option) => { const ROOT = "https://www.themealdb.com/api/json/v1/1/"; if (option === null) { @@ -100,11 +103,8 @@ const App = () => { .then(data => set(data)); }; - // Fetch wrappers for each use const getRandomMeal = () => { - // setIsLoading(true); getData("random", setMeal); - // setIsLoading(false); }; const getMeal = id => { @@ -123,6 +123,7 @@ const App = () => { const { value } = ev.target; setSearchString(value); }; + const buttonUrl = "/random"; return ( @@ -146,14 +147,14 @@ const App = () => { // isLoading={isLoading} /> - /> + - /> + { searchResults={searchResults} /> + + + + - - + + - />