Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
/* module.exports = {
env: {
browser: true,
es2021: true,
Expand Down Expand Up @@ -60,4 +60,4 @@ module.exports = {
"react/forbid-prop-types": "off",
"react/prop-types": "off",
},
};
}; */
464 changes: 155 additions & 309 deletions package-lock.json

Large diffs are not rendered by default.

17 changes: 3 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"prop-types": "^15.7.2",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-router-dom": "^5.2.0",
"react-router-dom": "^5.3.0",
"react-scripts": "4.0.3",
"sass": "^1.32.11",
"web-vitals": "^1.0.1"
Expand All @@ -44,7 +44,7 @@
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.2.1",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-markdown": "^2.0.0",
"eslint-plugin-markdown": "^2.2.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-react-hooks": "^4.2.0",
Expand All @@ -60,18 +60,7 @@
"eject": "react-scripts eject",
"test:watch": "react-scripts test --watchAll",
"test:ci:all": "cross-env CI=true react-scripts test --all --env=jsdom",
"test:related": "cross-env CI=true react-scripts test --bail --findRelatedTests --env=jsdom",
"lint:js": "eslint . --ext .js",
"lint:js:fix": "npm run lint:js -- --fix",
"lint:format": "prettier --write .",
"lint:format:check": "prettier --check .",
"pre:push": "npm run lint:js && npm run lint:format:check && npm run test:ci:all"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
"test:related": "cross-env CI=true react-scripts test --bail --findRelatedTests --env=jsdom"
},
"browserslist": {
"production": [
Expand Down
1 change: 1 addition & 0 deletions react-shopping-cart-hoc
Submodule react-shopping-cart-hoc added at 44846a
29 changes: 27 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
import React from "react";

import { Route, Switch } from "react-router-dom";
import {
CHARACTER,
EPISODE,
HOME,
LOCATION,
} from "./constants/routes";
import Home from "./pages/Home";
import Episode from "./pages/Episode/Episode";
import Character from "./pages/CharacterPage/Character";
import Location from "./pages/Location/Location";

function App() {
return <Home />;
return (
<>
<Switch>
<Route path={HOME} exact component={Home} />
<Route path={`${EPISODE}/:episodeId`}
render={(routeProps)=><Episode {...routeProps} />}
/>
<Route path={`${CHARACTER}/:characterId`}
render={(routeProps)=><Character {...routeProps} />}
/>
<Route
path={`${LOCATION}/:locationId`}
render={(routeProps) => <Location {...routeProps} />}
/>
</Switch>
</>
);
}

export default App;
143 changes: 143 additions & 0 deletions src/pages/CharacterPage/Character.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import React, { Component } from "react";
import { getCharacter, getEpisode } from "../../utils/axios";
import Layout from "../../components/Layout";
import EpisodeCard from "../../components/EpisodeCard";
import axios from "axios";
class Character extends Component {
constructor(props) {
super(props);
this.state = {
character: {},
episode: [],
hasLoaded: false,
hasError: false,
errorMessage: null,
};
}
async componentDidMount() {
const {
match: { params },
} = this.props;

this.loadCharacter(params.characterId);
}
async loadCharacter(characterId) {
try {
const response = await getCharacter(characterId);
const res = await axios.all(
response.data.episode.map(async (cUrl) => {
const response = await axios(cUrl);
return response.data;
}),
);
this.setState({
character: {
id: response.data.id,
name: response.data.name,
image: response.data.image,
species: response.data.species,
status: response.data.status,
origin: response.data.origin,
location: response.data.location,
},
episode: res,
hasLoaded: true,
});
} catch (error) {
this.setState({
errorMessage: error.message,
hasLoaded: false,
hasError: false,
});
}
}
render() {
const { character, episode, hasLoaded, hasError, errorMessage } = this.state;
return (
<>
<Layout>
{hasLoaded && !hasError && (
<section className="row">
<div className="col col-4">
<img className="h3 Character__img" src={character.image} alt="" />
</div>
<div className="col col-8 d-flex align-items-center">
<div className="row">
<div className="col col-12">
<h1 className="h3">{character.name}</h1>
</div>
<div className="col col-12">
<hr />
</div>
<div className="col col-12">
<div className="d-flex flex-column mb-4">
<p className="mb-0 mr-2 text-uppercase font-weight-bold">
Character
</p>
<div className="d-flex">
<p className="mb-0 mr-2">{character.species}</p>
<p className="mb-0 mr-2">|</p>
<p className="mb-0">{character.status}</p>
</div>
</div>
</div>
<div className="col col-12">
<div className="d-flex">
<div className="d-flex flex-column mr-4">
<p className="mb-0 mr-2 text-uppercase font-weight-bold">
Origin
</p>
<p className="mb-0">{character.origin.name}</p>
</div>
<div className="d-flex flex-column">
<p className="mb-0 mr-2 text-uppercase font-weight-bold">
Location
</p>
<p className="mb-0">{character.location.name}</p>
</div>
</div>
</div>
</div>
</div>
<div className="col col-12">
<hr />
</div>
<div className="col col-12">
<h2 className="h5">Episodes</h2>
</div>
<div className="col col-12">
<hr />
</div>
{episode.length > 0 &&
episode.map((episode) => (
<EpisodeCard
key={episode.id}
id={episode.id}
name={episode.name}
airDate={episode.air_date}
episode={episode.episode}
/>
))}
</section>
)}
{!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>
)}
</Layout>
</>
);
}
}
export default Character;
1 change: 1 addition & 0 deletions src/pages/CharacterPage/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "./Episode";
117 changes: 93 additions & 24 deletions src/pages/Episode/Episode.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,108 @@
import React, { Component } from "react";

import Layout from "../../components/Layout";
// import CharacterCard from "../../components/CharacterCard";

import CharacterCard from "../../components/CharacterCard";
import { getEpisode } from "../../utils/axios";
import axios from "axios";
class Episode extends Component {
constructor(props) {
super(props);

this.state = {};
// episode: null,
// characters: [],
// hasLoaded: false,
// hasError: false,
// errorMessage: null,
this.state = {
episode: null,
characters: [],
hasLoaded: false,
hasError: false,
errorMessage: null,
};
}

async componentDidMount() {
const {
match: { params },
} = this.props;
this.loadEpisode(params.episodeId);
}

async loadEpisode(episodeId) {
try {
const response = await getEpisode(episodeId);
this.setState({
episode: response.data,
hasLoaded: true,
});

const { episode } = this.state;
const res = await axios.all(
episode.characters.map(async (cUrl) => {
const response = await axios(cUrl)
return response.data
}))
this.setState({
characters:res
})
}
catch (error) {
this.setState({
errorMessage: error.message,
hasLoaded:false,
hasError: true,
});
}
}
render() {
const { characters, episode,hasError,hasLoaded} = this.state;
return (
<Layout>
<section className="row">
<div className="col col-12">
{/* {characters.map((character) => (
<CharacterCard
key={character.id}
id={character.id}
name={character.name}
image={character.image}
species={character.species}
status={character.status}
origin={character.origin}
location={character.location}
/>
))} */}
</div>
</section>
{hasLoaded && !hasError && (
<section className="row">
<div className="col col-12">
<h1 className="h3">{episode.name}</h1>
</div>
<div className="col col-12">
<hr />
</div>
<div className="col col-12">
<div className="d-flex">
<p className="mb-0 mr-2">{episode.episode}</p>
<p className="mb-0 mr-2">|</p>
<p className="mb-0">{episode.air_date}</p>
</div>
<div className="col col-12">
<hr />
</div>
</div>
{characters.length > 0 &&
characters.map((character) => (
<CharacterCard
key={character.id}
id={character.id}
name={character.name}
image={character.image}
species={character.species}
status={character.status}
origin={character.origin}
location={character.location}
/>
))}
</section>
)}

{!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>
)}
</Layout>
);
}
Expand Down
Loading