Skip to content

Commit

Permalink
Feat(JS & HTML) Added search
Browse files Browse the repository at this point in the history
  • Loading branch information
ViktorSvertoka committed Dec 17, 2023
1 parent 05e5450 commit 04f22f7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 34 deletions.
68 changes: 34 additions & 34 deletions src/js/04-search-form.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
// import APIService from './00-api';
// const apiService = new APIService();
import APIService from './00-api';
const apiService = new APIService();

// const searchButton = document.getElementById('search-button');
// const searchInput = document.getElementById('search-input');
// const listItem = document.querySelector('.js-list');
const searchButton = document.getElementById('search__button');
const searchInput = document.getElementById('search__input');
const listItem = document.querySelector('.js-list');

// listItem.addEventListener('click', onSearch);
listItem.addEventListener('click', onSearch);

// let query = '';
let query = '';

// searchButton.addEventListener('click', function (event) {
// event.preventDefault();
// onSearch();
// });
searchButton.addEventListener('click', function (event) {
event.preventDefault();
onSearch();
});

// searchInput.addEventListener('keydown', function (event) {
// if (event.key === 'Enter') {
// event.preventDefault();
// onSearch();
// }
// });
searchInput.addEventListener('keydown', function (event) {
if (event.key === 'Enter') {
event.preventDefault();
onSearch();
}
});

// async function onSearch(event) {
// const searchQuery = searchInput.value.trim();
async function onSearch(event) {
const searchQuery = searchInput.value.trim();

// if (!event.target.closest('.filters__item')) {
// return;
// }
if (!event.target.closest('.filters__item')) {
return;
}

// const item = event.target.closest('.filters__item');
const item = event.target.closest('.filters__item');

// const filter = item.children[0].innerText.toLowerCase();
// const name = item.children[1].innerText.toLowerCase();
const filter = item.children[0].innerText.toLowerCase();
const name = item.children[1].innerText.toLowerCase();

// try {
// const data = await apiService.getSearch(filter, name, searchQuery);
// console.log(data);
// } catch (error) {
// console.log(error);
// }
try {
const data = await apiService.getSearch(filter, name, searchQuery);
console.log(data);
} catch (error) {
console.log(error);
}

// listItem.innerHTML = '';
listItem.innerHTML = '';

// query = searchQuery;
// }
query = searchQuery;
}
5 changes: 5 additions & 0 deletions src/partials/03-exercises.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<section class="section">
<div class="exersices__container container">
<h2 class="exersices__title">Exercises</h2>

<form class="search__form">
<input class="search__input" type="text" />
<button class="search__button" type="button">svg</button>
</form>
<ul class="exersices__list">
<li>
<button class="exercises__btn btnFilters active" type="button">
Expand Down

0 comments on commit 04f22f7

Please sign in to comment.