Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CYF London | Rihanna Poursoltani | Module-Data-Flows | Sprint 2 | Book Library #138

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions debugging/book-library/script.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let myLibrary = [];

window.addEventListener("load", function (e) {
window.addEventListener("load", function () {
populateStorage();
render();
});
Expand Down Expand Up @@ -31,14 +31,18 @@ function submit() {
if (
title.value == null ||
title.value == "" ||
author.value == null ||
author.value == "" ||
pages.value == null ||
pages.value == ""
) {
alert("Please fill all fields!");
return false;
} else {
let book = new Book(title.value, title.value, pages.value, check.checked);
library.push(book);
//Correctly pass author.value
let book = new Book(title.value, author.value, pages.value, check.checked);
//Replace library.push(book) with myLibrary.push(book)
myLibrary.push(book);
render();
}
}
Expand All @@ -54,7 +58,7 @@ function render() {
let table = document.getElementById("display");
let rowsNumber = table.rows.length;
//delete old table
for (let n = rowsNumber - 1; n > 0; n-- {
for (let n = rowsNumber - 1; n > 0; n--) {
table.deleteRow(n);
}
//insert updated row and cells
Expand All @@ -71,30 +75,33 @@ function render() {
pagesCell.innerHTML = myLibrary[i].pages;

//add and wait for action for read/unread button
let changeBut = document.createElement("button");
changeBut.id = i;
changeBut.className = "btn btn-success";
wasReadCell.appendChild(changeBut);
let changeButton = document.createElement("button");
//changeButton.id = i;
changeButton.className = "btn btn-success";
wasReadCell.appendChild(changeButton);
let readStatus = "";
if (myLibrary[i].check == false) {
//Fix the logic for the "Read" statues true for "Yes", false for No
if (myLibrary[i].check == true) {
readStatus = "Yes";
} else {
readStatus = "No";
}
changeBut.innerText = readStatus;
changeButton.innerText = readStatus;

changeBut.addEventListener("click", function () {
changeButton.addEventListener("click", function () {
myLibrary[i].check = !myLibrary[i].check;
render();
});

//add delete button to every row and render again
// correct delButton in rows
let delButton = document.createElement("button");
delBut.id = i + 5;
deleteCell.appendChild(delBut);
delBut.className = "btn btn-warning";
delBut.innerHTML = "Delete";
delBut.addEventListener("clicks", function () {
//delButton.id = i + 5;
deleteCell.appendChild(delButton);
delButton.className = "btn btn-warning";
delButton.innerHTML = "Delete";
//Fix the event listener: "click" instead of "clicks".
delButton.addEventListener("click", function () {
alert(`You've deleted title: ${myLibrary[i].title}`);
myLibrary.splice(i, 1);
render();
Expand Down