43 lines
1.1 KiB
JavaScript
Raw Normal View History

2022-11-07 19:18:05 -08:00
// main.js
import {getAllReviewsFromStorage} from "./localStorage.js";
2022-11-07 19:18:05 -08:00
// Run the init() function when the page has loaded
window.addEventListener("DOMContentLoaded", init);
2022-11-07 19:18:05 -08:00
function init() {
// Get the reviews from localStorage
let reviews = getAllReviewsFromStorage();
// Add each reviews to the <main> element
addReviewsToDocument(reviews);
// Add the event listeners to the form elements
initFormHandler();
2022-11-07 19:18:05 -08:00
}
2022-11-07 19:18:05 -08:00
/**
2022-11-08 15:57:02 -08:00
* @param {Array<Object>} reviews An array of reviews
2022-11-07 19:18:05 -08:00
*/
2022-11-08 15:57:02 -08:00
function addReviewsToDocument(reviews) {
2022-11-21 11:58:26 -08:00
let reviewBox = document.getElementById("review-container");
reviews.forEach(review => {
let newReview = document.createElement("review-card");
newReview.data = review;
//TODO: want to append it to whatever the box is in layout
2022-11-21 11:58:26 -08:00
reviewBox.append(newReview);
});
2022-11-07 19:18:05 -08:00
}
/**
2022-11-11 00:03:56 -08:00
* Adds the necessary event handlers to <form> and the clear storage
2022-11-07 19:18:05 -08:00
* <button>.
*/
function initFormHandler() {
2022-11-12 14:16:03 -08:00
//btn to create form (could be its own function?)
let createBtn = document.getElementById("create-btn");
createBtn.addEventListener("click", function(){
window.location.assign("./CreatePage.html");
});
2022-11-11 12:07:58 -08:00
}