Skip to content

Commit 1bda685

Browse files
committed
update project
1 parent bce8809 commit 1bda685

File tree

6 files changed

+83
-20
lines changed

6 files changed

+83
-20
lines changed

src/App.tsx

-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { FunctionComponent } from 'react';
2-
import PokemonCard from './components/pokemon-card';
32
import './App.css';
43
import PokemonList from './pages/pokemon-list';
54

@@ -10,6 +9,4 @@ const App: FunctionComponent = () => {
109
</>
1110
)
1211
}
13-
1412
export default App;
15-

src/components/pokemon-card.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
.horizontal{
2-
border : solid 4px #270b0b;
2+
border : solid 4px ;
33
height : 200px;
44
}

src/components/pokemon-card.tsx

+24-7
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,39 @@
1-
import React, { FunctionComponent } from 'react';
1+
import React, { FunctionComponent, useState } from 'react';
22
import Pokemon from '../models/pokemon';
33
import './pokemon-card.css';
4-
type Props = {
5-
pokemon: Pokemon
4+
import formatDate from '../helpers/formatDate';
5+
import formatType from '../helpers/formatType';
6+
type Props = {//methodes pour les props
7+
pokemon: Pokemon,
8+
borderColor ? : string //couleur des bordures par défaut
69
};
710

8-
const PokemonCard: FunctionComponent<Props> = ({ pokemon }) => {
11+
const PokemonCard: FunctionComponent<Props> = ({ pokemon, borderColor = 'red' }) => { //methode pour les props
12+
const [color, setColor] = useState <string>();
13+
14+
const showBorder = () => {
15+
setColor(borderColor);
16+
}
17+
const hideBorder = ()=>{
18+
setColor("#f5f5f5");
19+
}
920

1021
return (
11-
<div className="col s6 m4">
12-
<div className="card horizontal">
22+
<div className="col s6 m4" onMouseEnter={showBorder} onMouseLeave={hideBorder}>
23+
<div className="card horizontal" style={{borderColor : color}}>
1324
<div className="card-image">
1425
<img src={pokemon.picture} alt={pokemon.name} />
1526
</div>
1627
<div className="card-stacked">
1728
<div className="card-content">
29+
1830
<p>{pokemon.name}</p>
19-
<p><small>{pokemon.created.toString()}</small></p>
31+
<p><small>{formatDate(pokemon.created)}</small></p>
32+
33+
{pokemon.types.map(type=>(
34+
<span key={type} className={formatType(type)}> {type}</span>
35+
))}
36+
2037
</div>
2138
</div>
2239
</div>

src/helpers/formatDate.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function formatDate(date: Date) : string{
2+
return `${date.getFullYear()}/ ${date.getMonth()+1} / ${date.getDay()}`;
3+
}
4+
export default formatDate;

src/helpers/formatType.ts

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const formatType = (type: string): string => {
2+
let color: string;
3+
switch (type) {
4+
case 'Feu':
5+
color = 'red lighten-1';
6+
break;
7+
case 'Eau':
8+
color = 'blue lighten-1';
9+
break;
10+
case 'Plante':
11+
color = 'green lighten-1';
12+
break;
13+
case 'Insecte':
14+
color = 'brown lighten-1';
15+
break;
16+
case 'Normal':
17+
color = 'grey lighten-3';
18+
break;
19+
case 'Vol':
20+
color = 'blue lighten-3';
21+
break;
22+
case 'Poison':
23+
color = 'deep-purple accent-1';
24+
break;
25+
case 'Fée':
26+
color = 'pink lighten-4';
27+
break;
28+
case 'Psy':
29+
color = 'deep-purple darken-2';
30+
break;
31+
case 'Electrik':
32+
color = 'lime accent-1';
33+
break;
34+
case 'Combat':
35+
color = 'deep-orange';
36+
break;
37+
default:
38+
color = 'grey';
39+
break;
40+
}
41+
return `chip ${color}`;
42+
}
43+
export default formatType;

src/pages/pokemon-list.tsx

+11-9
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,27 @@ import Pokemon from '../models/pokemon';
33
import POKEMONS from '../models/mock-pokemon';
44
import PokemonCard from '../components/pokemon-card';
55

6-
const PokemonList: FunctionComponent = () => {
7-
const [pokemons, setPokemons] = useState<Pokemon[]>([]);
6+
const PokemonList: FunctionComponent = () => {
7+
const [pokemons, setPokemons] = useState<Pokemon[]>([]);// variable d'état avec un type de tableau de pokemon, initié a un tableau vide
88

9-
useEffect(() => {
10-
setPokemons(POKEMONS);
9+
10+
//equivalent de componentDidMount
11+
useEffect(() => { //methode pour cycle de vie d'un composant
12+
setPokemons(POKEMONS);//insertion dans la variable setPokemons
1113
}, []);
1214

13-
return (
15+
return ( //le code jsx , utilise le framework MATERIALIZE
1416
<div>
1517
<h1 className="center">Pokédex</h1>
1618
<div className="container">
1719
<div className="row">
18-
{pokemons.map(pokemon => (
19-
<PokemonCard key={pokemon.id} pokemon={pokemon}/>
20-
))}
20+
{pokemons.map(pokemon => (//lister les éléments dans un tableau
21+
<PokemonCard key={pokemon.id} pokemon={pokemon}/>
22+
))}
2123
</div>
2224
</div>
2325
</div>
2426
);
2527
}
2628

27-
export default PokemonList;
29+
export default PokemonList;

0 commit comments

Comments
 (0)