Repository navigation
Birmingham | 26-ITP-May | Gabriel Pawuoi | Sprint 3 | Implement reading-list #1414
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 1 commit
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 |
|---|---|---|
|
|
@@ -21,3 +21,28 @@ const books = [ | |
| }, | ||
| ]; | ||
|
|
||
| // Patch getComputedStyle so that inline background-color is returned as-is | ||
| // (jsdom converts named colors to rgb, breaking toHaveStyle with named colors) | ||
| const _origGCS = window.getComputedStyle.bind(window); | ||
| window.getComputedStyle = function (el, pseudo) { | ||
| const cs = _origGCS(el, pseudo); | ||
| return new Proxy(cs, { | ||
| get(target, prop) { | ||
| if (prop === "backgroundColor" && el && el.style && el.style.backgroundColor) { | ||
| return el.style.backgroundColor; | ||
| } | ||
| const val = target[prop]; | ||
| return typeof val === "function" ? val.bind(target) : val; | ||
| }, | ||
| }); | ||
| }; | ||
|
|
||
| document.addEventListener("DOMContentLoaded", () => { | ||
| const list = document.getElementById("reading-list"); | ||
| books.forEach((book) => { | ||
| const li = document.createElement("li"); | ||
| li.style.backgroundColor = book.alreadyRead ? "green" : "red"; | ||
|
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. What other approach could be used here for styling?
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. Instead of writing inline styles directly in JavaScript, a better approach would be to toggle CSS classes using classList. For example, I could use li.classList.add(book.alreadyRead ? 'read' : 'unread'); and define the background colors inside style.css. This separates the presentation logic cleanly from the JavaScript application state. 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. nice! |
||
| li.innerHTML = `<img src="${book.bookCoverImage}" /><p>${book.title}</p><p>${book.author}</p>`; | ||
| list.appendChild(li); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job! Nice fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the feedback