London | 26-ITP-May | Khaliun Baatarkhuu | Sprint 2 | Book Library - #535
London | 26-ITP-May | Khaliun Baatarkhuu | Sprint 2 | Book Library#535khaliun-dev wants to merge 6 commits into
Conversation
Changed input types for title and author fields to 'text'.
cjyuan
left a comment
There was a problem hiding this comment.
Can you check if any of this general feedback can help you further improve your code?
https://github.com/CodeYourFuture/Module-Data-Flows/blob/general-review-feedback/debugging/book-library/feedback.md
Doing so can help me speed up the review process. Thanks.
|
@cjyuan i have made some improvements to the code from the general feedback, specifically: Changes
TestingTested adding, validating, displaying, toggling Read/No, deleting books, and clearing the form. Browser console checked with no errors. |
There was a problem hiding this comment.
According to https://validator.w3.org/, there are errors in your index.html. Could you fix these errors?
There was a problem hiding this comment.
-
Even though this element has a
requiredattribute, the user could still "submit" the input the even if this input field is empty. Could you find out why and then address the issue? -
If possible, also make this input field to accept only positive whole numbers.
There was a problem hiding this comment.
The checkbox is not showing.
The issue is related to Bootstrap 4.4.1. Could you use AI to find a way to fix the issue? Mentioning "Bootstrap 4.4.1" might help.
| value="Submit" | ||
| class="btn btn-primary" | ||
| onclick="submit();" | ||
| onclick="addBook();" |
There was a problem hiding this comment.
Could you research the trade-off between
- Attaching event listener in HTML
- Attaching event listener using
addEventListener()in JS
There was a problem hiding this comment.
Can we declare myLibrary in a way that prevents it from being accidentally reassigned?
| const book = new Book( | ||
| titleInput.value, | ||
| authorInput.value, | ||
| Number(pagesInput.value), | ||
| readInput.checked | ||
| ); |
There was a problem hiding this comment.
-
What if the input contains leading and trailing space characters?
-
Could
Number(pagesInput.value)evaluates to an invalid page count? What numbers should be considered "invalid page count"?
Note: A better and safer approach to deal with user input is to first preprocess/sanitise them, and then store the cleaned values in variables. Thereafter, refer only to the variables for cleaned values consistently throughout the rest of the code.
| titleInput.value = ""; | ||
| authorInput.value = ""; | ||
| pagesInput.value = ""; | ||
| readInput.checked = false; |
There was a problem hiding this comment.
Note: If the input elements are inside a <form> element, we could also just call a form method to reset the form.
| const rowsNumber = table.rows.length; | ||
|
|
||
|
|
||
| for (let n = rowsNumber - 1; n > 0; n--) { | ||
| table.deleteRow(n); | ||
| } |
There was a problem hiding this comment.
Clearing a table by deleting its rows row by row is not efficient. Could you look up a more efficient way to clear a table (the <tbody> part of the table)?
| alert(`You've deleted title: ${myLibrary[i].title}`); | ||
| myLibrary.splice(i, 1); | ||
| render(); |
There was a problem hiding this comment.
The alert message is shown before the book is actually deleted; the deletion only occurs after the alert dialog is dismissed. This introduces a risk that the operation may not complete (e.g., if the user closes the browser before dismissing the alert).
In general, it’s better to display a confirmation message only after the associated operation has successfully completed.
alert() is a blocking function call. As a result, invoking it prevents the browser from updating the UI until the dialog is dismissed.
If time permits, research for approaches that allows the UI to update before displaying the alert dialog. (This is an optional change).
|
@cjyuan I have addressed all the comments you have made. Thanks. |
cjyuan
left a comment
There was a problem hiding this comment.
Changes look good. Well done.
| library.push(book); | ||
| render(); | ||
| } | ||
| const bookForm = document.getElementById("bookForm"); |
There was a problem hiding this comment.
Could consider placing all code that runs once on page load in a single function. For example, you could put it inside the page load callback or create a function named init() or setup() and call it once when the page loads.
This makes it easier to locate and manage all the code that runs once when the app starts.
| const titleInput = document.getElementById("title"); | ||
| const authorInput = document.getElementById("author"); | ||
| const pagesInput = document.getElementById("pages"); | ||
| const readInput = document.getElementById("check"); |
There was a problem hiding this comment.
Common practice is to declare all shared variables/constants at the beginning of the files, before function definitions. Doing so makes locating them easier.
| !Number.isFinite(pages) || | ||
| pages < 1 || | ||
| !Number.isInteger(pages) |
There was a problem hiding this comment.
Could you figure out which check is redundant?
There was a problem hiding this comment.
the code on line 43, due to another code preventing invalid values anyway.
| myLibrary.splice(i, 1); | ||
| render(); | ||
|
|
||
| alert(`You've deleted title: ${deletedTitle}`); |
There was a problem hiding this comment.
alert() is a blocking function call. As a result, invoking it prevents the browser from updating the UI until the dialog is dismissed.
If time permits, research for approaches that allows the UI to update before displaying the alert dialog. (This is an optional change).
Change alert to use setTimeout for better UX.
Self checklist
Changelist
Testing
Questions
None.