diff --git a/README.md b/README.md index a75202e..550b8d5 100644 --- a/README.md +++ b/README.md @@ -87,4 +87,3 @@ Free meal planner for cooks short on ideas! (like me …) - Use ErrorBoundaries component ? - add sidenav on mobile - contact form -- override Router with scoll to top function diff --git a/public/manifest.json b/public/manifest.json index b6e857e..96a6f51 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -25,6 +25,6 @@ ], "start_url": "/", "display": "standalone", - "theme_color": "#000000", + "theme_color": "#ee6e73", "background_color": "#ffffff" } \ No newline at end of file diff --git a/src/App.js b/src/App.js index 14296d0..99a960e 100644 --- a/src/App.js +++ b/src/App.js @@ -1,41 +1,37 @@ import React, { useState } from "react"; -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"; -import CategoryListPage from "./pages/CategoryList"; -import CategoryPage from "./pages/Category"; -import NotFound from "./pages/NotFound"; -import Navbar from "./components/Navbar"; -import SearchBar from "./components/SearchBar"; -import Footer from "./components/Footer"; +import { Router } from "./utils/router"; +import { Switch, Route, Redirect } from "react-router-dom"; +import { HomePage } from "./pages/Home"; +import { MealPage } from "./pages/Meal"; +import { SearchPage } from "./pages/Search"; +import { CategoryListPage } from "./pages/CategoryList"; +import { CategoryPage } from "./pages/Category"; +import { NotFoundPage } from "./pages/NotFound"; +import { Navbar } from "./components/Navbar"; +import { SearchBar } from "./components/SearchBar"; +import { Footer } from "./components/Footer"; import "./index.css"; +import { getData } from "./utils/methods"; -const App = () => { +export const App = () => { const [searchString, setSearchString] = useState(""); const [categories, setCategories] = useState({ categories: [] }); const [searchResults, setSearchResults] = useState({ meals: [] }); - // const [isLoading, setIsLoading] = useState(true); //For Preloader // Default meal object. TODO: Find a better alternative … const mealDef = { meals: [ { idMeal: "52837", - strMeal: "Pilchard puttanesca", + strMeal: "Chef's meal", strDrinkAlternate: null, - strCategory: "Pasta", - strArea: "Italian", + strCategory: "yummy", + strArea: "Mine", strInstructions: "Cook the pasta following pack instructions.\r\n\r\nHeat the oil in a non-stick frying pan and cook the onion, garlic and chilli for 3-4 mins to soften. Stir in the tomato pur\u00e9e and cook for 1 min, then add the pilchards with their sauce. Cook, breaking up the fish with a wooden spoon, then add the olives and continue to cook for a few more mins.\r\n\r\nDrain the pasta and add to the pan with 2-3 tbsp of the cooking water. Toss everything together well, then divide between plates and serve, scattered with Parmesan.", - strMealThumb: - "https://www.themealdb.com/images/media/meals/vvtvtr1511180578.jpg", + strMealThumb: require("./images/breakfast.svg"), + // "https://www.themealdb.com/images/media/meals/vvtvtr1511180578.jpg", strTags: null, - strYoutube: "https://www.youtube.com/watch?v=wqZzLAPmr9k", + strYoutube: "#", strIngredient1: "Spaghetti", strIngredient2: "Olive Oil", strIngredient3: "Onion", @@ -83,26 +79,6 @@ const App = () => { }; const [meal, setMeal] = useState(mealDef); - const createURI = (keyword, option) => { - const ROOT = "https://www.themealdb.com/api/json/v1/1/"; - if (option === null) { - return `${ROOT}${keyword}.php`; - } else if (option === "filter") { - return `${ROOT}${option}.php?c=${keyword}`; - } else if (option === "lookup") { - return `${ROOT}${option}.php?i=${keyword}`; - } else if (option === "search") { - return `${ROOT}${option}.php?s=${keyword}`; - } - }; - - const getData = (keyword, set, option = null) => { - const URI = createURI(keyword, option); - fetch(URI) - .then(response => response.json()) - .then(data => set(data)); - }; - const getRandomMeal = () => { getData("random", setMeal); }; @@ -129,32 +105,24 @@ const App = () => { return ( -
- -
+ - + - - { /> - + @@ -183,5 +151,3 @@ const App = () => {
); }; - -export default App; diff --git a/src/components/CardEntry.js b/src/components/CardEntry.js index cf58434..ef9739d 100644 --- a/src/components/CardEntry.js +++ b/src/components/CardEntry.js @@ -1,7 +1,7 @@ import React from "react"; import { Link } from "react-router-dom"; -const CardEntry = props => { +export const CardEntry = props => { const { idMeal, strMeal, strMealThumb } = props.item; return ( @@ -22,4 +22,3 @@ const CardEntry = props => { ); }; -export default CardEntry; diff --git a/src/components/CategoryEntry.js b/src/components/CategoryEntry.js index 128e14c..c506fa7 100644 --- a/src/components/CategoryEntry.js +++ b/src/components/CategoryEntry.js @@ -12,7 +12,7 @@ const CategoryEntry = props => { return ( // - +
  • diff --git a/src/components/CopyrightText.js b/src/components/CopyrightText.js index aa411ba..dcc57ba 100644 --- a/src/components/CopyrightText.js +++ b/src/components/CopyrightText.js @@ -1,6 +1,6 @@ import React from "react"; -const CopyrightText = () => { +export const CopyrightText = () => { return ( © 2020 - Chef's - Made with{" "} @@ -10,5 +10,3 @@ const CopyrightText = () => { ); }; - -export default CopyrightText; diff --git a/src/components/Footer.js b/src/components/Footer.js index 1f391c6..3cb4e33 100644 --- a/src/components/Footer.js +++ b/src/components/Footer.js @@ -1,8 +1,8 @@ import React from "react"; -import CopyrightText from "./CopyrightText"; -import GitHubLink from "./GitHubLink"; +import { CopyrightText } from "./CopyrightText"; +import { GitHubLink } from "./GitHubLink"; -const Footer = () => { +export const Footer = () => { return (
    @@ -14,5 +14,3 @@ const Footer = () => {
    ); }; - -export default Footer; diff --git a/src/components/GitHubLink.js b/src/components/GitHubLink.js index 5cacd9d..084babd 100644 --- a/src/components/GitHubLink.js +++ b/src/components/GitHubLink.js @@ -1,6 +1,6 @@ import React from "react"; -const GitHubLink = () => { +export const GitHubLink = () => { return ( { ); }; - -export default GitHubLink; diff --git a/src/components/IngredientList.js b/src/components/IngredientList.js index 13420ac..7101acb 100644 --- a/src/components/IngredientList.js +++ b/src/components/IngredientList.js @@ -1,6 +1,6 @@ import React from "react"; -const IngredientList = props => { +export const IngredientList = props => { const { ingredients } = props; return (
    @@ -15,4 +15,3 @@ const IngredientList = props => {
    ); }; -export default IngredientList; diff --git a/src/components/Logo.js b/src/components/Logo.js index 8a3076e..d7bf2ea 100644 --- a/src/components/Logo.js +++ b/src/components/Logo.js @@ -1,7 +1,7 @@ import React from "react"; import { Link } from "react-router-dom"; -const Logo = () => { +export const Logo = () => { return (
    @@ -12,5 +12,3 @@ const Logo = () => {
    ); }; - -export default Logo; diff --git a/src/components/MealPresentation.js b/src/components/MealPresentation.js index 414defc..c733444 100644 --- a/src/components/MealPresentation.js +++ b/src/components/MealPresentation.js @@ -1,7 +1,7 @@ import React from "react"; import { Link } from "react-router-dom"; -const MealPresentation = props => { +export const MealPresentation = props => { const { mealName, imgAddress, @@ -53,4 +53,3 @@ const MealPresentation = props => {
    ); }; -export default MealPresentation; diff --git a/src/components/Navbar.js b/src/components/Navbar.js index f6ff619..d1e87fa 100644 --- a/src/components/Navbar.js +++ b/src/components/Navbar.js @@ -1,10 +1,10 @@ import React from "react"; -import Logo from "./Logo"; +import { Logo } from "./Logo"; -import RandomButton from "./RandomButton"; +import { RandomButton } from "./RandomButton"; import { Link } from "react-router-dom"; -const Navbar = props => { +export const Navbar = props => { return (
    ); }; - -export default Navbar; diff --git a/src/components/PreLoader.js b/src/components/PreLoader.js index d77866e..d50f257 100644 --- a/src/components/PreLoader.js +++ b/src/components/PreLoader.js @@ -1,6 +1,6 @@ import React from "react"; -const PreLoader = () => { +export const PreLoader = () => { return (
    @@ -17,5 +17,3 @@ const PreLoader = () => {
    ); }; - -export default PreLoader; diff --git a/src/components/RandomButton.js b/src/components/RandomButton.js index 1edc0a0..28d3b5a 100644 --- a/src/components/RandomButton.js +++ b/src/components/RandomButton.js @@ -1,7 +1,7 @@ import React from "react"; import { Link } from "react-router-dom"; -const RandomButton = props => { +export const RandomButton = props => { const classString = `waves-effect waves-light btn-${props.size}`; return ( @@ -15,5 +15,3 @@ const RandomButton = props => { ); }; - -export default RandomButton; diff --git a/src/components/Recipe.js b/src/components/Recipe.js index 5a64836..4447780 100644 --- a/src/components/Recipe.js +++ b/src/components/Recipe.js @@ -1,6 +1,6 @@ import React from "react"; -const Recipe = props => { +export const Recipe = props => { return (

    Instructions

    @@ -8,4 +8,3 @@ const Recipe = props => {
    ); }; -export default Recipe; diff --git a/src/components/SearchBar.js b/src/components/SearchBar.js index e697a0c..8474380 100644 --- a/src/components/SearchBar.js +++ b/src/components/SearchBar.js @@ -1,31 +1,32 @@ import React from "react"; import { Link } from "react-router-dom"; -const SearchBar = props => { +export const SearchBar = props => { return ( -
    -
    - - - - -
    +
    +
    +
    + + + + +
    +
    ); }; -export default SearchBar; diff --git a/src/components/SearchResult.js b/src/components/SearchResult.js index 2b98eb7..330422e 100644 --- a/src/components/SearchResult.js +++ b/src/components/SearchResult.js @@ -1,9 +1,7 @@ import React from "react"; -import CardEntry from "./CardEntry"; +import { CardEntry } from "./CardEntry"; -const SearchResult = props => { +export const SearchResult = props => { const { meal } = props; return ; }; - -export default SearchResult; diff --git a/src/images/parallax1.jpg b/src/images/parallax1.jpg deleted file mode 100644 index bbc8bb2..0000000 Binary files a/src/images/parallax1.jpg and /dev/null differ diff --git a/src/images/parallax2.jpg b/src/images/parallax2.jpg deleted file mode 100644 index 071d649..0000000 Binary files a/src/images/parallax2.jpg and /dev/null differ diff --git a/src/index.js b/src/index.js index ae00620..1747bb3 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,7 @@ import React from "react"; import ReactDOM from "react-dom"; import "./index.css"; -import App from "./App"; +import { App } from "./App"; import * as serviceWorker from "./serviceWorker"; ReactDOM.render(, document.getElementById("root")); diff --git a/src/pages/Category.js b/src/pages/Category.js index 620e8c1..1db0c8c 100644 --- a/src/pages/Category.js +++ b/src/pages/Category.js @@ -1,7 +1,7 @@ import React, { useEffect, useState } from "react"; import { useParams, Link, Redirect } from "react-router-dom"; -const CategoryPage = props => { +export const CategoryPage = props => { const [meals, setMeals] = useState({ meals: [] }); const { getData } = props; const { strCategory } = useParams(); @@ -24,7 +24,7 @@ const CategoryPage = props => { {meals.meals.map((meal, i) => (
  • {/* */} - +
    @@ -45,4 +45,3 @@ const CategoryPage = props => {
    ); }; -export default CategoryPage; diff --git a/src/pages/CategoryList.js b/src/pages/CategoryList.js index 9970864..bc2cc59 100644 --- a/src/pages/CategoryList.js +++ b/src/pages/CategoryList.js @@ -1,7 +1,7 @@ import React, { useEffect } from "react"; import CategoryEntry from "../components/CategoryEntry"; -const CategoryListPage = props => { +export const CategoryListPage = props => { const { categories } = props.categories; const { getCategories } = props; @@ -22,5 +22,3 @@ const CategoryListPage = props => {
    ); }; - -export default CategoryListPage; diff --git a/src/pages/Home.js b/src/pages/Home.js index 18af367..4be5739 100644 --- a/src/pages/Home.js +++ b/src/pages/Home.js @@ -1,7 +1,7 @@ import React from "react"; -import RandomButton from "../components/RandomButton"; +import { RandomButton } from "../components/RandomButton"; -const HomePage = props => { +export const HomePage = props => { return (
    @@ -12,10 +12,7 @@ const HomePage = props => {
    hero_image @@ -25,5 +22,3 @@ const HomePage = props => {
    ); }; - -export default HomePage; diff --git a/src/pages/Meal.js b/src/pages/Meal.js index d028a10..46991be 100644 --- a/src/pages/Meal.js +++ b/src/pages/Meal.js @@ -1,11 +1,10 @@ import React, { useEffect } from "react"; -import MealPresentation from "../components/MealPresentation"; -import IngredientList from "../components/IngredientList"; -import Recipe from "../components/Recipe"; +import { MealPresentation } from "../components/MealPresentation"; +import { IngredientList } from "../components/IngredientList"; +import { Recipe } from "../components/Recipe"; import { useParams, Redirect } from "react-router-dom"; -// import PreLoader from "../components/PreLoader"; -const MealPage = props => { +export const MealPage = props => { const { getMeal } = props; const { idMeal } = useParams(); @@ -43,7 +42,6 @@ const MealPage = props => { } } - // return isLoading ? : page; return (
    @@ -61,5 +59,3 @@ const MealPage = props => { return ; } }; - -export default MealPage; diff --git a/src/pages/NotFound.js b/src/pages/NotFound.js index 5a07247..098c6c3 100644 --- a/src/pages/NotFound.js +++ b/src/pages/NotFound.js @@ -1,7 +1,7 @@ import React from "react"; -import RandomButton from "../components/RandomButton"; +import { RandomButton } from "../components/RandomButton"; -const NotFoundPage = props => { +export const NotFoundPage = props => { return (
    @@ -17,5 +17,3 @@ const NotFoundPage = props => {
    ); }; - -export default NotFoundPage; diff --git a/src/pages/Search.js b/src/pages/Search.js index 261900d..e816f6f 100644 --- a/src/pages/Search.js +++ b/src/pages/Search.js @@ -1,7 +1,7 @@ import React from "react"; -import SearchResult from "../components/SearchResult"; +import { SearchResult } from "../components/SearchResult"; -const SearchPage = props => { +export const SearchPage = props => { let { meals } = props.searchResults; const { searchString } = props; if (meals === null) { @@ -12,7 +12,17 @@ const SearchPage = props => {

    Search Results for: {searchString}

    {meals[0] === undefined ? ( -

    Nothing ! Create a component to illustrate emptiness

    +
    +

    + No results to display, instead there is a picture of my breakfast. +

    + Nothing here! +

    +
    ) : (
      {meals.map((meal, i) => ( @@ -23,4 +33,3 @@ const SearchPage = props => {
    ); }; -export default SearchPage; diff --git a/src/utils/methods.js b/src/utils/methods.js new file mode 100644 index 0000000..710a97d --- /dev/null +++ b/src/utils/methods.js @@ -0,0 +1,19 @@ +export const createURI = (keyword, option) => { + const ROOT = "https://www.themealdb.com/api/json/v1/1/"; + if (option === null) { + return `${ROOT}${keyword}.php`; + } else if (option === "filter") { + return `${ROOT}${option}.php?c=${keyword}`; + } else if (option === "lookup") { + return `${ROOT}${option}.php?i=${keyword}`; + } else if (option === "search") { + return `${ROOT}${option}.php?s=${keyword}`; + } +}; + +export const getData = (keyword, set, option = null) => { + const URI = createURI(keyword, option); + fetch(URI) + .then(response => response.json()) + .then(data => set(data)); +}; diff --git a/src/utils/router.js b/src/utils/router.js new file mode 100644 index 0000000..c6ce817 --- /dev/null +++ b/src/utils/router.js @@ -0,0 +1,51 @@ +import React, { useMemo, useEffect } from "react"; +import { + Router as RouterOriginal, + useParams, + useLocation, + useHistory, + useRouteMatch +} from "react-router-dom"; +import queryString from "query-string"; + +import { createBrowserHistory } from "history"; +export const history = createBrowserHistory(); + +export const Router = ({ children }) => { + return ( + + + {children} + + ); +}; + +export const ScrollToTop = () => { + const location = useLocation(); + useEffect(() => { + window.scrollTo(0, 0); + }, [location.pathname]); + return null; +}; + +export const useRouter = () => { + const params = useParams(); + const location = useLocation(); + const history = useHistory(); + const match = useRouteMatch(); + + return useMemo(() => { + return { + push: history.push, + replace: history.replace, + pathname: location.pathname, + query: { + ...queryString.parse(location.search), + ...params + }, + match, + location, + history + }; + }, [params, match, location, history]); +};