Skip to content

London| ITP-May-2025| Zohreh Kazemianpour |Book library #252

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
wants to merge 18 commits into
base: book-library
Choose a base branch
from

Conversation

zohrehKazemianpour
Copy link

@zohrehKazemianpour zohrehKazemianpour commented Jul 29, 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

This PR addresses all major functionality bugs in the Book Library:

✔ Fixed book display
Books now render correctly on page load
The default books appear as intended

✔ Corrected form submission
Properly captures all fields (title, author, pages, read status)
Fixed title/author mixup bug
Added validation for required fields

✔ Fixed delete functionality
Delete buttons now work reliably
Uses stable data-index system instead of fragile IDs

✔ Read status accuracy
Correctly saves and displays read/unread state
Toggle buttons update properly

Questions

Ask any questions you have for your reviewer.

cjyuan and others added 10 commits May 6, 2025 14:44
- Add event listener for submit button instead of HTML onclick
- Prevent default form submission behavior
- Correct array name from 'library' to 'myLibrary'
- Call render() after adding new books to update display
- Fix validation to check for empty author field
- Reset title, author, and pages input fields to empty strings
@zohrehKazemianpour zohrehKazemianpour added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Jul 29, 2025
let book = new Book(title.value, title.value, pages.value, check.checked);
library.push(book);
render();
let book = new Book(title.value, author.value, pages.value, check.checked);
Copy link
Contributor

Choose a reason for hiding this comment

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

  • Do you want to keep leading and trailing space characters in title, author, and pages?

  • The following page numbers are possible

image

Copy link
Author

Choose a reason for hiding this comment

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

No, I don't think it's a good idea to keep leading and trailing spaces. Thank you for catching this issue! I have now implemented better data validation. I used alert() for consistency here, but I am not sure if it is the best in terms of UX.

table.deleteRow(n);
}
//insert updated row and cells
let length = myLibrary.length;
for (let i = 0; i < length; i++) {
let row = table.insertRow(1);
let row = table.insertRow(i+1);
Copy link
Contributor

Choose a reason for hiding this comment

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

We could also omit the argument in insertRow() if we wanted to append a row to the table.

Comment on lines 82 to 83
readStatus = myLibrary[i].check ? "Yes" : "No";
changeBut.innerText = readStatus;
Copy link
Contributor

Choose a reason for hiding this comment

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

The declaration of variable readStatus was deleted. You could also combined lines 82-83 into one statement without using readStatus.

Comment on lines 98 to 100
alert(`You've deleted title: ${myLibrary[i].title}`);
myLibrary.splice(i, 1);
const index = parseInt(this.dataset.index)
myLibrary.splice(index, 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

@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 3, 2025
@zohrehKazemianpour
Copy link
Author

Hi @cjyuan, thank you so much as always, for the valuable feedback. I have updated the code based on your comments. Could you please review when you have a moment? I appreciate your insights!

@zohrehKazemianpour zohrehKazemianpour added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Aug 4, 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.

Changes look great! Well done!

Comment on lines 29 to 37
) {
alert("Please fill all fields!");
return false;
} else {
let book = new Book(title.value, author.value, pages.value, check.checked);
}
if (isNaN(parseInt(pages.value)) || parseInt(pages.value) <= 0) {
alert("Please enter a valid positive number for pages!");
return false;
}
let book = new Book(title.value.trim(), author.value.trim(), parseInt(pages.value), check.checked);
Copy link
Contributor

Choose a reason for hiding this comment

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

For better performance (reduce number of function calls) and reducing the chance of using raw input accidently, we could stored the pre-processed/sanitized/normalized input in some variables first, and reference the variables in other part of the function.

  const cleanTitle = title.value.trim();
  ...
  
  const pageNum = parseInt(pages.value);
  ...
  
  const book = new Book(cleanTitle, cleanAuthor, pageNum, check.checked);

myLibrary.push(book1);
myLibrary.push(book2);
}
}
}

const title = document.getElementById("title");
Copy link
Contributor

Choose a reason for hiding this comment

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

Using descriptive and consistent suffixes (like El, Input, Btn, Form, etc.) for variables that store DOM elements can 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 Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Aug 4, 2025
@zohrehKazemianpour
Copy link
Author

Changes look great! Well done!

Thank you so much for the complete label. I appreciate the time and energy you put into reviewing our coursework.

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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants