From 3422f584f98dc9f6f74786a261a7ef0c1a0f537d Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Fri, 18 Nov 2022 07:56:07 +0000 Subject: [PATCH] fix linting in js --- source/assets/scripts/CreatePage.js | 8 ++++---- source/assets/scripts/ReviewCard.js | 18 +++++++++--------- source/assets/scripts/ReviewDetails.js | 2 +- source/assets/scripts/localStorage.js | 6 +++--- source/assets/scripts/localStorage.test.js | 6 +++--- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/source/assets/scripts/CreatePage.js b/source/assets/scripts/CreatePage.js index fca6dc5..c5c641f 100644 --- a/source/assets/scripts/CreatePage.js +++ b/source/assets/scripts/CreatePage.js @@ -3,10 +3,10 @@ import { newReviewToStorage } from "./localStorage.js"; window.addEventListener("DOMContentLoaded", init); function init() { - // get next id + // get next id - // creates the key - initFormHandler(); + // creates the key + initFormHandler(); } @@ -42,7 +42,7 @@ function initFormHandler() { let nextReviewId = newReviewToStorage(reviewObject); sessionStorage.setItem("currID", JSON.stringify(nextReviewId)); - window.location.assign('./ReviewDetails.html'); + window.location.assign("./ReviewDetails.html"); }); diff --git a/source/assets/scripts/ReviewCard.js b/source/assets/scripts/ReviewCard.js index d7bd1ce..70a0660 100644 --- a/source/assets/scripts/ReviewCard.js +++ b/source/assets/scripts/ReviewCard.js @@ -132,18 +132,18 @@ class ReviewCard extends HTMLElement { let articleEl = this.shadowEl.querySelector("article"); // setting the article elements for the review card - this.reviewID = data["reviewID"]; + this.reviewID = data["reviewID"]; //image setup let mealImg = document.createElement("img"); mealImg.setAttribute("id", "a-mealImg"); mealImg.setAttribute("alt",data["imgAlt"]); - if(data["mealImg"] != ""){ - mealImg.setAttribute("src",data["mealImg"]); - } - else{ - mealImg.setAttribute("src", "./assets/images/icons/plate_with_cutlery.png"); - } + if(data["mealImg"] != ""){ + mealImg.setAttribute("src",data["mealImg"]); + } + else{ + mealImg.setAttribute("src", "./assets/images/icons/plate_with_cutlery.png"); + } //meal name setup let mealLabel = document.createElement("label"); @@ -187,7 +187,7 @@ class ReviewCard extends HTMLElement { } } - //adding final ID to data! + //adding final ID to data! articleEl.append(mealImg); articleEl.append(mealLabel); @@ -223,7 +223,7 @@ class ReviewCard extends HTMLElement { let dataContainer = {}; // getting the article elements for the review card - dataContainer["reviewID"] = this.reviewID; + dataContainer["reviewID"] = this.reviewID; //get image let mealImg = this.shadowEl.getElementById("a-mealImg"); diff --git a/source/assets/scripts/ReviewDetails.js b/source/assets/scripts/ReviewDetails.js index f2545fa..b07282b 100644 --- a/source/assets/scripts/ReviewDetails.js +++ b/source/assets/scripts/ReviewDetails.js @@ -15,7 +15,7 @@ function setupDelete(){ deleteBtn.addEventListener("click", function(){ if(window.confirm("Are you sure you want to delete this entry?")){ deleteReviewFromStorage(currID); - sessionStorage.removeItem('currID'); + sessionStorage.removeItem("currID"); window.location.assign("./index.html"); } }); diff --git a/source/assets/scripts/localStorage.js b/source/assets/scripts/localStorage.js index 62b834d..20be650 100644 --- a/source/assets/scripts/localStorage.js +++ b/source/assets/scripts/localStorage.js @@ -52,8 +52,8 @@ export function deleteReviewFromStorage(ID){ for (let i in activeIDS) { if (activeIDS[i] == ID) { activeIDS.splice(i,1); - localStorage.setItem('activeIDS', JSON.stringify(activeIDS)); - localStorage.removeItem(`review${ID}`) + localStorage.setItem("activeIDS", JSON.stringify(activeIDS)); + localStorage.removeItem(`review${ID}`); return; } } @@ -70,7 +70,7 @@ export function getAllReviewsFromStorage() { } //iterate thru activeIDS let activeIDS = JSON.parse(localStorage.getItem("activeIDS")); - let reviews = [] + let reviews = []; for (let i = 0; i < activeIDS.length; i++) { let currReview = JSON.parse(localStorage.getItem(`review${activeIDS[i]}`)); reviews.push(currReview); diff --git a/source/assets/scripts/localStorage.test.js b/source/assets/scripts/localStorage.test.js index 94730d1..0ed85c4 100644 --- a/source/assets/scripts/localStorage.test.js +++ b/source/assets/scripts/localStorage.test.js @@ -1,5 +1,5 @@ import {strict as assert} from "node:assert"; -import {describe, it, beforeEach} from "mocha"; +import {describe, it, before, after} from "mocha"; import {newReviewToStorage, getReviewFromStorage, updateReviewToStorage, deleteReviewFromStorage, getAllReviewsFromStorage} from "./localStorage.js"; describe("test app localStorage interaction", () => { @@ -49,7 +49,7 @@ describe("test app localStorage interaction", () => { "restaurant": `sample restaurant ${i}`, "rating": i, "tags": [`tag ${3*i}`, `tag ${3*i + 1}`, `tag ${3*i + 2}`] - } + }; newReviewToStorage(new_review); @@ -75,7 +75,7 @@ describe("test app localStorage interaction", () => { "restaurant": `updated sample restaurant ${i}`, "rating": i*2+i, "tags": [`tag ${3*i}`, `tag ${3*i + 1}`, `tag ${3*i + 2}`] - } + }; new_review.reviewID = i; reviews[i] = new_review;