From 9338a70918d1c1ea67726c2b6a4f968ae70fa88f Mon Sep 17 00:00:00 2001 From: Jason Zhu Date: Mon, 17 Apr 2023 00:14:29 +1000 Subject: [PATCH] Renamed Pokemon component to PokemonCard --- README.md | 2 +- src/features/Pokedex/Pokedex.tsx | 4 ++-- src/features/Pokedex/Pokemon/index.ts | 2 -- .../Pokemon.css => PokemonCard/PokemonCard.css} | 0 .../PokemonCard.stories.tsx} | 12 ++++++------ .../PokemonCard.test.ts} | 2 +- .../Pokemon.tsx => PokemonCard/PokemonCard.tsx} | 11 ++++++++--- .../Pokedex/{Pokemon => PokemonCard}/assets/bug.png | Bin .../{Pokemon => PokemonCard}/assets/dark.png | Bin .../{Pokemon => PokemonCard}/assets/dragon.png | Bin .../{Pokemon => PokemonCard}/assets/electric.png | Bin .../{Pokemon => PokemonCard}/assets/fairy.png | Bin .../{Pokemon => PokemonCard}/assets/fighting.png | Bin .../{Pokemon => PokemonCard}/assets/fire.png | Bin .../{Pokemon => PokemonCard}/assets/flying.png | Bin .../{Pokemon => PokemonCard}/assets/ghost.png | Bin .../{Pokemon => PokemonCard}/assets/grass.png | Bin .../{Pokemon => PokemonCard}/assets/ground.png | Bin .../Pokedex/{Pokemon => PokemonCard}/assets/ice.png | Bin .../{Pokemon => PokemonCard}/assets/index.ts | 0 .../{Pokemon => PokemonCard}/assets/normal.png | Bin .../{Pokemon => PokemonCard}/assets/poison.png | Bin .../{Pokemon => PokemonCard}/assets/psychic.png | Bin .../{Pokemon => PokemonCard}/assets/rock.png | Bin .../{Pokemon => PokemonCard}/assets/steel.png | Bin .../assets/stories/charizard.json | 0 .../assets/stories/charizard.svg | 0 .../{Pokemon => PokemonCard}/assets/water.png | Bin src/features/Pokedex/PokemonCard/index.ts | 2 ++ .../Pokedex/{Pokemon => PokemonCard}/utils.ts | 0 src/features/Pokedex/__test__/pokedex.test.ts | 4 ++-- 31 files changed, 22 insertions(+), 17 deletions(-) delete mode 100644 src/features/Pokedex/Pokemon/index.ts rename src/features/Pokedex/{Pokemon/Pokemon.css => PokemonCard/PokemonCard.css} (100%) rename src/features/Pokedex/{Pokemon/Pokemon.stories.tsx => PokemonCard/PokemonCard.stories.tsx} (70%) rename src/features/Pokedex/{Pokemon/Pokemon.test.ts => PokemonCard/PokemonCard.test.ts} (90%) rename src/features/Pokedex/{Pokemon/Pokemon.tsx => PokemonCard/PokemonCard.tsx} (95%) rename src/features/Pokedex/{Pokemon => PokemonCard}/assets/bug.png (100%) rename src/features/Pokedex/{Pokemon => PokemonCard}/assets/dark.png (100%) rename src/features/Pokedex/{Pokemon => PokemonCard}/assets/dragon.png (100%) rename src/features/Pokedex/{Pokemon => PokemonCard}/assets/electric.png (100%) rename src/features/Pokedex/{Pokemon => PokemonCard}/assets/fairy.png (100%) rename src/features/Pokedex/{Pokemon => PokemonCard}/assets/fighting.png (100%) rename src/features/Pokedex/{Pokemon => PokemonCard}/assets/fire.png (100%) rename src/features/Pokedex/{Pokemon => PokemonCard}/assets/flying.png (100%) rename src/features/Pokedex/{Pokemon => PokemonCard}/assets/ghost.png (100%) rename src/features/Pokedex/{Pokemon => PokemonCard}/assets/grass.png (100%) rename src/features/Pokedex/{Pokemon => PokemonCard}/assets/ground.png (100%) rename src/features/Pokedex/{Pokemon => PokemonCard}/assets/ice.png (100%) rename src/features/Pokedex/{Pokemon => PokemonCard}/assets/index.ts (100%) rename src/features/Pokedex/{Pokemon => PokemonCard}/assets/normal.png (100%) rename src/features/Pokedex/{Pokemon => PokemonCard}/assets/poison.png (100%) rename src/features/Pokedex/{Pokemon => PokemonCard}/assets/psychic.png (100%) rename src/features/Pokedex/{Pokemon => PokemonCard}/assets/rock.png (100%) rename src/features/Pokedex/{Pokemon => PokemonCard}/assets/steel.png (100%) rename src/features/Pokedex/{Pokemon => PokemonCard}/assets/stories/charizard.json (100%) rename src/features/Pokedex/{Pokemon => PokemonCard}/assets/stories/charizard.svg (100%) rename src/features/Pokedex/{Pokemon => PokemonCard}/assets/water.png (100%) create mode 100644 src/features/Pokedex/PokemonCard/index.ts rename src/features/Pokedex/{Pokemon => PokemonCard}/utils.ts (100%) diff --git a/README.md b/README.md index 058b5df..4128a2d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Getting Started with Create React App -A simple Pokemon catalogue app, build with React, Redux-Toolkit, Material-UI and PokeAPI. +A simple PokemonCard catalogue app, build with React, Redux-Toolkit, Material-UI and PokeAPI. It's a learning project following [pokedex](https://github.com/s1varam/pokedex). In this project, I practised following skills: * Use React to create View for FE diff --git a/src/features/Pokedex/Pokedex.tsx b/src/features/Pokedex/Pokedex.tsx index 7114d77..cdd9c65 100644 --- a/src/features/Pokedex/Pokedex.tsx +++ b/src/features/Pokedex/Pokedex.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import Pokemon from './Pokemon'; +import PokemonCard from './PokemonCard'; import Filters from './Filters'; import Loading from 'components/Loading'; @@ -54,7 +54,7 @@ const Pokedex = () => { ) : ( sortedFilteredPokemonList.map(pokemon => ( - ; + component: PokemonCard, +} as ComponentMeta; -const Template: ComponentStory = (args: PokemonCardProps) => ( - -); +const Template: ComponentStory = ( + args: PokemonCardProps, +) => ; export const Primary = Template.bind({}); diff --git a/src/features/Pokedex/Pokemon/Pokemon.test.ts b/src/features/Pokedex/PokemonCard/PokemonCard.test.ts similarity index 90% rename from src/features/Pokedex/Pokemon/Pokemon.test.ts rename to src/features/Pokedex/PokemonCard/PokemonCard.test.ts index 6b1fecc..ac5af38 100644 --- a/src/features/Pokedex/Pokemon/Pokemon.test.ts +++ b/src/features/Pokedex/PokemonCard/PokemonCard.test.ts @@ -1,4 +1,4 @@ -import { formatNumber } from './Pokemon'; +import { formatNumber } from './PokemonCard'; describe('Test Functions', () => { describe('formatNumber', () => { diff --git a/src/features/Pokedex/Pokemon/Pokemon.tsx b/src/features/Pokedex/PokemonCard/PokemonCard.tsx similarity index 95% rename from src/features/Pokedex/Pokemon/Pokemon.tsx rename to src/features/Pokedex/PokemonCard/PokemonCard.tsx index bc74f96..a74ab5e 100644 --- a/src/features/Pokedex/Pokemon/Pokemon.tsx +++ b/src/features/Pokedex/PokemonCard/PokemonCard.tsx @@ -1,11 +1,11 @@ import React from 'react'; import { Tooltip, Zoom } from '@mui/material'; -import './Pokemon.css'; +import './PokemonCard.css'; import * as pokeTypeAsset from './assets'; import { colorTypeGradients } from './utils'; -export interface PokemonProps { +export interface PokemonCardProps { name: string; number: number; image: string; @@ -59,7 +59,12 @@ function findPokeTypeAsset(pokeType: string) { } } -export default function Pokemon({ name, number, image, types }: PokemonProps) { +export default function PokemonCard({ + name, + number, + image, + types, +}: PokemonCardProps) { let finalColor; if (types.length === 2) { diff --git a/src/features/Pokedex/Pokemon/assets/bug.png b/src/features/Pokedex/PokemonCard/assets/bug.png similarity index 100% rename from src/features/Pokedex/Pokemon/assets/bug.png rename to src/features/Pokedex/PokemonCard/assets/bug.png diff --git a/src/features/Pokedex/Pokemon/assets/dark.png b/src/features/Pokedex/PokemonCard/assets/dark.png similarity index 100% rename from src/features/Pokedex/Pokemon/assets/dark.png rename to src/features/Pokedex/PokemonCard/assets/dark.png diff --git a/src/features/Pokedex/Pokemon/assets/dragon.png b/src/features/Pokedex/PokemonCard/assets/dragon.png similarity index 100% rename from src/features/Pokedex/Pokemon/assets/dragon.png rename to src/features/Pokedex/PokemonCard/assets/dragon.png diff --git a/src/features/Pokedex/Pokemon/assets/electric.png b/src/features/Pokedex/PokemonCard/assets/electric.png similarity index 100% rename from src/features/Pokedex/Pokemon/assets/electric.png rename to src/features/Pokedex/PokemonCard/assets/electric.png diff --git a/src/features/Pokedex/Pokemon/assets/fairy.png b/src/features/Pokedex/PokemonCard/assets/fairy.png similarity index 100% rename from src/features/Pokedex/Pokemon/assets/fairy.png rename to src/features/Pokedex/PokemonCard/assets/fairy.png diff --git a/src/features/Pokedex/Pokemon/assets/fighting.png b/src/features/Pokedex/PokemonCard/assets/fighting.png similarity index 100% rename from src/features/Pokedex/Pokemon/assets/fighting.png rename to src/features/Pokedex/PokemonCard/assets/fighting.png diff --git a/src/features/Pokedex/Pokemon/assets/fire.png b/src/features/Pokedex/PokemonCard/assets/fire.png similarity index 100% rename from src/features/Pokedex/Pokemon/assets/fire.png rename to src/features/Pokedex/PokemonCard/assets/fire.png diff --git a/src/features/Pokedex/Pokemon/assets/flying.png b/src/features/Pokedex/PokemonCard/assets/flying.png similarity index 100% rename from src/features/Pokedex/Pokemon/assets/flying.png rename to src/features/Pokedex/PokemonCard/assets/flying.png diff --git a/src/features/Pokedex/Pokemon/assets/ghost.png b/src/features/Pokedex/PokemonCard/assets/ghost.png similarity index 100% rename from src/features/Pokedex/Pokemon/assets/ghost.png rename to src/features/Pokedex/PokemonCard/assets/ghost.png diff --git a/src/features/Pokedex/Pokemon/assets/grass.png b/src/features/Pokedex/PokemonCard/assets/grass.png similarity index 100% rename from src/features/Pokedex/Pokemon/assets/grass.png rename to src/features/Pokedex/PokemonCard/assets/grass.png diff --git a/src/features/Pokedex/Pokemon/assets/ground.png b/src/features/Pokedex/PokemonCard/assets/ground.png similarity index 100% rename from src/features/Pokedex/Pokemon/assets/ground.png rename to src/features/Pokedex/PokemonCard/assets/ground.png diff --git a/src/features/Pokedex/Pokemon/assets/ice.png b/src/features/Pokedex/PokemonCard/assets/ice.png similarity index 100% rename from src/features/Pokedex/Pokemon/assets/ice.png rename to src/features/Pokedex/PokemonCard/assets/ice.png diff --git a/src/features/Pokedex/Pokemon/assets/index.ts b/src/features/Pokedex/PokemonCard/assets/index.ts similarity index 100% rename from src/features/Pokedex/Pokemon/assets/index.ts rename to src/features/Pokedex/PokemonCard/assets/index.ts diff --git a/src/features/Pokedex/Pokemon/assets/normal.png b/src/features/Pokedex/PokemonCard/assets/normal.png similarity index 100% rename from src/features/Pokedex/Pokemon/assets/normal.png rename to src/features/Pokedex/PokemonCard/assets/normal.png diff --git a/src/features/Pokedex/Pokemon/assets/poison.png b/src/features/Pokedex/PokemonCard/assets/poison.png similarity index 100% rename from src/features/Pokedex/Pokemon/assets/poison.png rename to src/features/Pokedex/PokemonCard/assets/poison.png diff --git a/src/features/Pokedex/Pokemon/assets/psychic.png b/src/features/Pokedex/PokemonCard/assets/psychic.png similarity index 100% rename from src/features/Pokedex/Pokemon/assets/psychic.png rename to src/features/Pokedex/PokemonCard/assets/psychic.png diff --git a/src/features/Pokedex/Pokemon/assets/rock.png b/src/features/Pokedex/PokemonCard/assets/rock.png similarity index 100% rename from src/features/Pokedex/Pokemon/assets/rock.png rename to src/features/Pokedex/PokemonCard/assets/rock.png diff --git a/src/features/Pokedex/Pokemon/assets/steel.png b/src/features/Pokedex/PokemonCard/assets/steel.png similarity index 100% rename from src/features/Pokedex/Pokemon/assets/steel.png rename to src/features/Pokedex/PokemonCard/assets/steel.png diff --git a/src/features/Pokedex/Pokemon/assets/stories/charizard.json b/src/features/Pokedex/PokemonCard/assets/stories/charizard.json similarity index 100% rename from src/features/Pokedex/Pokemon/assets/stories/charizard.json rename to src/features/Pokedex/PokemonCard/assets/stories/charizard.json diff --git a/src/features/Pokedex/Pokemon/assets/stories/charizard.svg b/src/features/Pokedex/PokemonCard/assets/stories/charizard.svg similarity index 100% rename from src/features/Pokedex/Pokemon/assets/stories/charizard.svg rename to src/features/Pokedex/PokemonCard/assets/stories/charizard.svg diff --git a/src/features/Pokedex/Pokemon/assets/water.png b/src/features/Pokedex/PokemonCard/assets/water.png similarity index 100% rename from src/features/Pokedex/Pokemon/assets/water.png rename to src/features/Pokedex/PokemonCard/assets/water.png diff --git a/src/features/Pokedex/PokemonCard/index.ts b/src/features/Pokedex/PokemonCard/index.ts new file mode 100644 index 0000000..6e2a703 --- /dev/null +++ b/src/features/Pokedex/PokemonCard/index.ts @@ -0,0 +1,2 @@ +export * from './PokemonCard'; +export { default } from './PokemonCard'; diff --git a/src/features/Pokedex/Pokemon/utils.ts b/src/features/Pokedex/PokemonCard/utils.ts similarity index 100% rename from src/features/Pokedex/Pokemon/utils.ts rename to src/features/Pokedex/PokemonCard/utils.ts diff --git a/src/features/Pokedex/__test__/pokedex.test.ts b/src/features/Pokedex/__test__/pokedex.test.ts index 459ded5..ec92dc0 100644 --- a/src/features/Pokedex/__test__/pokedex.test.ts +++ b/src/features/Pokedex/__test__/pokedex.test.ts @@ -34,13 +34,13 @@ describe('pokedex Component', () => { pokemon4_Charmander, ]; - it('should return all Pokemon if the selected type is "All Types"', () => { + it('should return all PokemonCard if the selected type is "All Types"', () => { const selectedType = 'All Types'; const filteredList = filterPokemonByType(pokemonList, selectedType); expect(filteredList).toEqual(pokemonList); }); - it('should return only Pokemon of the selected type', () => { + it('should return only PokemonCard of the selected type', () => { const selectedType = 'fire'; const filteredList = filterPokemonByType(pokemonList, selectedType); const allPokemonAreOfTypeFire = filteredList.every(pokemon =>