Skip to content

Commit

Permalink
Fix bug of favorites icon in the favorites menu
Browse files Browse the repository at this point in the history
Dynamically:
1. update the icon on mouse click (was already done).
2. choose the default icon in the modal's HTML of
each book, so that it works when going to favorites
menu too.

Move the `index` variable at the top, so that it can
be accessed within the prototype.

* Bug:
* add book to favorites.
* Go to Favorites menu.
* The fav icon of each book should be filled, but it wasn't.
  • Loading branch information
porobertdev committed Dec 29, 2023
1 parent 417e3a3 commit e360653
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ const api = {
if (books == userBooks.favorites) console.log('parsing favorites...');

let olid = book.key.split('/')[2];
// used to remove the book
let index = userBooks.favorites.findIndex( item => item.key.includes(olid));

// create result & modal HTML for each book
Object.getPrototypeOf(book).createHTML = function() {
this.html = `<img src="https://covers.openlibrary.org/b/id/${this.cover_i}-L.jpg?default=false">
<div class="info">
Expand All @@ -105,7 +106,7 @@ const api = {
<img class="amazon" src="./assets/icons/amazon.svg">
</a>
<img class="read_status" src="./assets/icons/read_status.svg">
<img class="favorites ${olid}" src="./assets/icons/favorite.svg">
<img class="favorites ${olid}" src="./assets/icons/favorite-${(index != -1) ? 'filled' : 'empty'}.svg">
</div>
</div>
Expand Down Expand Up @@ -176,9 +177,6 @@ const api = {
let currBook = book;

favIcon.addEventListener('click', () => {

// used to remove the book
let index = userBooks.favorites.findIndex( item => item.key.includes(olid));

if (!userBooks.favorites.includes(currBook)) {
console.log('not included, adding...');
Expand Down

0 comments on commit e360653

Please sign in to comment.