mirror of
https://github.com/cse110-fa22-group29/cse110-fa22-group29.git
synced 2024-12-27 09:29:10 +00:00
Documentation for ReviewDetails.js
This commit is contained in:
parent
ea41495e49
commit
58e4f6fdeb
@ -4,6 +4,9 @@ import {deleteReviewFromStorage, getReviewFromStorage, updateReviewToStorage} fr
|
|||||||
// Run the init() function when the page has loaded
|
// Run the init() function when the page has loaded
|
||||||
window.addEventListener("DOMContentLoaded", init);
|
window.addEventListener("DOMContentLoaded", init);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Populates the relevant data to the details from local storage review.
|
||||||
|
*/
|
||||||
function init(){
|
function init(){
|
||||||
setupInfo();
|
setupInfo();
|
||||||
setupDelete();
|
setupDelete();
|
||||||
@ -51,6 +54,9 @@ function setupInfo(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets up delete button to delete reveiw from storage and switch to homepage.
|
||||||
|
*/
|
||||||
function setupDelete(){
|
function setupDelete(){
|
||||||
let deleteBtn = document.getElementById("delete-btn");
|
let deleteBtn = document.getElementById("delete-btn");
|
||||||
let currID = JSON.parse(sessionStorage.getItem("currID"));
|
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(){
|
function setupUpdate(){
|
||||||
let updateBtn = document.getElementById("update-btn");
|
let updateBtn = document.getElementById("update-btn");
|
||||||
let currID = JSON.parse(sessionStorage.getItem("currID"));
|
let currID = JSON.parse(sessionStorage.getItem("currID"));
|
||||||
@ -139,19 +148,18 @@ function setupUpdate(){
|
|||||||
|
|
||||||
//Take formdata values as newData when submit
|
//Take formdata values as newData when submit
|
||||||
form.addEventListener("submit", function(){
|
form.addEventListener("submit", function(){
|
||||||
/*
|
//We create reviewCard datea, replace it in in storage, and update tags
|
||||||
* User submits the form for their review.
|
|
||||||
* We create reviewCard and put in storage
|
|
||||||
*/
|
|
||||||
let formData = new FormData(form);
|
let formData = new FormData(form);
|
||||||
let newData = {};
|
let newData = {};
|
||||||
|
|
||||||
|
// Iterate through formData an add to newData
|
||||||
for (let [key, value] of formData) {
|
for (let [key, value] of formData) {
|
||||||
console.log(`${key}`);
|
console.log(`${key}`);
|
||||||
console.log(`${value}`);
|
console.log(`${value}`);
|
||||||
if (`${key}` !== "tag-form") {
|
if (`${key}` !== "tag-form") {
|
||||||
newData[`${key}`] = `${value}`;
|
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 === "") {
|
if (`${key}` === "mealImg" && document.getElementById("mealImg").value === "") {
|
||||||
newData["mealImg"] = currReview["mealImg"];
|
newData["mealImg"] = currReview["mealImg"];
|
||||||
}
|
}
|
||||||
@ -175,6 +183,7 @@ function setupUpdate(){
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Adding tag to form functionality
|
||||||
let tagAddBtn = document.getElementById("tag-add-btn");
|
let tagAddBtn = document.getElementById("tag-add-btn");
|
||||||
tagAddBtn.addEventListener("click", ()=> {
|
tagAddBtn.addEventListener("click", ()=> {
|
||||||
let tagField = document.getElementById("tag-form");
|
let tagField = document.getElementById("tag-form");
|
||||||
|
Loading…
Reference in New Issue
Block a user