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

Resolve(js-challenge): Add solve for eachs four problems #261

Open
wants to merge 1 commit 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
6 changes: 3 additions & 3 deletions PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

Solución al reto:

Nombre:
Usuario Platzi:
Correo Electronico:
Nombre:Roger David Alba Ortega
Usuario Platzi: Roger David Alba Ortega
Correo Electronico: [email protected]

## Reto:

Expand Down
11 changes: 10 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title></title>
<meta name="description" content="Js challenge for ethereum developer program">
<title>PlatziStore</title>
<meta property="og:locale" content="en_CO"/>
<meta property="og:type" content="WebPage"/>
<meta property="og:title" content="Buy our tech products - PlatziStore"/>
<meta property="og:description" content="Js challenge for ethereum developer program"/>
<meta property="og:image" content="/favicon.ico"/>
<meta property="og:site_name" content="PlatziStore"/>
<meta property="og:url" content="https://platzi.com/"/>
<link rel="canonical" href="https://platzi.com/"/>
<link type="text/css" href="styles.css" rel="stylesheet">
</head>

Expand Down
43 changes: 34 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,55 @@ const $app = document.getElementById('app');
const $observe = document.getElementById('observe');
const API = 'https://api.escuelajs.co/api/v1/products';

const getData = api => {
fetch(api)
const getData = (api,limit = 10) => {
const offset= localStorage.getItem('pagination') ? parseInt(localStorage.getItem('pagination')) + 10 : 5-1;
localStorage.setItem('pagination', offset)
fetch(`${api}?offset=${offset}&limit=${limit}`)
.then(response => response.json())
.then(response => {
let products = response;
let output = products.map(product => {
// template
});
let lengths =products.length;
console.log(products);
let output = products.map(product =>(

`<article class="Card" id="${product.id}">
<img src="${product.images[0]}" alt="${product.title}" />
<h2>
Producto: ${product.title}
<small>$: ${product.price}</small>
</h2>
</article>`

));
let newItem = document.createElement('section');
newItem.classList.add('Item');
newItem.innerHTML = output;
$app.appendChild(newItem);
if (lengths < limit){
let message = document.createElement('span')
message.innerText = 'Todos los productos Obtenidos'
$app.appendChild(message)
intersectionObserver.unobserve($observe)
}
})
.catch(error => console.log(error));
}

const loadData = () => {
getData(API);
const loadData = async() => {
const get = await getData(API);
}

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

intersectionObserver.observe($observe);

window.addEventListener("beforeunload", (event) =>
{
event.preventDefault()
localStorage.clear()
})