Skip to content

Commit

Permalink
add load next gallery
Browse files Browse the repository at this point in the history
  • Loading branch information
ihor-kutsenko committed Jun 11, 2023
1 parent 388de42 commit f68df8b
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import axios from "axios";


const form = document.querySelector('#search-form');
const gallery = document.querySelector('.gallery')
const gallery = document.querySelector('.gallery');
const loadBtn = document.querySelector('.load-more')



Expand Down Expand Up @@ -43,6 +44,7 @@ async function createGallery(event) {
gallery.insertAdjacentHTML('beforeend', markup);

const lightbox = new SimpleLightbox('.gallery a');

} catch (error) {
Notiflix.Notify.failure('Something went wrong!')
}
Expand All @@ -51,3 +53,22 @@ async function createGallery(event) {

form.reset();
}


loadBtn.addEventListener('click', loadNextGallery);

async function loadNextGallery(event) {
event.preventDefault();

pageNumber += 1;
const nextPage = await fetchImages(name, pageNumber);
// console.log(nextPage);
const nextMarkup = await renderGalleryCard(nextPage.hits);
gallery.insertAdjacentHTML('beforeend', nextMarkup);

const lightbox = new SimpleLightbox('.gallery a');
lightbox.refresh();



}

0 comments on commit f68df8b

Please sign in to comment.