Browse Source

Last modification

Alex Ortiz 1 year ago
parent
commit
25393999fc
3 changed files with 41 additions and 16 deletions
  1. 13
    0
      src/data/BioInfo.ts
  2. 26
    11
      src/pages/Biography.tsx
  3. 2
    5
      src/pages/ListBiographies.tsx

+ 13
- 0
src/data/BioInfo.ts View File

@@ -0,0 +1,13 @@
1
+import ListBio from '../data/Biograph.json';
2
+
3
+export interface BioInfo {
4
+    id: number;
5
+    title: string;
6
+    content: string;
7
+    tags: string;
8
+    photo: string;
9
+}
10
+
11
+export const getMessages = () => ListBio;
12
+
13
+export const getMessage = (id: number) => ListBio.find(m => m.id === id);

+ 26
- 11
src/pages/Biography.tsx View File

@@ -12,17 +12,28 @@ import {
12 12
     IonImg,
13 13
     IonGrid,
14 14
     IonRow,
15
-    IonCol
15
+    IonCol,
16
+    useIonViewWillEnter
16 17
 } from '@ionic/react';
17 18
 import { arrowBack } from 'ionicons/icons';
18
-import React from 'react';
19
+import React, { useState } from 'react';
19 20
 import './Biography.css';
20 21
 import ListBiographies from './ListBiographies';
21 22
 import Questions from './Questions';
22 23
 import EnciclopediaPR from '../assets/EnciclopediaPR.png';
23 24
 import RobertoClemente from '../assets/RobertoClemente.jpg';
25
+import { useParams } from 'react-router';
26
+import { BioInfo, getMessage } from '../data/BioInfo';
24 27
 
25 28
 const Biography: React.FC = () => {
29
+    const [BioItem, setMessage] = useState<BioInfo>();
30
+    const params = useParams<{ id: string }>();
31
+
32
+    useIonViewWillEnter(() => {
33
+        const msg = getMessage(parseInt(params.id, 10));
34
+        setMessage(msg);
35
+    });
36
+
26 37
     return (
27 38
         <IonPage>
28 39
             <IonHeader>
@@ -40,16 +51,20 @@ const Biography: React.FC = () => {
40 51
                 </IonToolbar>
41 52
             </IonHeader>
42 53
             <IonContent fullscreen className="ion-padding">
43
-                <IonImg style={{ height: 300, width: 600 }} src={RobertoClemente} alt='Logo'></IonImg>
44
-                <h1>Roberto Clemente</h1>
45
-
46
-                <p>Pelotero, Filántropo</p>
47
-                <p>Fue un afamado pelotero puertorriqueño que formó parte de las Grandes Ligas de Estados Unidos. El notable jardinero derecho y bateador fue el primer latinoamericano en formar parte del Salón de la Fama del Béisbol de Estados Unidos. También fue conocido por su labor filantrópica.</p>
48
-                <p>Nació el 18 de agosto de 1934 en San Antón, Carolina. Sus padres fueron Melchor Clemente y Luisa Walker. Desde los ocho años mostró habilidades deportivas con su participación en programas de pequeñas ligas y atletismo infantil. Se destacó en pista y campo, deporte en el que ganó varias medallas, específicamente en tiro de jabalina y distancias cortas. Con apenas 14 años, ya formaba parte del equipo de softball de Sello Rojo, compañía procesadora de arroz. Más adelante, formó parte del equipo de pelota aficionado de Juncos. En 1952, con 18 años de edad, ingresó a la liga de beisbol profesional de Puerto Rico, cuando fue contratado por los Cangrejeros de Santurce. El tiempo que formó parte de este equipo fue crucial para su carrera, ya que pudo pulir sus destrezas deportivas.</p>
54
+                {BioItem ? (
55
+                    <>
56
+                        <IonImg style={{ height: 300, width: 600 }} src={RobertoClemente} alt='Logo'></IonImg>
57
+                        <h1>{BioItem.title}</h1>
49 58
 
50
-                <IonNavLink routerDirection="forward" component={() => <Questions />}>
51
-                    <IonButton>Tomar quiz</IonButton>
52
-                </IonNavLink>
59
+                        <p>{BioItem.tags}</p>
60
+                        <p>{BioItem.content}</p>
61
+                        <IonNavLink routerDirection="forward" component={() => <Questions />}>
62
+                            <IonButton>Tomar quiz</IonButton>
63
+                        </IonNavLink>
64
+                    </>
65
+                ) : (
66
+                    <div>Message not found</div>
67
+                )}
53 68
             </IonContent>
54 69
 
55 70
             <IonFooter>

+ 2
- 5
src/pages/ListBiographies.tsx View File

@@ -61,21 +61,18 @@ const ListBiographies: React.FC = () => {
61 61
                   </IonCardHeader><IonCardContent>
62 62
                     {listbio.content}
63 63
                   </IonCardContent>
64
-                  <IonNavLink routerDirection="forward" component={() => <Biography />}>
65
-                    <IonButton>Go to</IonButton>
64
+                  <IonNavLink routerDirection="forward" component={() => <Biography />} >
65
+                    <IonButton key={listbio.id}>Go to</IonButton>
66 66
                   </IonNavLink>
67 67
 
68 68
                   <IonNavLink routerDirection="forward" component={() => <Questions />}>
69 69
                     <IonButton>Tomar quiz</IonButton>
70 70
                   </IonNavLink>
71
-
72 71
                 </IonCard>
73 72
               </>
74 73
             )
75 74
           })
76 75
         }
77
-
78
-
79 76
       </IonContent>
80 77
       <IonFooter>
81 78
         <IonToolbar>