generated from assembler-institute/reactjs-project-template
-
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
Open
Noiztbander
wants to merge
4
commits into
assembler-institute:main
Choose a base branch
from
Noiztbander:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,38 @@ | ||
| import React from "react"; | ||
|
|
||
| import { Switch, Route } from "react-router-dom"; | ||
|
|
||
| import { | ||
| CHARACTER, | ||
| EPISODE, | ||
| // EPISODES, | ||
| HOME, | ||
| LOCATION, | ||
| } from "./constants/routes"; | ||
|
|
||
| import Home from "./pages/Home"; | ||
| import Episode from "./pages/Episode"; | ||
| import CharacterPage from "./pages/Character"; | ||
| import LocationPage from "./pages/LocationPage"; | ||
|
|
||
| function App() { | ||
| return <Home />; | ||
| return ( | ||
| <Switch> | ||
| <Route | ||
| path={`${EPISODE}/:episodeId`} | ||
| render={(routeProps) => <Episode {...routeProps} />} | ||
| /> | ||
| <Route | ||
| path={`${CHARACTER}/:characterId`} | ||
| render={(routeProps) => <CharacterPage {...routeProps} />} | ||
| /> | ||
| <Route | ||
| path={`${LOCATION}/:locationId`} | ||
| render={(routeProps) => <LocationPage {...routeProps} />} | ||
| /> | ||
| <Route path={HOME} render={(routeProps) => <Home {...routeProps} />} /> | ||
| </Switch> | ||
| ); | ||
| } | ||
|
|
||
| export default App; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,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); | ||
| } | ||
|
Comment on lines
+1
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Esta parte esta perfecta ! |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from "./api"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| import React, { Component } from "react"; | ||
|
|
||
| import Layout from "../../components/Layout"; | ||
|
|
||
| import { getCharacters, getUrl } from "../../api"; | ||
|
|
||
| import "../../components/CharacterCard/CharacterCard.scss"; | ||
|
|
||
| import EpisodeCard from "../../components/EpisodeCard"; | ||
|
|
||
| import * as routes from "../../constants/routes"; | ||
|
|
||
| function makePromises(urls = []) { | ||
| const myArray = urls.map((url) => getUrl(url)); | ||
| // console.log(myArray); | ||
| return myArray; | ||
| } | ||
|
|
||
| class CharacterPage extends Component { | ||
| constructor(props) { | ||
| super(props); | ||
|
|
||
| this.state = { | ||
| episodes: [], | ||
| name: "", | ||
| image: "", | ||
| species: "", | ||
| status: "", | ||
| origin: "", | ||
| location: "", | ||
| hasLoaded: false, | ||
| hasError: false, | ||
| errorMessage: null, | ||
| }; | ||
| this.loadCharacters = this.loadCharacters.bind(this); | ||
| } | ||
|
|
||
| componentDidMount() { | ||
| // console.log(this); | ||
|
|
||
| const { match } = this.props; | ||
| const { characterId } = match.params; | ||
|
|
||
| // console.log(characterId); | ||
| this.loadCharacters(characterId); | ||
| } | ||
|
|
||
| async loadCharacters(characterId) { | ||
| // console.log(this); | ||
| try { | ||
| const { data } = await getCharacters(characterId); | ||
|
|
||
| // eslint-disable-next-line compat/compat | ||
| const characterEpisodes = await Promise.all( | ||
| makePromises(data.episode), | ||
| ); | ||
|
|
||
| const episodesFromCharacter = characterEpisodes.map((character) => character.data); | ||
|
|
||
| console.log(episodesFromCharacter); | ||
|
|
||
| this.setState({ | ||
| episodes: episodesFromCharacter, | ||
| name: data.name, | ||
| image: data.image, | ||
| species: data.species, | ||
| status: data.status, | ||
| origin: data.origin.name, | ||
| location: data.location.name, | ||
| hasLoaded: true, | ||
| hasError: false, | ||
| errorMessage: null, | ||
|
|
||
| }); | ||
|
|
||
| console.log(data); | ||
| } catch (error) { | ||
| this.setState({ | ||
| hasLoaded: true, | ||
| hasError: true, | ||
| errorMessage: error.message, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| render() { | ||
| const { | ||
| episodes, | ||
| name, | ||
| image, | ||
| species, | ||
| status, | ||
| origin, | ||
| location, | ||
| hasLoaded, | ||
| hasError, | ||
| errorMessage, | ||
| } = this.state; | ||
|
|
||
| return ( | ||
| <Layout> | ||
| <section className="container"> | ||
| {!hasLoaded && ( | ||
| <section className="row"> | ||
| <div className="col col-12"> | ||
| <h1 className="h3">Loading data...</h1> | ||
| </div> | ||
| </section> | ||
| )} | ||
| {hasError && ( | ||
| <section className="row"> | ||
| <div className="col col-12"> | ||
| <h1>Something went wrong...</h1> | ||
| <p>{errorMessage}</p> | ||
| </div> | ||
| </section> | ||
| )} | ||
| <section className="row row-12 row-sm-6 row-xl-3 CharacterCard"> | ||
| <div className="col col-12 col-sm-6 col-xl-3 CharacterCard"> | ||
| <img className="CharacterCard__img" src={image} alt="" /> | ||
| </div> | ||
| <div className="col col-12 col-sm-6 col-xl-3 CharacterCard"> | ||
| <h3 className="CharacterCard__name h4">{name}</h3> | ||
| <hr /> | ||
| <div> | ||
| <h6>CHARACTER</h6> | ||
| <p className="CharacterCard__meta-item"> {species} | {status}</p> | ||
| </div> | ||
| <div className="CharacterCard__meta"> | ||
| <div className="CharacterCard"> | ||
| <h6>ORIGIN</h6> | ||
| <p className="CharacterCard__meta-item">{origin}</p> | ||
| </div> | ||
| <div className="CharacterCard"> | ||
| <h6>LOCATION</h6> | ||
| <p className="CharacterCard__meta-item">{location}</p> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </section> | ||
| <hr /> | ||
| <section className="row"> | ||
| {episodes.length > 0 && | ||
| episodes.map((episode) => ( | ||
| <EpisodeCard | ||
| key={episode.id} | ||
| id={episode.id} | ||
| name={episode.name} | ||
| airDate={episode.air_date} | ||
| episode={episode.episode} | ||
| /> | ||
| ))} | ||
| </section> | ||
| </section> | ||
| </Layout> | ||
| ); | ||
| } | ||
| } | ||
| export default CharacterPage; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default } from "./characterPage"; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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