From 541628076b4916096b43ab810e9a65add3ac7954 Mon Sep 17 00:00:00 2001 From: masterarias Date: Sun, 12 Jun 2022 08:33:40 +0200 Subject: [PATCH 1/5] challenge v1 --- .DS_Store | Bin 0 -> 6148 bytes public/index.html | 3 ++- src/index.js | 54 +++++++++++++++++++++++++++++++++------------- 3 files changed, 41 insertions(+), 16 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b58b51eb1bcce3b292f0b283b09be84d2d433f4f GIT binary patch literal 6148 zcmeHKI|>3Z5S>vG!DdU#T)`Uz(Gz$9Q5#`FLF~8kTprCgpF&yfv{2r_^uvY(4IA~Jy+%GHLx*}i$t1{qNx9A_M4w?FUN?eW<5vR?;`JC>7NWGn3>-!^De zfC^9nDnJFOz{eHH5<8iG{A3;e&iX;6Vd)od{|=!lohtBGA;&_%QP(7ai*Ls7pS=NC^Gt$`e=02O#vU>M8B>i-J< zrvHB?aYY5Fz+Wk#qvd+Jz>~7J_8w=ow!k-V%eleLFn0c7o_SK_6`Nzf VCU${NN8IT^{tTEdG%E0I1@0mY6@&l) literal 0 HcmV?d00001 diff --git a/public/index.html b/public/index.html index 5f8fbe0d..12a3a894 100755 --- a/public/index.html +++ b/public/index.html @@ -5,8 +5,9 @@ - + PlatziStore + diff --git a/src/index.js b/src/index.js index eb2631c2..d778b65b 100755 --- a/src/index.js +++ b/src/index.js @@ -2,30 +2,54 @@ const $app = document.getElementById('app'); const $observe = document.getElementById('observe'); const API = 'https://api.escuelajs.co/api/v1/products'; -const getData = api => { - fetch(api) - .then(response => response.json()) - .then(response => { - let products = response; - let output = products.map(product => { - // template - }); - let newItem = document.createElement('section'); - newItem.classList.add('Item'); - newItem.innerHTML = output; - $app.appendChild(newItem); - }) - .catch(error => console.log(error)); +const getData = async api => { + let current = parseInt(localStorage.getItem('pagination')) || 5; + if (current > 200) { + $observe.innerHTML = "

Todos los productos Obtenidos

"; + intersectionObserver.unobserve($observe); + return; + } + const getData = await fetch(`${api}?offset=${current}&limit=10`); + const response = await getData.json(); + let products = response; + let output = products.map(product => { + return `
+ ${product.title} +

+ ${product.title} + $ ${product.price} +

