Skip to content

Commit

Permalink
Merge branch 'main' into Favorites-Anatolii
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtanFS committed Oct 22, 2023
2 parents c561565 + 3366408 commit c2ae216
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
15 changes: 14 additions & 1 deletion src/js/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
createCategoryMarkup,
createPaginationBtnsMarkup,
} from './templates/categories-markup';
import { handleOpenModalClick } from './modal-exercise';

const refs = {
catsList: document.querySelector('.categories-wrapper'),
Expand All @@ -16,8 +17,10 @@ const refs = {
catFilterInput: document.querySelector('.cat-filter-input'),
};
const { catsList, catFilterList, exercisesTitleSpan, catFilterInput } = refs;

let categoryName = '';
let currentExercise;

catFilterList.addEventListener('click', catFilterBtnHandler);
catFilterInput.addEventListener('input', catInputHandler);

Expand Down Expand Up @@ -71,13 +74,23 @@ async function catsListBtnHandler(e) {
}

currentExercise = e.target.closest('.categories-item').dataset.bodyPart;
console.log('Exercise', currentExercise);
const getExercises = await fetchExercises(categoryName, currentExercise);

catsList.innerHTML = createExercisesMarkup(getExercises);

exercisesTitleSpan.innerHTML = currentExercise;
catFilterInput.hidden = false;
// const resp = await fetchAllExercises(categoryName, currentExercise);

const openModalBtns = document.querySelectorAll('[data-modal-exercise="open"]').forEach(btn => {
btn.addEventListener('click', (event) => {
const exerciseId = event.currentTarget.closest('.exercises-item').dataset.exerciseId;
console.log(exerciseId);
handleOpenModalClick(event, exerciseId);
})
});

// const resp = await fetchAllExercises(categoryName, currentExercise);
}

function catInputHandler(e) {
Expand Down
5 changes: 3 additions & 2 deletions src/js/modal-exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ openModalExerciseBtnRef.addEventListener('click', handleOpenModalClick);

export async function handleOpenModalClick(
_,
favoriteId = '64f389465ae26083f39b17a2'
favoriteId,
) {
console.log(favoriteId);
let modalBox = {};
let ratingValue = 0;

try {
const exericiseData = await fetchExerciseModalById();
const exericiseData = await fetchExerciseModalById(favoriteId);
modalBox = new ModalBox(
createModalExerciseMarkup,
closeModalSelector,
Expand Down
4 changes: 2 additions & 2 deletions src/js/templates/exercises-markup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ export function createExercisesMarkup(data) {
<ul class="exer-pagination-list"></ul>`;
}

function createMarkup({ rating, name, burnedCalories, bodyPart, target }) {
return `<li class="exercises-item">
function createMarkup({ rating, name, burnedCalories, bodyPart, target, _id }) {
return `<li class="exercises-item" data-exercise-id="${_id}">
<div class="exercises-header">
<div class="exercises-meta-container">
<p class="exercises-meta">WORKOUT</p>
Expand Down

0 comments on commit c2ae216

Please sign in to comment.