-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0fc6458
commit 3a6e5db
Showing
14 changed files
with
826 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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
27 changes: 27 additions & 0 deletions
27
full-stack-javascript/21-inventory-application/client/src/components/PokeDetails.jsx
This file contains 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,27 @@ | ||
import { useParams } from "react-router-dom"; | ||
|
||
function PokeDetails() { | ||
const params = useParams(); | ||
const endpoint = "http://localhost:3000/pokemon/" + params.pokemonId; | ||
async function fetchPokemon() { | ||
try { | ||
const response = await fetch(endpoint); | ||
const result = await response.json(); | ||
|
||
console.log(result); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
} | ||
|
||
fetchPokemon(); | ||
|
||
return ( | ||
<div> | ||
<div>Main Details</div> | ||
<div>Pokemon: {params.pokemonId}</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default PokeDetails; |
This file contains 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
4 changes: 2 additions & 2 deletions
4
...ion/client/src/components/PokemonType.jsx → ...cation/client/src/components/PokeType.jsx
This file contains 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,11 +1,11 @@ | ||
import pokemonTypes from "../utils/pokemonTypes"; | ||
|
||
function PokemonType({ type }) { | ||
function PokeType({ type }) { | ||
const typeColor = pokemonTypes[type.toLowerCase()]; | ||
const classes = | ||
"min-w-12 rounded-xl px-2 py-1 text-center text-xs font-bold text-white "; | ||
|
||
return <span className={classes + typeColor}>{type}</span>; | ||
} | ||
|
||
export default PokemonType; | ||
export default PokeType; |
This file contains 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 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 @@ | ||
node_modules |
22 changes: 12 additions & 10 deletions
22
full-stack-javascript/21-inventory-application/server/app.js
This file contains 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 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
20 changes: 20 additions & 0 deletions
20
full-stack-javascript/21-inventory-application/server/models/pokeDetails.js
This file contains 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,20 @@ | ||
const mongoose = require("mongoose"); | ||
|
||
const Schema = mongoose.Schema; | ||
|
||
const PokeDetailsSchema = new Schema({ | ||
height: { type: String, required: true }, | ||
weight: { type: Number, required: true }, | ||
has_gender: { type: Boolean, required: true }, | ||
hp: { type: Number, required: true }, | ||
attack: { type: Number, required: true }, | ||
defense: { type: Number, required: true }, | ||
specialAttack: { type: Number, required: true }, | ||
specialDefense: { type: Number, required: true }, | ||
speed: { type: Number, required: true }, | ||
abilities: [{ type: String }], | ||
evolvesTo: [{ type: Schema.Types.ObjectId, ref: "Pokemon" }], | ||
}); | ||
|
||
// Export model | ||
module.exports = mongoose.model("PokeDetails", PokeDetailsSchema); |
19 changes: 19 additions & 0 deletions
19
full-stack-javascript/21-inventory-application/server/models/pokemon.js
This file contains 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,19 @@ | ||
const mongoose = require("mongoose"); | ||
|
||
const Schema = mongoose.Schema; | ||
|
||
const PokeSchema = new Schema({ | ||
name: { type: String, required: true }, | ||
dexId: { type: Number, required: true }, | ||
types: [{ type: String }], | ||
avatar: { type: String, required: true }, | ||
details: { type: Schema.Types.ObjectId, ref: "PokeDetails", required: true }, | ||
}); | ||
|
||
// Virtual for pokemon's URL | ||
PokeSchema.virtual("url").get(function () { | ||
return `/pokemon/${this._id}`; | ||
}); | ||
|
||
// Export model | ||
module.exports = mongoose.model("Pokemon", PokeSchema); |
Oops, something went wrong.