-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e82297
commit bf30f4e
Showing
1 changed file
with
2 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ import image from '../img/modal-exercise-image.jpg'; | |
import imageRetina from '../img/[email protected]'; | ||
const apiService = new APIService(); | ||
|
||
let isFavorite = false; | ||
let idFavorite; | ||
|
||
const modalExercises = document.querySelector('.modal-exercises'); | ||
|
@@ -35,7 +34,6 @@ async function onExercisesCardClick(event) { | |
'.modal-exercises__btn-favorites' | ||
); | ||
btnModalFavorites.addEventListener('click', toggleFavorites); | ||
|
||
const btnModalClose = document.querySelector('.modal-exercises__btn-close'); | ||
btnModalClose.addEventListener('click', closeModalExercises); | ||
} catch (error) { | ||
|
@@ -189,28 +187,17 @@ function createMarkup({ | |
} | ||
|
||
function toggleFavorites() { | ||
// isFavorite = !isFavorite; | ||
|
||
const local = JSON.parse(localStorage.getItem('exerciseData')); | ||
|
||
if (local?.some(item => item._id === idFavorite)) { | ||
isFavorite = true; | ||
} | ||
|
||
console.log(local); | ||
const btnModalFavorites = document.querySelector( | ||
'.modal-exercises__btn-favorites' | ||
); | ||
|
||
const favoritesIcon = document.querySelector('.btn-favorites__icon'); | ||
|
||
if (isFavorite) { | ||
if (local?.some(item => item._id === idFavorite) || local == null) { | ||
btnModalFavorites.innerHTML = createRemoveFromFavoritesMarkup(); | ||
} else { | ||
btnModalFavorites.innerHTML = createAddToFavoritesMarkup(); | ||
} | ||
|
||
const newFavoritesIcon = document.querySelector('.btn-favorites__icon'); | ||
newFavoritesIcon.addEventListener('click', toggleFavorites); | ||
} | ||
|
||
function createAddToFavoritesMarkup() { | ||
|