Skip to content

Conversation

@Noiztbander
Copy link

No description provided.

Copy link

@Ethan-Alfaro Ethan-Alfaro left a 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 />;

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.

Copy link
Author

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

Comment on lines +1 to +26
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);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esta parte esta perfecta !

Comment on lines +46 to 90
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,
});
}
}

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";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deberias borrar estos comentarios

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants