Skip to content

Conversation

halyna-k
Copy link

@halyna-k halyna-k commented Aug 1, 2025

Learners, PR Template

Self checklist

  • I have committed my files one by one, on purpose, and for a reason
  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • I have tested my changes
  • My changes follow the style guide
  • My changes meet the requirements of this task

Changelist

  • Fix read/unread status logic;
  • Correct event listener scope for buttons;
  • Ensure new books render properly;
  • Improve form input handling and validation;
  • Improved form submission handling;
  • Fixed data initialization typo;
  • Enhanced input validation and reset;
  • Made DOM updates safer and cleaner;
  • Strengthened code reliability with strict checks

Questions

Ask any questions you have for your reviewer.

- add an omitted parenthesis
- fix the variable name of library to the correct one;
- fix the name of the delete button
- change 'clicks' to 'click' to enable button functionality.
- show "Yes" when book is marked as read.
- Set correct <title> to "My Book Library"
- Replace <div> with <form id="book-form"> for proper submission handling
- Fix incorrect input types: "title" and "author" → "text"
- Set checkbox value to "read"
- Remove inline onClick handler from submit button
- Clean up initial <tbody> structure to avoid empty table row
- Fix typo: "Robison Crusoe" → "Robinson Crusoe"
- Remove duplicate render() call after initial data push
- Replace inline form submission with `form.addEventListener('submit', ...)`
- Rename submit() → submitNewBook() for clarity
- Ensure pages are stored as a number in Book constructor
- Replace innerHTML with textContent for safer rendering
- Replace `==` with strict `===` for checkbox comparison
- Add `form.reset()` after successful book submission
@halyna-k halyna-k added 📅 Sprint 3 Assigned during Sprint 3 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Aug 1, 2025
@halyna-k halyna-k linked an issue Aug 1, 2025 that may be closed by this pull request
@halyna-k halyna-k changed the title London | 25-ITP-May | Halyna Kozlovska | Sprint 3 | Alarm Clock London | 25-ITP-May | Halyna Kozlovska | Sprint 3 | Book Library Aug 1, 2025
@halyna-k halyna-k changed the title London | 25-ITP-May | Halyna Kozlovska | Sprint 3 | Book Library London | 25-ITP-May | Halyna Kozlovska | Sprint 2 | Book Library Aug 1, 2025
@halyna-k halyna-k added 📅 Sprint 2 Assigned during Sprint 2 of this module and removed 📅 Sprint 3 Assigned during Sprint 3 of this module labels Aug 3, 2025
Copy link
Contributor

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check if any of this general feedback can help you further improve your code?
https://github.com/cjyuan/Module-Data-Flows/blob/book-library-feedback/debugging/book-library/feedback.md

Doing so can help me speed up the review process. Thanks.

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Aug 8, 2025
- replace constructor function with ES6 class for Book;
- rename variables ('check' → 'isRead') for semantic clarity;
- improve input validation logic: trims input, ensures page count is a valid number > 0;
- remove unnecessary else block after validation return;
- clean up event listener and DOM variable naming for better readability;
- reorganize button creation with modern const declarations;
- ensure proper UX: confirmation message shown after deletion, not before;
- use textContent consistently instead of innerHTML;
- remove unnecessary IDs and used button text instead;
- optimize table row clearing using a while loop.
@halyna-k
Copy link
Author

halyna-k commented Aug 8, 2025

Can you check if any of this general feedback can help you further improve your code? https://github.com/cjyuan/Module-Data-Flows/blob/book-library-feedback/debugging/book-library/feedback.md

Doing so can help me speed up the review process. Thanks.

@cjyuan Thank you for your comment. I've checked everything and corrected.

Copy link
Contributor

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code has been improved greatly! I still have few more suggestions.

function submitNewBook() {
let title = titleInput.value.trim();
let author = authorInput.value.trim();
let pages = Number(pagesInput.value.trim());
Copy link
Contributor

@cjyuan cjyuan Aug 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pagesInput could be a value like "3.1416". Do we want to allow such value as page count?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cjyuan Thanks for the great catch! I’ve updated the validation logic to require the page count to be a positive integer, preventing decimal values from being accepted.

Comment on lines 57 to 59
while (table.rows.length > 1) {
table.deleteRow(1);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach is still deleting table rows one by one. A more efficient approach is to empty <tbody> in the table .

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cjyuan Thanks for the suggestion! I updated the render function to clear the table body by setting its innerHTML to empty instead of deleting rows one by one. This should improve rendering efficiency, especially with larger datasets.

delBut.addEventListener("clicks", function () {
alert(`You've deleted title: ${myLibrary[i].title}`);
myLibrary.splice(i, 1);
const deleteCell = row.insertCell(4);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you think of the pros and cons of these two approaches for creating cells within a row?

  1. Keeping all the cell creation code in one location, like the original code does.
  2. Scattering the cell creation code across different locations, like what you did.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cjyuan Thank you for your comment.
Keeping all cell creation in one place improves readability and maintainability by clearly defining the row structure and minimizing the risk of mismatched cells. It also ensures consistent and efficient DOM updates.

Scattering cell creation allows for modular handling of complex UI elements or conditional logic but can fragment the code, making it harder to follow and maintain.

I refactored the code to centralize cell creation within render() for clarity, while extracting button-specific logic into helper functions to separate concerns without scattering cell insertion.

…etup

- create all cells in one place within render();
- extract read toggle and delete button creation to helper functions;
- improve code readability and maintainability
@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Aug 10, 2025
@cjyuan
Copy link
Contributor

cjyuan commented Aug 10, 2025

Changes look great. Well done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed. 📅 Sprint 2 Assigned during Sprint 2 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TECH ED] Book Library

3 participants