Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test reto #257

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 62 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,67 @@
const $app = document.getElementById('app');
const $observe = document.getElementById('observe');
const API = 'https://api.escuelajs.co/api/v1/products';
const API_5TO10 = (init,limit) =>`https://api.escuelajs.co/api/v1/products?offset=${init}&limit=${limit}`;

const getData = api => {
console.log('test');

const isIntersecting = (entry) => {
return entry.isIntersecting
}
const accion = () => {
console.log('hola.');
}
const intersectionObserver = new IntersectionObserver(entries => {
// logic...
entries
.filter(isIntersecting)
.forEach(accion)
}, {
rootMargin: '0px 0px 100% 0px'
});
const registerItem = (item) => {
intersectionObserver.observe(item)
};

const getData = (api) => {
fetch(api)
.then(response => response.json())
.then(response => {

//console.log(response);

let products = response;
let output = products.map(product => {

return '<div style ="border:solid">'+ product.title +'</div>';

});
let newItem = document.createElement('section');
newItem.classList.add('Item');
newItem.innerHTML = output;
$app.appendChild(newItem);
registerItem(newItem);
})
.catch(error => console.log(error));
}

const getDataInit5To10 = (api) => {
fetch(api)
.then(response => response.json())
.then(response => {

//console.log(response);

let products = response;
let output = products.map(product => {
// template

return '<article class="Card">'+
'<img src="'+ product.images[0]+'"/>'+
'<h2>' +
product.title +
'<small>$ '+ product.price + '</small>'+
'</h2>'+
'</article>';
});
let newItem = document.createElement('section');
newItem.classList.add('Item');
Expand All @@ -19,13 +72,13 @@ const getData = api => {
}

const loadData = () => {
getData(API);
//getData(API);
getDataInit5To10(API_5TO10(5,10));
localStorage.pagination = 5;
}

const intersectionObserver = new IntersectionObserver(entries => {
// logic...
}, {
rootMargin: '0px 0px 100% 0px',
});

intersectionObserver.observe($observe);

//intersectionObserver.observe($app);

loadData();