Skip to content

Commit

Permalink
Update 05-modal-exercises.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ViktorSvertoka committed Dec 16, 2023
1 parent 9e82297 commit bf30f4e
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions src/js/05-modal-exercises.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit bf30f4e

Please sign in to comment.