-
Notifications
You must be signed in to change notification settings - Fork 52
Solution: Erick Noiztbander #14
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
base: main
Are you sure you want to change the base?
Conversation
Ethan-Alfaro
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Por lo general esta bastante bien, pero yo quitaría todos los comentarios innecesarios que tienes, y dejaría solo los explicativos, pero buen trabajo
| import LocationPage from "./pages/LocationPage"; | ||
|
|
||
| function App() { | ||
| return <Home />; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
El primer return creo que no haría falta.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No men hahaha las lineas en rojo son cosas que se han eliminado pero que quedan registradas dentro del git como un "cambio". osea que ese return, en verdad yo no lo tengo en mis lineas. si sale en rojo es precisamente porque esta eliminado ehhehe
| import axios from "axios"; | ||
|
|
||
| export function makeApi() { | ||
| return axios.create({ | ||
| baseURL: "https://rickandmortyapi.com/api", | ||
| timeout: 1000, | ||
| }); | ||
| } | ||
|
|
||
| export function getEpisodes(page = 1, api = makeApi()) { | ||
| return api.get(`/episode?page=${page}`); | ||
| } | ||
|
|
||
| export function getEpisode(episodeId, api = makeApi()) { | ||
| return api.get(`/episode/${episodeId}`); | ||
| } | ||
| export function getCharacters(characterId, api = makeApi()) { | ||
| return api.get(`/character/${characterId}`); | ||
| } | ||
| export function getLocation(locationId, api = makeApi()) { | ||
| return api.get(`/location/${locationId}`); | ||
| } | ||
|
|
||
| export function getUrl(url, api = makeApi()) { | ||
| return api.get(url); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Esta parte esta perfecta !
| async loadEpisode(episodeId) { | ||
| // console.log(this); | ||
| /* | ||
| * Aquí lo que hacemos es encapsular dentro de DATA, toda la informacion | ||
| * del episodio que nos traemos del API | ||
| */ | ||
|
|
||
| try { | ||
| const { data } = await getEpisode(episodeId); | ||
| /* | ||
| * Esta funcion nos llama a otra funcion que dentro nos devuelve un Array mediante un map | ||
| * en la siguiente variante, haremos lo mismo pero de forma manual (NO RECOMENDABLE) | ||
| */ | ||
| // eslint-disable-next-line compat/compat | ||
| const characterResponse = await Promise.all( | ||
| makePromises(data.characters), | ||
| ); | ||
|
|
||
| // const promises = data.characters.map((character) => axios.get(character)); | ||
|
|
||
| /* | ||
| * Ademas, axios, siempre nos devuelve las propiedades que necesitamos dentro de un objeto y dentro del objeto en DATA. | ||
| * para solucionarlo, debemos recorrer cada objeto, sacando ese DATA y guardandolo | ||
| * en un nuevo array con ese contenido. | ||
| */ | ||
| const characters = characterResponse.map((character) => character.data); | ||
|
|
||
| this.setState({ | ||
| hasLoaded: true, | ||
| episode: data, | ||
| characters: characters, | ||
| }); | ||
|
|
||
| // console.log(data); | ||
| // console.log(characterResponse); | ||
| // console.log(promises); | ||
| // console.log(characters); | ||
| } catch (error) { | ||
| this.setState({ | ||
| hasLoaded: true, | ||
| hasError: true, | ||
| errorMessage: error.message, | ||
| }); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creo que toda esta parte la podrias haber echo de manera mas sencilla usando axios
| import { getEpisodes } from "../../api"; | ||
|
|
||
| import Layout from "../../components/Layout"; | ||
| // import EpisodeCard from "../../components/EpisodeCard"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deberias borrar estos comentarios
No description provided.