-
-
Notifications
You must be signed in to change notification settings - Fork 234
Sheffield | 26-ITP-jan | Martha Ogunbiyi | Sprint 2 | Book Library #447
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
Open
marthak1
wants to merge
19
commits into
CodeYourFuture:main
Choose a base branch
from
marthak1:feature/book-library
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
d7e7b4c
fix error in render function for loo closing missing closing bracket
marthak1 11e500e
update delete button
marthak1 de9d89d
update add book function and inputs
marthak1 3dadc55
fixed delete button
marthak1 9fb77a9
removed unused comment
marthak1 da350c1
unco changes in html
marthak1 2132c95
removed unused comment
marthak1 856dff7
validate html code
marthak1 341fded
refactor page count with number type and update element variable names
marthak1 2a37c41
refactor submit function by using logical NOT to validate input
marthak1 3ba292d
add html input validation
marthak1 fa04d30
add efficient approach to remove rows in table, add delete all button…
marthak1 fc525ce
add form validation in js
marthak1 da4c5db
Delete .vscode/settings.json
marthak1 b7cf828
Refactor element retrieval and library initialization
marthak1 79887c0
Remove IDs from buttons in book library
marthak1 a92aab7
Refactor table row clearing in render function
marthak1 5cdb0e0
removed bracket
marthak1 9ddeb45
Fix row insertion to use tableBody instead of table
marthak1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| let myLibrary = []; | ||
|
|
||
| window.addEventListener("load", function (e) { | ||
| populateStorage(); | ||
| render(); | ||
|
|
@@ -16,14 +15,19 @@ function populateStorage() { | |
| ); | ||
| myLibrary.push(book1); | ||
| myLibrary.push(book2); | ||
| render(); | ||
| } | ||
| } | ||
|
|
||
| const title = document.getElementById("title"); | ||
| const author = document.getElementById("author"); | ||
| const pages = document.getElementById("pages"); | ||
| const check = document.getElementById("check"); | ||
| const submitBtn = document.getElementById("submit-btn"); | ||
|
|
||
| submitBtn.addEventListener("click", function (event) { | ||
| event.preventDefault(); | ||
| submit(); | ||
| }); | ||
|
|
||
| //check the right input from forms and if its ok -> add the new book (object in array) | ||
| //via Book function and start render function | ||
|
|
@@ -37,8 +41,8 @@ function submit() { | |
| 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); | ||
| render(); | ||
| } | ||
| } | ||
|
|
@@ -54,9 +58,9 @@ 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 | ||
| let length = myLibrary.length; | ||
| for (let i = 0; i < length; i++) { | ||
|
|
@@ -77,9 +81,9 @@ function render() { | |
| wasReadCell.appendChild(changeBut); | ||
| let readStatus = ""; | ||
| if (myLibrary[i].check == false) { | ||
| readStatus = "Yes"; | ||
| } else { | ||
| readStatus = "No"; | ||
| } else { | ||
| readStatus = "Yes"; | ||
| } | ||
| changeBut.innerText = readStatus; | ||
|
|
||
|
|
@@ -89,15 +93,16 @@ function render() { | |
| }); | ||
|
|
||
| //add delete button to every row and render again | ||
| let delButton = document.createElement("button"); | ||
| let delBut = document.createElement("button"); | ||
| delBut.id = i + 5; | ||
|
cjyuan marked this conversation as resolved.
Outdated
|
||
| 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(); | ||
| }); | ||
| } | ||
| } | ||
|
Comment on lines
+113
to
116
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. Indentation is off. Have you successfully enabled "Format on save"? |
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.