diff --git a/source/assets/scripts/ReviewDetails.js b/source/assets/scripts/ReviewDetails.js index 32a28ea..5625849 100644 --- a/source/assets/scripts/ReviewDetails.js +++ b/source/assets/scripts/ReviewDetails.js @@ -4,6 +4,9 @@ import {deleteReviewFromStorage, getReviewFromStorage, updateReviewToStorage} fr // Run the init() function when the page has loaded window.addEventListener("DOMContentLoaded", init); +/** + * Populates the relevant data to the details from local storage review. + */ function init(){ setupInfo(); setupDelete(); @@ -51,6 +54,9 @@ function setupInfo(){ } } +/** + * Sets up delete button to delete reveiw from storage and switch to homepage. + */ function setupDelete(){ let deleteBtn = document.getElementById("delete-btn"); let currID = JSON.parse(sessionStorage.getItem("currID")); @@ -63,6 +69,9 @@ function setupDelete(){ }); } +/** + * Sets up update button to reveal form and update info in storage and the current page. + */ function setupUpdate(){ let updateBtn = document.getElementById("update-btn"); let currID = JSON.parse(sessionStorage.getItem("currID")); @@ -139,19 +148,18 @@ function setupUpdate(){ //Take formdata values as newData when submit form.addEventListener("submit", function(){ - /* - * User submits the form for their review. - * We create reviewCard and put in storage - */ + //We create reviewCard datea, replace it in in storage, and update tags let formData = new FormData(form); let newData = {}; + + // Iterate through formData an add to newData for (let [key, value] of formData) { console.log(`${key}`); console.log(`${value}`); if (`${key}` !== "tag-form") { newData[`${key}`] = `${value}`; } - //Account for the case where image is not updated + // Account for the case where image is not updated if (`${key}` === "mealImg" && document.getElementById("mealImg").value === "") { newData["mealImg"] = currReview["mealImg"]; } @@ -175,6 +183,7 @@ function setupUpdate(){ }); + // Adding tag to form functionality let tagAddBtn = document.getElementById("tag-add-btn"); tagAddBtn.addEventListener("click", ()=> { let tagField = document.getElementById("tag-form");