-
-
Notifications
You must be signed in to change notification settings - Fork 231
London | 26-ITP-Jan | Angela McLeary | Sprint 2 | Book Library #415
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
base: main
Are you sure you want to change the base?
Changes from 39 commits
6fe2b67
b647506
dc2969c
6146e7f
731ac4c
377bd24
200d98c
6d570e5
ff6b347
376af2f
1d6d91b
366d541
957ce0b
b6bb86f
c87d77d
89af4d0
1a97cd5
6822947
5350f6e
9228c2f
5062215
10ae61f
ece0823
6b1fb53
380c723
820a4e1
f170475
94388ba
eb6981c
adfb8c0
d53e21d
e4c4826
e29da34
d89ea46
6fff30c
eab8a1f
851e2ce
4e49d1d
c96752d
dc383b1
2474cd9
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 |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ window.addEventListener("load", function (e) { | |
|
|
||
| function populateStorage() { | ||
| if (myLibrary.length == 0) { | ||
| let book1 = new Book("Robison Crusoe", "Daniel Defoe", "252", true); | ||
| let book1 = new Book("Robinson Crusoe", "Daniel Defoe", "252", true); | ||
| let book2 = new Book( | ||
| "The Old Man and the Sea", | ||
| "Ernest Hemingway", | ||
|
|
@@ -29,32 +29,52 @@ const check = document.getElementById("check"); | |
| //via Book function and start render function | ||
| function submit() { | ||
| if ( | ||
| title.value == null || | ||
| title.value == "" || | ||
| pages.value == null || | ||
| pages.value == "" | ||
| !title.value || | ||
| !author.value || | ||
| !pages.value || | ||
| Number(pages.value) <= 0 || | ||
| Number.isNaN(Number(pages.value)) | ||
| ) { | ||
| alert("Please fill all fields!"); | ||
| alert("Please fill all fields with valid input!"); | ||
| 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, | ||
| Number(pages.value), | ||
| check.checked | ||
| ); | ||
| myLibrary.push(book); | ||
| render(); | ||
|
|
||
| //clears the form for new entries | ||
| title.value = ""; | ||
| author.value = ""; | ||
| pages.value = ""; | ||
| check.checked = false; | ||
| } | ||
| } | ||
|
|
||
| function Book(title, author, pages, check) { | ||
| this.title = title; | ||
| this.author = author; | ||
| this.pages = pages; | ||
| this.pages = Number(pages); | ||
| this.check = check; | ||
| } | ||
| function alertDeleteToast(message) { | ||
|
cjyuan marked this conversation as resolved.
|
||
| const toast = document.getElementById("toast"); | ||
| toast.innerHTML = message; | ||
| toast.classList.add("visible"); | ||
|
|
||
| setTimeout(() => { | ||
| toast.classList.remove("visible"); | ||
| }, 4000); | ||
| } | ||
| 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 | ||
|
|
@@ -71,33 +91,31 @@ 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 readStatus = ""; | ||
| if (myLibrary[i].check == false) { | ||
| readStatus = "Yes"; | ||
| } else { | ||
| readStatus = "No"; | ||
| } | ||
| changeBut.innerText = readStatus; | ||
| let changeBtn = document.createElement("button"); | ||
| changeBtn.className = "btn btn-success"; | ||
| wasReadCell.appendChild(changeBtn); | ||
|
|
||
| changeBut.addEventListener("click", function () { | ||
| let readStatus = myLibrary[i].check ? "Yes" : "No"; | ||
| changeBtn.innerText = readStatus; | ||
|
|
||
| changeBtn.addEventListener("click", function () { | ||
| myLibrary[i].check = !myLibrary[i].check; | ||
| render(); | ||
| }); | ||
|
|
||
| //add delete button to every row and render again | ||
| let delButton = document.createElement("button"); | ||
| delBut.id = i + 5; | ||
| deleteCell.appendChild(delBut); | ||
| delBut.className = "btn btn-warning"; | ||
| delBut.innerHTML = "Delete"; | ||
| delBut.addEventListener("clicks", function () { | ||
| alert(`You've deleted title: ${myLibrary[i].title}`); | ||
| let deleteBtn = document.createElement("button"); | ||
| deleteBtn.className = "btn btn-warning"; | ||
| deleteBtn.innerHTML = "Delete"; | ||
| deleteCell.appendChild(deleteBtn); | ||
|
|
||
| deleteBtn.addEventListener("click", function () { | ||
| const deleteTitle = myLibrary[i].title; | ||
| myLibrary.splice(i, 1); | ||
| render(); | ||
| alertDeleteToast( | ||
| `You've deleted title: <br> <strong>${deleteTitle}</strong>` | ||
|
Contributor
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. Note: Since this argument is to be assigned to (No change needed)
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. Hi @cjyuan, thank you for your feedback and suggestion. I have updated the code to prevent any HTML or script injection issues. |
||
| ); | ||
| }); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,94 @@ | ||
| .jumbotron { | ||
| padding: 1.5rem 2rem; | ||
| margin-bottom: 1rem; | ||
| text-align: center; | ||
| } | ||
|
|
||
| .jumbotron h2 { | ||
| font-size: 1.5rem; | ||
| font-weight: 300; | ||
| margin-top: 0.5rem; | ||
| } | ||
|
|
||
| .form-group { | ||
| width: 400px; | ||
| height: 300px; | ||
| align-self: left; | ||
| padding-left: 20px; | ||
| padding-left: 50px; | ||
| } | ||
|
|
||
| #check { | ||
| margin-left: 0; | ||
| margin-top: 10px; | ||
| } | ||
|
|
||
| .btn { | ||
| display: block; | ||
| } | ||
|
|
||
| .form-control { | ||
| border-style: solid; | ||
| border-color: lightslategrey; | ||
| } | ||
|
|
||
| .form-check-label { | ||
| padding-left: 20px; | ||
| margin: 5px 0px 5px 0px; | ||
| } | ||
|
|
||
| button.btn-info { | ||
| margin: 20px; | ||
| .btn-info { | ||
| background-color: blue; | ||
| border-color: blue; | ||
| color: #fff; | ||
| margin: 20px 20px 20px 50px; | ||
| } | ||
|
|
||
| .btn-success { | ||
| background-color: #0d4a0d; | ||
| border-color: #0d4a0d; | ||
| color: #fff; | ||
| } | ||
|
|
||
| .btn-success:hover, | ||
| .btn-success:focus { | ||
| background-color: #1f6e1f; | ||
| border-color: #1f6e1f; | ||
| color: #fff; | ||
| } | ||
|
|
||
| .btn-warning { | ||
| background-color: #9f6000; | ||
| border-color: #9f6000; | ||
| color: #fff; | ||
| } | ||
|
|
||
| .btn-warning:hover, | ||
| .btn-warning:focus { | ||
| background-color: #b76e01; | ||
| border-color: #b76e01; | ||
| color: #fff; | ||
| } | ||
|
|
||
| /* for delete alert */ | ||
| .toast { | ||
| position: fixed; | ||
| top: 130px; | ||
| left: 50%; | ||
| font-size: 1rem; | ||
| transform: translateX(-50%); | ||
| background: #a84600; | ||
| color: white; | ||
| min-width: 300px; | ||
| width: fit-content; | ||
| white-space: normal; | ||
| word-wrap: break-word; | ||
| text-align: center; | ||
| padding: 10px 15px; | ||
| border-radius: 5px; | ||
| opacity: 0; | ||
| transition: opacity 0.3s ease; | ||
| pointer-events: none; | ||
| } | ||
|
|
||
| .toast.visible { | ||
| opacity: 1; | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.