-
-
Notifications
You must be signed in to change notification settings - Fork 183
ITP-2025-WM | Hatef-Eidi|Module-Data-Flows|Book-library | Sprint 2 #180
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| node_modules | ||
| **/node_modules | ||
| .DS_Store | ||
| **/.DS_Store | ||
| **/.DS_Store | ||
| .qodo |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,27 +18,36 @@ function populateStorage() { | |
| myLibrary.push(book2); | ||
| render(); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| const title = document.getElementById("title"); | ||
| const author = document.getElementById("author"); | ||
| const pages = document.getElementById("pages"); | ||
| const check = document.getElementById("check"); | ||
| console.log(title.value, author.value, pages.value, check.checked); | ||
|
|
||
| //check the right input from forms and if its ok -> add the new book (object in array) | ||
| //via Book function and start render function | ||
|
|
||
| function submit() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now author validation is added, all the fields must be containing something |
||
| if ( | ||
| title.value == null || | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. now when a book is submitted the fields are reset |
||
| title.value == "" || | ||
| pages.value == null || | ||
| pages.value == "" | ||
| pages.value == "" || | ||
| author.value == null || | ||
| author.value == "" | ||
| ) { | ||
| alert("Please fill all fields!"); | ||
| return false; | ||
| } else { | ||
| let book = new Book(title.value, title.value, pages.value, check.checked); | ||
| library.push(book); | ||
| let book = new Book(title.value, author.value, pages.value, check.checked); | ||
| myLibrary.push(book); | ||
| title.value = ""; | ||
| author.value = ""; | ||
| pages.value = ""; check.checked = false; | ||
| alert(`You've added title: ${book.title}`); | ||
| render(); | ||
| } | ||
| } | ||
|
|
@@ -50,11 +59,12 @@ function Book(title, author, pages, check) { | |
| this.check = check; | ||
| } | ||
|
|
||
|
|
||
| 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 | ||
|
|
@@ -73,14 +83,10 @@ function render() { | |
| //add and wait for action for read/unread button | ||
| let changeBut = document.createElement("button"); | ||
| changeBut.id = i; | ||
| changeBut.className = "btn btn-success"; | ||
| changeBut.className = "btn"; | ||
| changeBut.className = myLibrary[i].check ? "btn btn-success" : "btn btn-danger"; | ||
| wasReadCell.appendChild(changeBut); | ||
| let readStatus = ""; | ||
| if (myLibrary[i].check == false) { | ||
| readStatus = "Yes"; | ||
| } else { | ||
| readStatus = "No"; | ||
| } | ||
| let readStatus = myLibrary[i].check ? "Read" : "Unread"; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice to see button as red if book is marked as unread to increase UI&UX
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now added, if the book is unread it's red by adding btn-danger class to the button, Thanks for suggestion |
||
| changeBut.innerText = readStatus; | ||
|
|
||
| changeBut.addEventListener("click", function () { | ||
|
|
@@ -89,12 +95,12 @@ function render() { | |
| }); | ||
|
|
||
| //add delete button to every row and render again | ||
| let delButton = document.createElement("button"); | ||
| delBut.id = i + 5; | ||
| let delBut = document.createElement("button"); | ||
| delBut.id = i+10; | ||
| deleteCell.appendChild(delBut); | ||
| delBut.className = "btn btn-warning"; | ||
| delBut.innerHTML = "Delete"; | ||
| delBut.addEventListener("clicks", function () { | ||
| delBut.addEventListener("click", function () { | ||
| alert(`You've deleted title: ${myLibrary[i].title}`); | ||
| myLibrary.splice(i, 1); | ||
| render(); | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I accidentally approve your PR but your form submission validation needs to be fixed. That's why I'm leaving this comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No Worries, Since I completed every comment of yours I label this PR as completed