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} /> + + + + - - + + - /> diff --git a/src/components/Logo.js b/src/components/Logo.js index 5d3b90d..8a3076e 100644 --- a/src/components/Logo.js +++ b/src/components/Logo.js @@ -3,13 +3,13 @@ import { Link } from "react-router-dom"; const Logo = () => { return ( - + 👩🍳 Chef's - + ); }; diff --git a/src/index.css b/src/index.css index 9e0dddd..af20389 100644 --- a/src/index.css +++ b/src/index.css @@ -19,6 +19,6 @@ div { /* width: 100%; */ } -logo { +.logo { font-family: "Marck Script", cursive; } diff --git a/src/index.js b/src/index.js index 90fb3f6..ae00620 100644 --- a/src/index.js +++ b/src/index.js @@ -6,4 +6,4 @@ import * as serviceWorker from "./serviceWorker"; ReactDOM.render(, document.getElementById("root")); -serviceWorker.unregister(); +serviceWorker.register(); diff --git a/src/pages/Category.js b/src/pages/Category.js index 8f31f3f..620e8c1 100644 --- a/src/pages/Category.js +++ b/src/pages/Category.js @@ -1,6 +1,5 @@ import React, { useEffect, useState } from "react"; -import { useParams, Link, useRouteMatch } from "react-router-dom"; -import CardEntry from "../components/CardEntry"; +import { useParams, Link, Redirect } from "react-router-dom"; const CategoryPage = props => { const [meals, setMeals] = useState({ meals: [] }); @@ -15,33 +14,34 @@ const CategoryPage = props => { getMeals(); }, []); - const { url } = useRouteMatch(); - return ( Chef's {strCategory} Recipes - - - {meals.meals.map((meal, i) => ( - - {/* */} - - - - - - - - - {meal.strMeal} + {meals.meals === null ? ( + + ) : ( + + {meals.meals.map((meal, i) => ( + + {/* */} + + + + + + + + + {meal.strMeal} + - - - - ))} - + + + ))} + + )} ); }; diff --git a/src/pages/Home.js b/src/pages/Home.js index 6b8bff0..18af367 100644 --- a/src/pages/Home.js +++ b/src/pages/Home.js @@ -8,11 +8,7 @@ const HomePage = props => { The Chef's Meal Suggestions - + { - const meal = props.meal.meals[0]; const { getMeal } = props; const { idMeal } = useParams(); @@ -14,48 +13,53 @@ const MealPage = props => { idMeal === null ? getMeal() : getMeal(idMeal); }, []); - const { - strMeal, - strMealThumb, - strYoutube, - strCategory, - strArea, - strInstructions - } = meal; + if (props.meal.meals !== null) { + const meal = props.meal.meals[0]; - const item = { - mealName: strMeal, - imgAddress: strMealThumb, - videoAddress: strYoutube, - mealCategory: strCategory, - mealArea: strArea - }; + const { + strMeal, + strMealThumb, + strYoutube, + strCategory, + strArea, + strInstructions + } = meal; - let ingredientList = []; - var i; - for (i = 1; i <= 20; i++) { - var strIng = `strIngredient${i}`; - var strMes = `strMeasure${i}`; - if (meal[strIng] !== "" && meal[strIng] !== null) { - ingredientList.push([meal[strIng], meal[strMes]]); + const item = { + mealName: strMeal, + imgAddress: strMealThumb, + videoAddress: strYoutube, + mealCategory: strCategory, + mealArea: strArea + }; + + let ingredientList = []; + var i; + for (i = 1; i <= 20; i++) { + var strIng = `strIngredient${i}`; + var strMes = `strMeasure${i}`; + if (meal[strIng] !== "" && meal[strIng] !== null) { + ingredientList.push([meal[strIng], meal[strMes]]); + } } - } - // const page = - - // return isLoading ? : page; - return ( - - - - - - - - + // return isLoading ? : page; + return ( + + + + + + + + + - - ); + ); + } else { + return ; + } }; + export default MealPage; diff --git a/src/pages/Search.js b/src/pages/Search.js index 2857ed0..261900d 100644 --- a/src/pages/Search.js +++ b/src/pages/Search.js @@ -2,17 +2,24 @@ import React from "react"; import SearchResult from "../components/SearchResult"; const SearchPage = props => { - const { meals } = props.searchResults; + let { meals } = props.searchResults; const { searchString } = props; + if (meals === null) { + meals = []; + } return ( Search Results for: {searchString} - - {meals.map((meal, i) => ( - - ))} - + {meals[0] === undefined ? ( + Nothing ! Create a component to illustrate emptiness + ) : ( + + {meals.map((meal, i) => ( + + ))} + + )} ); };
Nothing ! Create a component to illustrate emptiness