index.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import {pizzaList} from './data/pizzaList.js';
  2. import {renderCards} from './view/pizza.render.js';
  3. import PizzaService from './services/pizza.service.js'
  4. import {openCreatePizza} from './view/createPizza.render.js';
  5. renderCards(pizzaList)
  6. const searchForm = document.querySelector('.form-search');
  7. let searchPizza = new PizzaService(pizzaList)
  8. searchForm.oninput = searchPizza.filterByName;
  9. const sortSelect = document.getElementById('sort');
  10. sortSelect.onchange = e => {
  11. document.querySelector('.card-list').innerHTML = '';
  12. renderCards(searchPizza.sortPizzas(pizzaList, sortSelect.value));
  13. }
  14. const btnChoiceByPrice = document.querySelector('#btn-price');
  15. btnChoiceByPrice.addEventListener('click', searchPizza.filterByPrice);
  16. const btnChoiceByCaloricity = document.querySelector('#btn-caloricity');
  17. btnChoiceByCaloricity.addEventListener('click', searchPizza.filterByCaloricity);
  18. document.querySelector('#cancel').addEventListener('click', function (e) {
  19. e.preventDefault();
  20. this.parentNode.reset();
  21. renderCards(pizzaList);
  22. })
  23. const btnModalOpen = document.querySelector('.btn-modal-open');
  24. btnModalOpen.addEventListener('click', () => {
  25. openCreatePizza();
  26. });