mirror of
https://github.com/rjNemo/meal_planner
synced 2026-06-12 13:26:45 +00:00
Fav Button
This commit is contained in:
parent
c20a7330c8
commit
f4833c4214
4 changed files with 39 additions and 4 deletions
|
|
@ -96,7 +96,8 @@ Free meal planner for cooks short on ideas! (like me …)
|
||||||
## TO DO
|
## TO DO
|
||||||
|
|
||||||
1. send message after contact form validation (confirm to sender and msg+info to admin)
|
1. send message after contact form validation (confirm to sender and msg+info to admin)
|
||||||
1. Design & Breadcrumb
|
1. Local storage of prefeernces
|
||||||
|
1. Breadcrumb
|
||||||
1. Cookie bar
|
1. Cookie bar
|
||||||
1. code cleanup (props and refactoring)
|
1. code cleanup (props and refactoring)
|
||||||
1. Back to top button
|
1. Back to top button
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,9 @@ export const MealPresentation = props => {
|
||||||
imgAddress,
|
imgAddress,
|
||||||
videoAddress,
|
videoAddress,
|
||||||
mealCategory,
|
mealCategory,
|
||||||
mealArea
|
mealArea,
|
||||||
|
isFav,
|
||||||
|
setIsFav
|
||||||
} = props.meal;
|
} = props.meal;
|
||||||
return (
|
return (
|
||||||
<div className="row">
|
<div className="row">
|
||||||
|
|
@ -38,7 +40,22 @@ export const MealPresentation = props => {
|
||||||
<div className="chip">
|
<div className="chip">
|
||||||
<b>Origin:</b> {mealArea}
|
<b>Origin:</b> {mealArea}
|
||||||
</div>
|
</div>
|
||||||
|
<div className="chip">
|
||||||
|
<b>
|
||||||
|
{isFav ? "Remove from favourites" : "Add to favourites"}:
|
||||||
|
</b>
|
||||||
|
|
||||||
|
<Link to="#">
|
||||||
|
<i
|
||||||
|
className="close material-icons"
|
||||||
|
onClick={() => setIsFav(!isFav)}
|
||||||
|
>
|
||||||
|
{isFav ? "favorite" : "favorite_border"}
|
||||||
|
</i>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
</li>
|
</li>
|
||||||
|
<li></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { useEffect } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import { MealPage } from "../pages/MealPage";
|
import { MealPage } from "../pages/MealPage";
|
||||||
import { NotFoundPage } from "../pages/NotFoundPage";
|
import { NotFoundPage } from "../pages/NotFoundPage";
|
||||||
|
|
@ -22,12 +22,27 @@ export const MealController = ({ meal, getMeal, getRandomMeal }) => {
|
||||||
strInstructions
|
strInstructions
|
||||||
} = mealItem;
|
} = mealItem;
|
||||||
|
|
||||||
|
const favInit = Boolean(localStorage.getItem(strMeal));
|
||||||
|
// console.log(favInit);
|
||||||
|
const [isFav, setIsFav] = useState(favInit);
|
||||||
|
// console.log(isFav);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
isFav
|
||||||
|
? localStorage.setItem(strMeal, isFav)
|
||||||
|
: localStorage.setItem(strMeal, "");
|
||||||
|
console.log(localStorage.getItem(strMeal));
|
||||||
|
console.log(isFav);
|
||||||
|
}, [isFav, strMeal]);
|
||||||
|
|
||||||
const item = {
|
const item = {
|
||||||
mealName: strMeal,
|
mealName: strMeal,
|
||||||
imgAddress: strMealThumb,
|
imgAddress: strMealThumb,
|
||||||
videoAddress: strYoutube,
|
videoAddress: strYoutube,
|
||||||
mealCategory: strCategory,
|
mealCategory: strCategory,
|
||||||
mealArea: strArea
|
mealArea: strArea,
|
||||||
|
isFav: isFav,
|
||||||
|
setIsFav: setIsFav
|
||||||
};
|
};
|
||||||
|
|
||||||
let ingredientList = [];
|
let ingredientList = [];
|
||||||
|
|
|
||||||
|
|
@ -22,3 +22,5 @@ export const getData = (keyword, set, option = null) => {
|
||||||
export const upFirstChar = lower => {
|
export const upFirstChar = lower => {
|
||||||
return lower.replace(/^\w/, c => c.toUpperCase());
|
return lower.replace(/^\w/, c => c.toUpperCase());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const addToFavourites = () => {};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue