├── .gitignore
├── LICENSE
├── PULL_REQUEST_TEMPLATE.md
├── README.md
├── package.json
├── public
├── index.html
└── styles.css
├── screenshot.png
└── src
└── index.js
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Runtime data
9 | pids
10 | *.pid
11 | *.seed
12 | *.pid.lock
13 |
14 | # Directory for instrumented libs generated by jscoverage/JSCover
15 | lib-cov
16 |
17 | # Coverage directory used by tools like istanbul
18 | coverage
19 |
20 | # nyc test coverage
21 | .nyc_output
22 |
23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24 | .grunt
25 |
26 | # Bower dependency directory (https://bower.io/)
27 | bower_components
28 |
29 | # node-waf configuration
30 | .lock-wscript
31 |
32 | # Compiled binary addons (https://nodejs.org/api/addons.html)
33 | build/Release
34 |
35 | # Dependency directories
36 | node_modules/
37 | jspm_packages/
38 |
39 | # TypeScript v1 declaration files
40 | typings/
41 |
42 | # Optional npm cache directory
43 | .npm
44 |
45 | # Optional eslint cache
46 | .eslintcache
47 |
48 | # Optional REPL history
49 | .node_repl_history
50 |
51 | # Output of 'npm pack'
52 | *.tgz
53 |
54 | # Yarn Integrity file
55 | .yarn-integrity
56 |
57 | # dotenv environment variables file
58 | .env
59 |
60 | # next.js build output
61 | .next
62 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Comunidad Platzi
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ## DESCRIPTION
2 |
3 | Solución al reto 03 de Escuela de JavaScript
4 |
5 | Nombre:
6 | Usuario Platzi:
7 |
8 | ## Reto:
9 | - [ ] Primer problema
10 | - [ ] Segundo problema
11 | - [ ] Tercer problema
12 | - [ ] Cuarto Problema (Opcional)
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # javascript-challenge-03
2 |
3 | # 100tifi.co
4 |
5 | 
6 |
7 | Somos un directorio de personajes de la serie animada "Rick and Morty". Estamos por lanzar nuestra implementación y necesitamos resolver los problemas que presenta nuestra aplicación.
8 |
9 | https://100tifi.co tiene un Bug, al llegar al final del listado de personajes se realiza una petición a la API ya que implementamos un "intersection observer" pero vuelve a obtener los mismos personajes y necesitamos cargar la lista completa de 468 personajes conforme hagamos scroll.
10 |
11 | ### Debug
12 |
13 | Visita el sitio web: https://100tifi.co
14 |
15 | ### Instalación
16 |
17 | ```
18 | npm install
19 | ```
20 |
21 | ### Ejecución
22 |
23 | ```
24 | npm run start
25 | ```
26 |
27 | ### Documentación
28 |
29 |
30 | - Variable llamada $app donde haremos render de nuestra app.
31 | - Elemento del DOM que sera Observado.
32 | - Constante 'API': Utilizamos la API de Rick and Morty.
33 |
34 | ```javascript
35 | const $app = document.getElementById('app');
36 | const $observe = document.getElementById('observe');
37 | const API = 'https://rickandmortyapi.com/api/character/';
38 | ```
39 |
40 | Función llamada 'getData' que se encarga de hacer Fetch a una API y construye un elemento nuevo en el DOM.
41 |
42 | ```javascript
43 | const getData = api => {
44 | fetch(api)
45 | .then(response => response.json())
46 | .then(response => {
47 | const characters = response.results;
48 | let output = characters.map(character => {
49 | return `
50 |
51 |
52 |
${character.name}${character.species}
53 |
54 | `
55 | }).join('');
56 | let newItem = document.createElement('section');
57 | newItem.classList.add('Items');
58 | newItem.innerHTML = output;
59 | $app.appendChild(newItem);
60 | })
61 | .catch(error => console.log(error));
62 | }
63 | ```
64 |
65 | Función encargada de hacer Fetch de los personajes.
66 |
67 | ```javascript
68 | const loadData = () => {
69 | getData(API);
70 | }
71 | ```
72 |
73 | Intersection Observer
74 | ```javascript
75 |
76 | const intersectionObserver = new IntersectionObserver(entries => {
77 | if (entries[0].isIntersecting) {
78 | loadData();
79 | }
80 | }, {
81 | rootMargin: '0px 0px 100% 0px',
82 | });
83 |
84 | intersectionObserver.observe($observe);
85 | ```
86 |
87 |
88 | ## RETO
89 |
90 | ### Primer problema
91 |
92 | 1. Guarda en localStorage la URL de la siguiente petición de personajes obtenida en la primera llamada a la API.
93 | 2. Utiliza el nombre para la llave: 'next_fetch'.
94 | 3. Comprueba que se ha guardado el valor 'next_fetch' en localStorage.
95 |
96 | ### Segundo Problema
97 |
98 | 1. Obten los datos almacenados en localStorage de la llave: 'next_fetch'.
99 | 2. Valida que exista un valor en 'next_fetch' o regresa el primer llamado de la API.
100 | 3. Actualiza la función loadData() a Async/Await.
101 |
102 | ### Tercer Problema
103 |
104 | Cuando cerramos la pestaña o recargamos la pagina se debe de volver a mostrar los primeros 20 personajes.
105 |
106 | 1. Mostrar los primeros 20 personajes al recargar
107 | 2. Eliminar el localStorage.
108 |
109 | ### Cuarto Problema (Opcional)
110 |
111 | La API utilizada "RickAndMortyApi.com" tiene 25 paginas de 20 personajes cada una, cuando la ultima petición sea ejecutada y el valor 'next' no sea entregado debes de mostrar un mensaje "Ya no hay personajes", a su vez debes de destruir el intersection observer.
112 |
113 | 1. Implementar mensaje: "Ya no hay personajes...".
114 | 2. Deja de observar el elemento "observe".
115 |
116 | ### Enviar solución de reto
117 |
118 | Debes de crear un "Fork" de este proyecto, revolver los problemas y crear un Pull Request hacia este repositorio.
119 |
120 | ### Contribuir
121 | Si alguien quiere agregar o mejorar algo, lo invito a colaborar directamente en este repositorio: [javascript-challenge-03](https://github.com/gndx/javascript-challenge-03/)
122 |
123 | ### Licencia
124 | javascript-challenge-03 se lanza bajo la licencia [MIT](https://opensource.org/licenses/MIT).
125 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "javascript-challenge-03",
3 | "version": "1.0.0",
4 | "description": "Reto JavaScript",
5 | "main": "index.js",
6 | "scripts": {
7 | "start": "live-server --open=public --entry-file=index.html"
8 | },
9 | "repository": {
10 | "type": "git",
11 | "url": "git+https://github.com/gndx/javascript-challenge-03.git"
12 | },
13 | "keywords": [],
14 | "author": "Oscar Barajas ",
15 | "license": "ISC",
16 | "bugs": {
17 | "url": "https://github.com/gndx/javascript-challenge-03/issues"
18 | },
19 | "homepage": "https://github.com/gndx/javascript-challenge-03#readme",
20 | "devDependencies": {
21 | "live-server": "^1.2.1"
22 | }
23 | }
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | EscuelaJS Reto 05
9 |
10 |
11 |
12 |
13 |