+
`; + }).join(''); + let newItem = document.createElement('section'); + newItem.classList.add('Item'); + newItem.innerHTML = output; + $app.appendChild(newItem); + localStorage.setItem('pagination', current + 10); } const loadData = () => { getData(API); } + const intersectionObserver = new IntersectionObserver(entries => { - // logic... + entries.forEach(entry => { + if (entry.isIntersecting) { + loadData(); + } + }) }, { rootMargin: '0px 0px 100% 0px', }); intersectionObserver.observe($observe); + + + + +(function () { + localStorage.clear('pagination'); +})(); + + From ae78bfa798250f7bcc4f77551003b6d64043e1b8 Mon Sep 17 00:00:00 2001 From: masterarias Date: Sun, 12 Jun 2022 08:44:11 +0200 Subject: [PATCH 2/5] logging / debug --- .DS_Store | Bin 6148 -> 6148 bytes .gitignore | 5 +++++ src/index.js | 1 + 3 files changed, 6 insertions(+) diff --git a/.DS_Store b/.DS_Store index b58b51eb1bcce3b292f0b283b09be84d2d433f4f..e54ad94420727715acf4fdd6a79046429caefb17 100644 GIT binary patch delta 54 zcmZoMXfc@J&&kBVz`)4BAiyv&Mt@=h%VYx)79kb}J%)6KOooz_;^ds9{QMk-jXi1X Ko7p-3@&f=!(G9`? delta 45 zcmZoMXfc@JFUrWkzyQPo3=EkJ$tlIjIZ65XITI7r85uV&Ok diff --git a/.gitignore b/.gitignore index ad46b308..b84d4365 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,8 @@ typings/ # next.js build output .next + +#mac +.DS_Store + + diff --git a/src/index.js b/src/index.js index d778b65b..c7b0103c 100755 --- a/src/index.js +++ b/src/index.js @@ -26,6 +26,7 @@ const getData = async api => { newItem.innerHTML = output; $app.appendChild(newItem); localStorage.setItem('pagination', current + 10); + console.log(localStorage.getItem('pagination')); } const loadData = () => { From 72a1dfc647662351dad09fc6a23aaf7fb879836e Mon Sep 17 00:00:00 2001 From: masterarias Date: Sun, 12 Jun 2022 08:59:25 +0200 Subject: [PATCH 3/5] done --- PULL_REQUEST_TEMPLATE.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md index ddfff263..3218aa46 100644 --- a/PULL_REQUEST_TEMPLATE.md +++ b/PULL_REQUEST_TEMPLATE.md @@ -2,14 +2,14 @@ Solución al reto: -Nombre: -Usuario Platzi: -Correo Electronico: +Nombre: Eduardo +Usuario Platzi: masterarias +Correo Electronico: e@masterarias.com ## Reto: -- [ ] Primer problema -- [ ] Segundo problema -- [ ] Tercer problema -- [ ] Cuarto Problema -- [ ] Quinto Problema +- [✅] Primer problema +- [✅] Segundo problema +- [✅] Tercer problema +- [✅] Cuarto Problema +- [✅] Quinto Problema -> https://masterarias.github.io/ From 7ee3111331ae94bbe9c7c394be8da2593ec10eef Mon Sep 17 00:00:00 2001 From: masterarias Date: Sun, 12 Jun 2022 09:12:43 +0200 Subject: [PATCH 4/5] fix errors --- cypress/e2e/test.cy.js | 6 +++--- src/index.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cypress/e2e/test.cy.js b/cypress/e2e/test.cy.js index 6c7dfd4e..18e648b6 100644 --- a/cypress/e2e/test.cy.js +++ b/cypress/e2e/test.cy.js @@ -13,17 +13,17 @@ describe("PlatziStore Tests", () => { }); it("Obtener los primeros 10 Productos", () => { - cy.get('*[class^="Items"]').find('article').should('have.length', 10) + cy.get('*[class^="Item"]').find('article').should('have.length', 10) }); it('Desplácese hacia abajo y renderice nuevos productos', () => { cy.scrollTo('bottom') - cy.get('*[class^="Items"]').should('have.length', 2); + cy.get('*[class^="Item"]').should('have.length', 2); }); it('Comprobar el nombre del Producto', () => { cy.scrollTo('bottom'); - cy.get('*[class^="Items"]').find('article').find('h2').eq(0).should('exist'); + cy.get('*[class^="Item"]').find('article').find('h2').eq(0).should('exist'); }); }); \ No newline at end of file diff --git a/src/index.js b/src/index.js index c7b0103c..a25d318d 100755 --- a/src/index.js +++ b/src/index.js @@ -3,7 +3,7 @@ const $observe = document.getElementById('observe'); const API = 'https://api.escuelajs.co/api/v1/products'; const getData = async api => { - let current = parseInt(localStorage.getItem('pagination')) || 5; + let current = parseInt(localStorage.getItem('pagination')); if (current > 200) { $observe.innerHTML = "

Todos los productos Obtenidos

"; intersectionObserver.unobserve($observe); @@ -26,7 +26,6 @@ const getData = async api => { newItem.innerHTML = output; $app.appendChild(newItem); localStorage.setItem('pagination', current + 10); - console.log(localStorage.getItem('pagination')); } const loadData = () => { @@ -51,6 +50,7 @@ intersectionObserver.observe($observe); (function () { localStorage.clear('pagination'); + localStorage.setItem('pagination', 5); })(); From df5c12754d01fda0ba9358101af3164444f7128f Mon Sep 17 00:00:00 2001 From: masterarias Date: Sun, 12 Jun 2022 09:27:22 +0200 Subject: [PATCH 5/5] fix v3 --- src/index.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/index.js b/src/index.js index a25d318d..d1688a04 100755 --- a/src/index.js +++ b/src/index.js @@ -2,6 +2,8 @@ const $app = document.getElementById('app'); const $observe = document.getElementById('observe'); const API = 'https://api.escuelajs.co/api/v1/products'; +localStorage.clear('pagination'); + const getData = async api => { let current = parseInt(localStorage.getItem('pagination')); if (current > 200) { @@ -25,7 +27,6 @@ const getData = async api => { newItem.classList.add('Item'); newItem.innerHTML = output; $app.appendChild(newItem); - localStorage.setItem('pagination', current + 10); } const loadData = () => { @@ -36,6 +37,17 @@ const loadData = () => { const intersectionObserver = new IntersectionObserver(entries => { entries.forEach(entry => { if (entry.isIntersecting) { + const check = localStorage.getItem("pagination"); + if (!check) { + localStorage.setItem("pagination", 5); + } + else + { + localStorage.setItem("pagination", parseInt(check) + 10); + } + + + loadData(); } }) @@ -47,10 +59,3 @@ intersectionObserver.observe($observe); - -(function () { - localStorage.clear('pagination'); - localStorage.setItem('pagination', 5); -})(); - -