Skip to content

Commit

Permalink
Updated frontend only to use actual pokemon
Browse files Browse the repository at this point in the history
  • Loading branch information
asif4318 committed Jun 18, 2023
1 parent 11e5b08 commit b4c755d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 29 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
frontend/.firebase/hosting.YnVpbGQ.cache
.DS_Store
frontend/.firebase/hosting.YnVpbGQ.cache
frontend/.firebase/*
.DS_Store
2 changes: 1 addition & 1 deletion backend
9 changes: 1 addition & 8 deletions frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,12 @@ function App() {
fetch(
`https://asifislam510.pythonanywhere.com/${searchMethod}/moves?name=${searchText}`
)
.then((res) => res.json()) // Convert API to json
.then((res) => res.json()) // Convert API response to json
.then((data) => {
// Parse data
if (data.status !== 400) {
let tempList = data.pokemon.split("\n");

//Split the names and update array
for (let i = 0; i < tempList.length; i++) {
const wordRegex = /[A-Z}[a-z[A-Z]?[a-z\-]+|[0-9]+|[A-Z]/gm;
const string = tempList[i];
const result = string.match(wordRegex);
tempList[i] = result[0] + " " + result[1];
}
// Update count and fetch time
setResultsCount(data.count);
setFetchTime(data.time);
Expand Down
7 changes: 2 additions & 5 deletions frontend/src/components/PokedexEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ const PokedexEntry = () => {

// Fetch the list of moves from backend api
const fetchMove = () => {
const searchName =
state.pokemon_name.split(" ")[0] + state.pokemon_name.split(" ")[1];
const searchName = state.pokemon_name;
const url =
`https://asifislam510.pythonanywhere.com/${searchMethod}/pokemon?name=` +
searchName;
Expand Down Expand Up @@ -60,9 +59,7 @@ const PokedexEntry = () => {

// split names (Ex: pikachuAlan => Pikachu Alan)
const getFormattedName = (pokemon_name) => {
const fname = pokemon_name.split(" ")[0];
const upperCase = fname.substring(0, 1).toUpperCase() + fname.substring(1);
return upperCase + " " + pokemon_name.split(" ")[1];
return capitalize(pokemon_name);
};

// Capitalize the first letter of the word
Expand Down
16 changes: 4 additions & 12 deletions frontend/src/components/PokemonCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,9 @@ const PokemonCard = ({ pokemon_name }) => {
}
};

const capitalizeName = (nameToCapitalize) => {
try {
const temp = nameToCapitalize.split(" ");
const firstName = temp[0].charAt(0).toUpperCase() + temp[0].slice(1);
const lastName = temp[1];
return `${firstName} ${lastName}`;
} catch (error) {
console.log("Error: name undefined");
return "";
}
};
// Capitalize the first letter of the word
const capitalize = (word) =>
word.substring(0, 1).toUpperCase() + word.substring(1);

useEffect(() => {
getSprite();
Expand All @@ -47,7 +39,7 @@ const PokemonCard = ({ pokemon_name }) => {
to={`/card/${pokemon_name}`}
state={{ pokemon_name: pokemon_name }}
>
{capitalizeName(pokemon_name)}
{capitalize(pokemon_name)}
</Link>
</h2>
<img
Expand Down

0 comments on commit b4c755d

Please sign in to comment.