mirror of
https://github.com/array-in-a-matrix/foodie.git
synced 2024-06-16 03:17:02 -04:00
unbookmark written
This commit is contained in:
parent
a2029c85d4
commit
0f401a8fe2
|
@ -13,6 +13,8 @@ function Bookmark() {
|
|||
|
||||
let recipeList = [];
|
||||
for (let i = 0; i < loadedRecipe.length; i++) {
|
||||
console.log("bookmark", loadedRecipe[i].isBookmarked)
|
||||
if(loadedRecipe[i].isBookmarked == true){
|
||||
recipeList.push(
|
||||
<div className="d-flex card" key={i} style={{ margin: '2% 3%', flexDirection: "row", alignItems: "center", padding: "1% 5%" }} >
|
||||
<Link to="/" onClick={() => changeCurRecipe(i)}>
|
||||
|
@ -25,7 +27,7 @@ function Bookmark() {
|
|||
<p style={{ fontSize: "80%", fontFamily: 'Archivo', }} >{loadedRecipe[i].description}</p> {/* //? small description of the recipe */}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
);}
|
||||
}
|
||||
return <section>
|
||||
<h1 style={{margin: "5% 0 5% 5%"}} >Bookmark recipes</h1>
|
||||
|
|
|
@ -5,6 +5,7 @@ const RecipeList = createContext({
|
|||
curRecipe: 0,
|
||||
changeRecipe: (recipe) => {},
|
||||
bookmarkRecipe: () => {},
|
||||
unbookmarkRecipe: () => {}
|
||||
});
|
||||
|
||||
export function RecipeListProvider(props) {
|
||||
|
@ -46,6 +47,33 @@ export function RecipeListProvider(props) {
|
|||
});
|
||||
}
|
||||
|
||||
function unbookmarkCurRecipe() {
|
||||
console.log(
|
||||
"bookmarkCurRecipe",
|
||||
"https://htv7-96f00-default-rtdb.firebaseio.com/recipe/" +
|
||||
loadedRecipe[curNum].id +
|
||||
".json"
|
||||
);
|
||||
|
||||
fetch(
|
||||
"https://htv7-96f00-default-rtdb.firebaseio.com/recipe/" +
|
||||
loadedRecipe[curNum].id +
|
||||
".json",
|
||||
{
|
||||
method: "PATCH",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ isBookmarked: false }),
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
console.log("response", response);
|
||||
return response.json();
|
||||
})
|
||||
.then((data) => {
|
||||
setIsLoading(false);
|
||||
});
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
setIsLoading(true);
|
||||
fetch("https://htv7-96f00-default-rtdb.firebaseio.com/recipe.json")
|
||||
|
@ -81,6 +109,7 @@ export function RecipeListProvider(props) {
|
|||
curRecipe: curNum,
|
||||
changeRecipe: changeCurRecipe,
|
||||
bookmarkRecipe: bookmarkCurRecipe,
|
||||
unbookmarkRecipe: unbookmarkCurRecipe
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
Loading…
Reference in a new issue