Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
ViktorSvertoka committed Dec 16, 2023
1 parent a1a3d69 commit a3db4e7
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/favorites.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@

<footer>
<load ="partials/05-modal-exercise.html" />
<load ="partials/06-modal-rating.html" />
<!-- <load ="partials/06-modal-rating.html" /> -->
<load ="partials/09-loader.html" />
</footer>

<script type="module" src="./js/01-mobile-menu.js"></script>
<script type="module" src="./js/02-quote.js"></script>
<script type="module" src="./js/10-favorites.js"></script>
<script type="module" src="./js/14-added-local.js"></script>
<script type="module" src="./js/15-remove-local.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<footer>
<load ="partials/04-footer.html" />
<load ="partials/05-modal-exercise.html" />
<load ="partials/06-modal-rating.html" />
<!-- <load ="partials/06-modal-rating.html" /> -->
<load ="partials/07-modal-team.html" />
<load ="partials/08-scroll-up.html" />
<load ="partials/09-loader.html" />
Expand Down
12 changes: 11 additions & 1 deletion src/js/05-modal-exercises.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import imageRetina from '../img/[email protected]';
const apiService = new APIService();

let isFavorite = false;
let idFavorite;

const modalExercises = document.querySelector('.modal-exercises');
const overlay = document.querySelector('.overlay');
Expand All @@ -24,6 +25,8 @@ async function onExercisesCardClick(event) {

const exerciseData = await apiService.getExercisesById(exerciseID);

idFavorite = exerciseID;

const markup = createMarkup(exerciseData);
updateModal(markup);
openModalExercises();
Expand Down Expand Up @@ -186,11 +189,18 @@ function createMarkup({
}

function toggleFavorites() {
isFavorite = !isFavorite;
// isFavorite = !isFavorite;

const local = JSON.parse(localStorage.getItem('exerciseData'));

if (local?.some(item => item._id === idFavorite)) {
isFavorite = true;
}

const btnModalFavorites = document.querySelector(
'.modal-exercises__btn-favorites'
);

const favoritesIcon = document.querySelector('.btn-favorites__icon');

if (isFavorite) {
Expand Down
2 changes: 1 addition & 1 deletion src/js/10-favorites.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async function onExercisesCardClick(event) {
const local = JSON.parse(localStorage.getItem('exerciseData'));

if (local?.some(item => item._id === exerciseData._id)) {
return;
array = local.filter(item => item._id !== exerciseData._id);
} else {
array.push(exerciseData);
}
Expand Down
2 changes: 1 addition & 1 deletion src/js/14-added-local.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const buttonFavorite = document.getElementById('favoritesButton');

buttonFavorite.addEventListener('click', renderFavorite());

function renderFavorite() {
export function renderFavorite() {
const local = JSON.parse(localStorage.getItem('exerciseData'));
if (local.length === 0) {
return;
Expand Down
4 changes: 2 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import './js/02-quote';
import './js/03-filters';
import './js/04-search-form';
import './js/05-modal-exercises';
import './js/06-modal-rating';
import './js/07-modal-team';
// import './js/06-modal-rating';
// import './js/07-modal-team';
import './js/08-scroll-up';
import './js/09-loader';
import './js/10-favorites';
Expand Down

0 comments on commit a3db4e7

Please sign in to comment.