Documentation for ReviewDetails.js

This commit is contained in:
rheabhutada02 2022-11-29 16:13:58 -08:00
parent ea41495e49
commit 58e4f6fdeb

View File

@ -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");