From 25a956b89b684771c5442cd8a781e000b51c7168 Mon Sep 17 00:00:00 2001
From: skutterbob <37837675+skutterbob@users.noreply.github.com>
Date: Fri, 24 Sep 2021 13:21:20 +0100
Subject: [PATCH 1/3] Split into individual component files
---
src/Pokedex.js | 592 +-----------------------------------------
src/PokedexCard.js | 68 +++++
src/Pokemon.js | 245 +++++++++++++++++
src/PokemonAbility.js | 68 +++++
src/PokemonType.js | 153 +++++++++++
src/SinglePokedex.js | 125 +++++++++
6 files changed, 661 insertions(+), 590 deletions(-)
create mode 100644 src/PokedexCard.js
create mode 100644 src/Pokemon.js
create mode 100644 src/PokemonAbility.js
create mode 100644 src/PokemonType.js
create mode 100644 src/SinglePokedex.js
diff --git a/src/Pokedex.js b/src/Pokedex.js
index 6aedfef..6d9bbeb 100644
--- a/src/Pokedex.js
+++ b/src/Pokedex.js
@@ -1,32 +1,11 @@
import React from 'react';
import {
- Box,
- Button,
Center,
- Drawer,
- DrawerBody,
- DrawerHeader,
- DrawerOverlay,
- DrawerContent,
- DrawerCloseButton,
Flex,
- Image,
- Modal,
- ModalOverlay,
- ModalContent,
- ModalHeader,
- ModalBody,
- ModalCloseButton,
- ModalFooter,
- Stat,
- StatLabel,
- StatNumber,
- StatGroup,
} from '@chakra-ui/react';
import Utilities from './Utilities.js';
import { Pokeball } from './Pokeball.js';
-import typeImages from './images.js';
-import pokemonImages from './pokemonImages.js';
+import PokedexCard from './PokedexCard.js';
@@ -72,7 +51,7 @@ class Pokedex extends React.Component {
{this.state.pokedexes.map(dex => (
-
+
))}
)
@@ -83,573 +62,6 @@ class Pokedex extends React.Component {
}
}
-class SinglePokedexCard extends React.Component {
-
- constructor(props) {
- super(props);
- this.state = {
- name: props.name,
- url: props.url,
- isModalOpen: false,
- }
- }
-
- openModal = () => {
- this.setState({ isModalOpen: true })
- }
-
- closeModal = () => {
- this.setState({ isModalOpen: false })
- }
-
- render() {
-
- return (
-
- <>
-
-
-
-
-
-
-
- {this.props.name}
-
-
-
-
-
-
-
-
- >
-
- );
- }
-}
-
-class SinglePokedex extends React.Component {
-
- constructor(props) {
- super(props);
- this.state = {
- loading: true,
- isDrawerOpen: false,
- name: props.name,
- url: props.url,
- desc: "",
- pokemon_entries: [],
- selectedPokemonName: "",
- selectedPokemonUrl: "",
- }
- }
-
- openDrawer = (name, url) => {
- this.setState({selectedPokemonName: name, selectedPokemonUrl: url});
- this.setState({ isDrawerOpen: true });
- }
-
- closeDrawer = () => {
- this.setState({ isDrawerOpen: false })
- }
-
- async componentDidMount() {
- try {
- const singlePokedexRequest = await fetch(this.props.url).then(Utilities.checkResponse);
- const singlePokedexJson = await singlePokedexRequest.json();
-
- let pokedexDescription = "";
-
- for (let i = 0; i < singlePokedexJson.descriptions.length; i++) {
-
- if (singlePokedexJson.descriptions[i].language.name === "en") {
- pokedexDescription = singlePokedexJson.descriptions[i].description;
-
- }
- }
- let entries = [];
- for (let i = 0; i < singlePokedexJson.pokemon_entries.length; i++) {
- let pokemon = singlePokedexJson.pokemon_entries[i].pokemon_species;
- entries.push([pokemon.name, pokemon.url]);
- }
-
- this.setState({pokemon_entries: entries, desc: pokedexDescription, loading: false});
- } catch(e) {
- console.log(e);
- }
-
- }
-
- render() {
-
-
-
- return(
- <>
-
- {this.state.loading ? () : (
- <>
- {this.state.desc}
-
-
-
-
- {this.state.pokemon_entries.map(pokemon => (
-
- ))}
-
-
-
-
-
-
-
-
-
-
-
- {Utilities.formatName(this.state.selectedPokemonName)}
-
-
-
-
-
-
-
-
- >
-
- )}
-
- >
- );
- }
-}
-
-class Pokemon extends React.Component {
-
- constructor(props) {
- super(props);
- this.state = {
- loading: true,
- isAbilityModalOpen: false,
- isTypeModalOpen: false,
- name: "",
- url: "",
- pokedexUrl: "",
- id: 0,
- varieties: [],
- desc: "",
- types: [],
- color: "",
- height: 0,
- weight: 0,
- abilities: [],
- evolvesFrom: "",
- habitat: "",
- isMythical: false,
- isLegendary: false,
- stats: [],
- selectedAbility: "",
- selectedType: ""
- }
- }
-
-
- openAbilityModal = (url) => {
- this.setState({ selectedAbility: url })
- this.setState({ isAbilityModalOpen: true })
- }
-
- closeAbilityModal = () => {
- this.setState({ isAbilityModalOpen: false })
- }
-
- openTypeModal = (url) => {
- this.setState({ selectedType: url })
- this.setState({ isTypeModalOpen: true })
- }
-
- closeTypeModal = () => {
- this.setState({ isTypeModalOpen: false })
- }
-
- async componentDidMount() {
- const pokemonUrl = "https://pokeapi.co/api/v2/pokemon/";
- try {
- const speciesRequest = await fetch(this.props.url).then(Utilities.checkResponse);
- const speciesJson = await speciesRequest.json();
-
- let speciesIdArray = this.props.url.split("/");
- let speciesId = speciesIdArray[6];
-
- let varietiesData = [];
- for (let i = 0; i < speciesJson.varieties.length; i++) {
- varietiesData.push(speciesJson.varieties[i]);
- }
-
- let descData = "";
- for (let i = 0; i < speciesJson.flavor_text_entries.length; i++) {
- if (speciesJson.flavor_text_entries[i].language.name === "en") {
- descData = speciesJson.flavor_text_entries[i].flavor_text;
- }
- }
-
- let colorData = "";
- if (speciesJson.color) {
- colorData = speciesJson.color.name;
- }
-
- let evolvesFromData = "";
- if (speciesJson.evolves_from_species) {
- evolvesFromData = speciesJson.evolves_from_species.name;
- }
-
- let habitatData = "";
- if (speciesJson.habitat) {
- habitatData = speciesJson.habitat.name;
- }
-
- let isMythicalData = speciesJson.is_mythical;
- let isLegendaryData = speciesJson.is_legendary;
-
- const pokemonRequest = await fetch(pokemonUrl + speciesId).then(Utilities.checkResponse);
- const pokemonJson = await pokemonRequest.json();
-
- let typesData = [];
- for (let i = 0; i < pokemonJson.types.length; i++) {
- typesData.push([pokemonJson.types[i].type.name, pokemonJson.types[i].type.url]);
- }
-
- let heightData = pokemonJson.height;
- let weightData = pokemonJson.weight;
-
- let abilitiesData = [];
- for (let i = 0; i < pokemonJson.abilities.length; i++) {
- abilitiesData.push([pokemonJson.abilities[i].ability.name, pokemonJson.abilities[i].ability.url]);
- }
-
- let statsData = {};
- for (let i = 0; i < pokemonJson.stats.length; i++) {
- statsData[pokemonJson.stats[i].stat.name] = pokemonJson.stats[i].base_stat;
- }
-
-
-
- this.setState({
- id: speciesId,
- varieties: varietiesData,
- desc: descData,
- types: typesData,
- color: colorData,
- height: heightData,
- weight: weightData,
- abilities: abilitiesData,
- evolvesFrom: evolvesFromData,
- habitat: habitatData,
- isMythical: isMythicalData,
- isLegendary: isLegendaryData,
- stats: statsData,
- loading: false
- });
-
-
- } catch(e) {
- console.log(e);
- }
- }
-
- render() {
-
-
-
- return (
- <>
-
- {this.state.loading ? () : (
-
- <>
-
-
- {this.state.desc}
-
-
-
-
- Abilities:
-
-
- {this.state.abilities.map(ability => (
-
- ))}
-
-
-
-
- {this.state.types.map(pType => (
-
- ))}
-
-
-
-
- Height
- {Utilities.calculatePokemonHeight(this.state.height)}
-
-
-
- Weight
- {Utilities.calculatePokemonWeight(this.state.weight)}
-
-
-
-
- {(this.state.habitat === "") ? "" : "Habitat: " + (Utilities.formatName(this.state.habitat))}
-
-
-
- {(this.state.evolvesFrom === "") ? "" : "Evolves from: " + (Utilities.formatName(this.state.evolvesFrom))}
-
-
-
-
-
- {/* Abilities Modal */}
-
-
-
-
-
-
-
-
-
- {/* Types Modal */}
-
-
-
-
-
-
-
-
-
- >
-
- )}
-
- >
- );
- }
-}
-
-class PokemonType extends React.Component {
-
- constructor(props) {
- super(props);
-
- this.state = {
- loading: true,
- name: "",
- url: props.url,
- doubleDamageFrom: [],
- doubleDamageTo: [],
- halfDamageFrom: [],
- halfDamageTo: [],
- noDamageFrom: [],
- noDamageTo: [],
- };
- }
-
- async componentDidMount() {
- const typeRequest = await fetch(this.props.url).then(Utilities.checkResponse);
- const typeJson = await typeRequest.json();
-
- let nameData = typeJson.name;
-
- let damageRelationsData = typeJson.damage_relations;
-
- this.setState({
- name: nameData,
- doubleDamageFrom: damageRelationsData.double_damage_from,
- doubleDamageTo: damageRelationsData.double_damage_to,
- halfDamageFrom: damageRelationsData.half_damage_from,
- halfDamageTo: damageRelationsData.half_damage_to,
- noDamageFrom: damageRelationsData.no_damage_from,
- noDamageTo: damageRelationsData.no_damage_to,
- loading: false,
- });
- }
-
- render() {
- const prefix = "m_";
-
- return (
- <>
- {this.state.loading ? () : (
- <>
- {Utilities.formatName(this.state.name)}
-
-
-
-
- Double damage from:
-
- {this.state.doubleDamageFrom.length > 0 ? (
- this.state.doubleDamageFrom.map(pType => (
-
-
-
- ))
- ) : (None
)}
-
-
-
-
- Double damage to:
-
- {this.state.doubleDamageTo.length > 0 ? (
- this.state.doubleDamageTo.map(pType => (
-
-
-
- ))
- ) : (None
)}
-
-
-
-
- Half damage from:
-
- {this.state.halfDamageFrom.length > 0 ? (
- this.state.halfDamageFrom.map(pType => (
-
-
-
- ))
- ) : (None
)}
-
-
-
-
- Half damage to:
-
- {this.state.halfDamageTo.length > 0 ? (
- this.state.halfDamageTo.map(pType => (
-
-
-
- ))
- ) : (None
)}
-
-
-
-
- No damage from:
-
- {this.state.noDamageFrom.length > 0 ? (
- this.state.noDamageFrom.map(pType => (
-
-
-
- ))
- ) : (None
)}
-
-
-
-
- No damage to:
-
- {this.state.noDamageTo.length > 0 ? (
- this.state.noDamageTo.map(pType => (
-
-
-
- ))
- ) : (None
)}
-
-
-
-
-
- >
- )}
- >
- )
- }
-}
-
-class Ability extends React.Component {
- constructor(props) {
- super(props);
-
- this.state = {
- loading: true,
- name: props.name,
- url: props.url,
- description: "",
- };
- }
-
-
- async componentDidMount() {
- const abilityRequest = await fetch(this.props.url).then(Utilities.checkResponse);
- const abilityJson = await abilityRequest.json();
-
- let nameData = abilityJson.name;
- let descriptionData = "";
-
- for (let i = 0; i < abilityJson.flavor_text_entries.length; i++) {
- if (abilityJson.flavor_text_entries[i].language.name === 'en')
- descriptionData = abilityJson.flavor_text_entries[i].flavor_text;
- }
-
- this.setState({
- name: nameData,
- description: descriptionData,
- loading: false
-
- });
- }
-
- render() {
-
- return (
- <>
- {this.state.loading ? () : (
- <>
- {Utilities.formatName(this.state.name)}
-
-
-
- {this.state.description}
-
-
-
- >
- )}
- >
-
- )
-
- }
-}
export default Pokedex;
\ No newline at end of file
diff --git a/src/PokedexCard.js b/src/PokedexCard.js
new file mode 100644
index 0000000..34cf8b3
--- /dev/null
+++ b/src/PokedexCard.js
@@ -0,0 +1,68 @@
+import React from 'react';
+import {
+ Box,
+ Button,
+ Flex,
+ Modal,
+ ModalOverlay,
+ ModalContent,
+ ModalHeader,
+ ModalBody,
+ ModalCloseButton,
+} from '@chakra-ui/react';
+import { Pokeball } from './Pokeball.js';
+import SinglePokedex from './SinglePokedex.js';
+
+class PokedexCard extends React.Component {
+
+ constructor(props) {
+ super(props);
+ this.state = {
+ name: props.name,
+ url: props.url,
+ isModalOpen: false,
+ }
+ }
+
+ openModal = () => {
+ this.setState({ isModalOpen: true })
+ }
+
+ closeModal = () => {
+ this.setState({ isModalOpen: false })
+ }
+
+ render() {
+
+ return (
+
+ <>
+
+
+
+
+
+
+
+ {this.props.name}
+
+
+
+
+
+
+
+
+ >
+
+ );
+ }
+}
+
+
+export default PokedexCard;
\ No newline at end of file
diff --git a/src/Pokemon.js b/src/Pokemon.js
new file mode 100644
index 0000000..eb32705
--- /dev/null
+++ b/src/Pokemon.js
@@ -0,0 +1,245 @@
+import React from 'react';
+import {
+ Box,
+ Button,
+ Center,
+ Flex,
+ Image,
+ Modal,
+ ModalOverlay,
+ ModalContent,
+ Stat,
+ StatLabel,
+ StatNumber,
+ StatGroup,
+} from '@chakra-ui/react';
+import Utilities from './Utilities.js';
+import { Pokeball } from './Pokeball.js';
+import typeImages from './images.js';
+import pokemonImages from './pokemonImages.js';
+
+import PokemonAbility from './PokemonAbility.js';
+import PokemonType from './PokemonType.js';
+
+class Pokemon extends React.Component {
+
+ constructor(props) {
+ super(props);
+ this.state = {
+ loading: true,
+ isAbilityModalOpen: false,
+ isTypeModalOpen: false,
+ name: "",
+ url: "",
+ pokedexUrl: "",
+ id: 0,
+ varieties: [],
+ desc: "",
+ types: [],
+ color: "",
+ height: 0,
+ weight: 0,
+ abilities: [],
+ evolvesFrom: "",
+ habitat: "",
+ isMythical: false,
+ isLegendary: false,
+ stats: [],
+ selectedAbility: "",
+ selectedType: ""
+ }
+ }
+
+
+ openAbilityModal = (url) => {
+ this.setState({ selectedAbility: url })
+ this.setState({ isAbilityModalOpen: true })
+ }
+
+ closeAbilityModal = () => {
+ this.setState({ isAbilityModalOpen: false })
+ }
+
+ openTypeModal = (url) => {
+ this.setState({ selectedType: url })
+ this.setState({ isTypeModalOpen: true })
+ }
+
+ closeTypeModal = () => {
+ this.setState({ isTypeModalOpen: false })
+ }
+
+ async componentDidMount() {
+ const pokemonUrl = "https://pokeapi.co/api/v2/pokemon/";
+ try {
+ const speciesRequest = await fetch(this.props.url).then(Utilities.checkResponse);
+ const speciesJson = await speciesRequest.json();
+
+ let speciesIdArray = this.props.url.split("/");
+ let speciesId = speciesIdArray[6];
+
+ let varietiesData = [];
+ for (let i = 0; i < speciesJson.varieties.length; i++) {
+ varietiesData.push(speciesJson.varieties[i]);
+ }
+
+ let descData = "";
+ for (let i = 0; i < speciesJson.flavor_text_entries.length; i++) {
+ if (speciesJson.flavor_text_entries[i].language.name === "en") {
+ descData = speciesJson.flavor_text_entries[i].flavor_text;
+ }
+ }
+
+ let colorData = "";
+ if (speciesJson.color) {
+ colorData = speciesJson.color.name;
+ }
+
+ let evolvesFromData = "";
+ if (speciesJson.evolves_from_species) {
+ evolvesFromData = speciesJson.evolves_from_species.name;
+ }
+
+ let habitatData = "";
+ if (speciesJson.habitat) {
+ habitatData = speciesJson.habitat.name;
+ }
+
+ let isMythicalData = speciesJson.is_mythical;
+ let isLegendaryData = speciesJson.is_legendary;
+
+ const pokemonRequest = await fetch(pokemonUrl + speciesId).then(Utilities.checkResponse);
+ const pokemonJson = await pokemonRequest.json();
+
+ let typesData = [];
+ for (let i = 0; i < pokemonJson.types.length; i++) {
+ typesData.push([pokemonJson.types[i].type.name, pokemonJson.types[i].type.url]);
+ }
+
+ let heightData = pokemonJson.height;
+ let weightData = pokemonJson.weight;
+
+ let abilitiesData = [];
+ for (let i = 0; i < pokemonJson.abilities.length; i++) {
+ abilitiesData.push([pokemonJson.abilities[i].ability.name, pokemonJson.abilities[i].ability.url]);
+ }
+
+ let statsData = {};
+ for (let i = 0; i < pokemonJson.stats.length; i++) {
+ statsData[pokemonJson.stats[i].stat.name] = pokemonJson.stats[i].base_stat;
+ }
+
+
+
+ this.setState({
+ id: speciesId,
+ varieties: varietiesData,
+ desc: descData,
+ types: typesData,
+ color: colorData,
+ height: heightData,
+ weight: weightData,
+ abilities: abilitiesData,
+ evolvesFrom: evolvesFromData,
+ habitat: habitatData,
+ isMythical: isMythicalData,
+ isLegendary: isLegendaryData,
+ stats: statsData,
+ loading: false
+ });
+
+
+ } catch(e) {
+ console.log(e);
+ }
+ }
+
+ render() {
+
+
+
+ return (
+ <>
+
+ {this.state.loading ? () : (
+
+ <>
+
+
+ {this.state.desc}
+
+
+
+
+ Abilities:
+
+
+ {this.state.abilities.map(ability => (
+
+ ))}
+
+
+
+
+ {this.state.types.map(pType => (
+
+ ))}
+
+
+
+
+ Height
+ {Utilities.calculatePokemonHeight(this.state.height)}
+
+
+
+ Weight
+ {Utilities.calculatePokemonWeight(this.state.weight)}
+
+
+
+
+ {(this.state.habitat === "") ? "" : "Habitat: " + (Utilities.formatName(this.state.habitat))}
+
+
+
+ {(this.state.evolvesFrom === "") ? "" : "Evolves from: " + (Utilities.formatName(this.state.evolvesFrom))}
+
+
+
+
+
+ {/* Abilities Modal */}
+
+
+
+
+
+
+
+
+
+ {/* Types Modal */}
+
+
+
+
+
+
+
+
+
+ >
+
+ )}
+
+ >
+ );
+ }
+}
+
+export default Pokemon;
\ No newline at end of file
diff --git a/src/PokemonAbility.js b/src/PokemonAbility.js
new file mode 100644
index 0000000..b7bf153
--- /dev/null
+++ b/src/PokemonAbility.js
@@ -0,0 +1,68 @@
+import React from 'react';
+import {
+ Center,
+ ModalHeader,
+ ModalBody,
+ ModalCloseButton,
+ ModalFooter,
+} from '@chakra-ui/react';
+import Utilities from './Utilities.js';
+import { Pokeball } from './Pokeball.js';
+
+class PokemonAbility extends React.Component {
+ constructor(props) {
+ super(props);
+
+ this.state = {
+ loading: true,
+ name: props.name,
+ url: props.url,
+ description: "",
+ };
+ }
+
+
+ async componentDidMount() {
+ const abilityRequest = await fetch(this.props.url).then(Utilities.checkResponse);
+ const abilityJson = await abilityRequest.json();
+
+ let nameData = abilityJson.name;
+ let descriptionData = "";
+
+ for (let i = 0; i < abilityJson.flavor_text_entries.length; i++) {
+ if (abilityJson.flavor_text_entries[i].language.name === 'en')
+ descriptionData = abilityJson.flavor_text_entries[i].flavor_text;
+ }
+
+ this.setState({
+ name: nameData,
+ description: descriptionData,
+ loading: false
+
+ });
+ }
+
+ render() {
+
+ return (
+ <>
+ {this.state.loading ? () : (
+ <>
+ {Utilities.formatName(this.state.name)}
+
+
+
+ {this.state.description}
+
+
+
+ >
+ )}
+ >
+
+ )
+
+ }
+}
+
+export default PokemonAbility;
\ No newline at end of file
diff --git a/src/PokemonType.js b/src/PokemonType.js
new file mode 100644
index 0000000..7cd5767
--- /dev/null
+++ b/src/PokemonType.js
@@ -0,0 +1,153 @@
+import React from 'react';
+import {
+ Box,
+ Center,
+ Flex,
+ Image,
+ ModalHeader,
+ ModalBody,
+ ModalCloseButton,
+ ModalFooter,
+} from '@chakra-ui/react';
+import Utilities from './Utilities.js';
+import { Pokeball } from './Pokeball.js';
+import typeImages from './images.js';
+
+class PokemonType extends React.Component {
+
+ constructor(props) {
+ super(props);
+
+ this.state = {
+ loading: true,
+ name: "",
+ url: props.url,
+ doubleDamageFrom: [],
+ doubleDamageTo: [],
+ halfDamageFrom: [],
+ halfDamageTo: [],
+ noDamageFrom: [],
+ noDamageTo: [],
+ };
+ }
+
+ async componentDidMount() {
+ const typeRequest = await fetch(this.props.url).then(Utilities.checkResponse);
+ const typeJson = await typeRequest.json();
+
+ let nameData = typeJson.name;
+
+ let damageRelationsData = typeJson.damage_relations;
+
+ this.setState({
+ name: nameData,
+ doubleDamageFrom: damageRelationsData.double_damage_from,
+ doubleDamageTo: damageRelationsData.double_damage_to,
+ halfDamageFrom: damageRelationsData.half_damage_from,
+ halfDamageTo: damageRelationsData.half_damage_to,
+ noDamageFrom: damageRelationsData.no_damage_from,
+ noDamageTo: damageRelationsData.no_damage_to,
+ loading: false,
+ });
+ }
+
+ render() {
+ const prefix = "m_";
+
+ return (
+ <>
+ {this.state.loading ? () : (
+ <>
+ {Utilities.formatName(this.state.name)}
+
+
+
+
+ Double damage from:
+
+ {this.state.doubleDamageFrom.length > 0 ? (
+ this.state.doubleDamageFrom.map(pType => (
+
+
+
+ ))
+ ) : (None
)}
+
+
+
+
+ Double damage to:
+
+ {this.state.doubleDamageTo.length > 0 ? (
+ this.state.doubleDamageTo.map(pType => (
+
+
+
+ ))
+ ) : (None
)}
+
+
+
+
+ Half damage from:
+
+ {this.state.halfDamageFrom.length > 0 ? (
+ this.state.halfDamageFrom.map(pType => (
+
+
+
+ ))
+ ) : (None
)}
+
+
+
+
+ Half damage to:
+
+ {this.state.halfDamageTo.length > 0 ? (
+ this.state.halfDamageTo.map(pType => (
+
+
+
+ ))
+ ) : (None
)}
+
+
+
+
+ No damage from:
+
+ {this.state.noDamageFrom.length > 0 ? (
+ this.state.noDamageFrom.map(pType => (
+
+
+
+ ))
+ ) : (None
)}
+
+
+
+
+ No damage to:
+
+ {this.state.noDamageTo.length > 0 ? (
+ this.state.noDamageTo.map(pType => (
+
+
+
+ ))
+ ) : (None
)}
+
+
+
+
+
+ >
+ )}
+ >
+ )
+ }
+}
+
+
+export default PokemonType;
\ No newline at end of file
diff --git a/src/SinglePokedex.js b/src/SinglePokedex.js
new file mode 100644
index 0000000..e989b8f
--- /dev/null
+++ b/src/SinglePokedex.js
@@ -0,0 +1,125 @@
+import React from 'react';
+import {
+ Box,
+ Button,
+ Center,
+ Drawer,
+ DrawerBody,
+ DrawerHeader,
+ DrawerOverlay,
+ DrawerContent,
+ DrawerCloseButton,
+ Flex,
+ Image,
+} from '@chakra-ui/react';
+import Utilities from './Utilities.js';
+import { Pokeball } from './Pokeball.js';
+import pokemonImages from './pokemonImages.js';
+
+import Pokemon from './Pokemon.js';
+
+class SinglePokedex extends React.Component {
+
+ constructor(props) {
+ super(props);
+ this.state = {
+ loading: true,
+ isDrawerOpen: false,
+ name: props.name,
+ url: props.url,
+ desc: "",
+ pokemon_entries: [],
+ selectedPokemonName: "",
+ selectedPokemonUrl: "",
+ }
+ }
+
+ openDrawer = (name, url) => {
+ this.setState({selectedPokemonName: name, selectedPokemonUrl: url});
+ this.setState({ isDrawerOpen: true });
+ }
+
+ closeDrawer = () => {
+ this.setState({ isDrawerOpen: false })
+ }
+
+ async componentDidMount() {
+ try {
+ const singlePokedexRequest = await fetch(this.props.url).then(Utilities.checkResponse);
+ const singlePokedexJson = await singlePokedexRequest.json();
+
+ let pokedexDescription = "";
+
+ for (let i = 0; i < singlePokedexJson.descriptions.length; i++) {
+
+ if (singlePokedexJson.descriptions[i].language.name === "en") {
+ pokedexDescription = singlePokedexJson.descriptions[i].description;
+
+ }
+ }
+ let entries = [];
+ for (let i = 0; i < singlePokedexJson.pokemon_entries.length; i++) {
+ let pokemon = singlePokedexJson.pokemon_entries[i].pokemon_species;
+ entries.push([pokemon.name, pokemon.url]);
+ }
+
+ this.setState({pokemon_entries: entries, desc: pokedexDescription, loading: false});
+ } catch(e) {
+ console.log(e);
+ }
+
+ }
+
+ render() {
+
+
+
+ return(
+ <>
+
+ {this.state.loading ? () : (
+ <>
+ {this.state.desc}
+
+
+
+
+ {this.state.pokemon_entries.map(pokemon => (
+
+ ))}
+
+
+
+
+
+
+
+
+
+
+
+ {Utilities.formatName(this.state.selectedPokemonName)}
+
+
+
+
+
+
+
+
+ >
+
+ )}
+
+ >
+ );
+ }
+}
+
+export default SinglePokedex;
\ No newline at end of file
From c405ca7444509c5186d91b9149e0b97d0b20e73f Mon Sep 17 00:00:00 2001
From: skutterbob <37837675+skutterbob@users.noreply.github.com>
Date: Sat, 25 Sep 2021 12:26:50 +0100
Subject: [PATCH 2/3] Implement custom theme
---
src/App.js | 2 +-
src/PokedexCard.js | 2 +-
src/theme.js | 24 ++++++++++++++++++++++++
3 files changed, 26 insertions(+), 2 deletions(-)
create mode 100644 src/theme.js
diff --git a/src/App.js b/src/App.js
index d483825..a56931a 100644
--- a/src/App.js
+++ b/src/App.js
@@ -2,8 +2,8 @@ import React from 'react';
import {
ChakraProvider,
Box,
- theme,
} from '@chakra-ui/react';
+import theme from './theme.js';
import Pokedex from './Pokedex.js';
diff --git a/src/PokedexCard.js b/src/PokedexCard.js
index 34cf8b3..d3ea21d 100644
--- a/src/PokedexCard.js
+++ b/src/PokedexCard.js
@@ -37,7 +37,7 @@ class PokedexCard extends React.Component {
return (
<>
-