Kaynağa Gözat

Implemented Capsule Search Bar and Biography Search Bar. Work needed on routing and props data handling.

Alejandro Soledad 1 yıl önce
ebeveyn
işleme
9e6b8a9a4f

+ 20
- 1
src/App.tsx Dosyayı Görüntüle

@@ -1,5 +1,8 @@
1
-import { IonNav, setupIonicReact } from '@ionic/react';
1
+import {Redirect, Route } from 'react-router-dom';
2
+import {IonReactRouter } from '@ionic/react-router';
3
+import {IonNav, setupIonicReact, IonApp, IonRouterOutlet } from '@ionic/react';
2 4
 import HomePage from './pages/HomePage';
5
+import Capsule from './pages/Capsule'
3 6
 
4 7
 /* Core CSS required for Ionic components to work properly */
5 8
 import '@ionic/react/css/core.css';
@@ -24,6 +27,22 @@ setupIonicReact();
24 27
 
25 28
 const App: React.FC = () => (
26 29
   <IonNav root={() => <HomePage />}></IonNav>
30
+  /*<IonApp>
31
+  <IonReactRouter>
32
+    <IonRouterOutlet>
33
+      <Route path="/" exact={true}>
34
+        <Redirect to="/home" />
35
+      </Route>
36
+      <Route path="/home" exact={true}>
37
+        <HomePage />
38
+      </Route>
39
+      <Route path="/capsule">
40
+         <CapsulePage />
41
+      </Route>
42
+    </IonRouterOutlet>
43
+  </IonReactRouter>
44
+</IonApp>*/
45
+  
27 46
 );
28 47
 
29 48
 export default App;

+ 39
- 0
src/components/BiographySearchBar.tsx Dosyayı Görüntüle

@@ -0,0 +1,39 @@
1
+import React, { useState } from 'react';
2
+import { IonItem, IonList, IonSearchbar, IonNavLink} from '@ionic/react';
3
+import biographies from '../data/Biograph.json'
4
+import Biography from '../pages/Biography'
5
+
6
+function SearchBar() {
7
+  const data: string [] = [];
8
+
9
+    for (var i = 0; i < biographies.length; i++){
10
+      data.push(biographies[i].title);
11
+    }
12
+
13
+  let [results, setResults] = useState([...data]);
14
+
15
+  const handleChange = (ev: Event) => {
16
+    let query = "";
17
+    const target = ev.target as HTMLIonSearchbarElement;
18
+    if (target) query = target.value!.toLowerCase();
19
+
20
+    setResults(data.filter(d => d.toLowerCase().indexOf(query) > -1));
21
+  }
22
+
23
+  return (
24
+    <>
25
+      <IonSearchbar debounce={500} onIonChange={(ev) => handleChange(ev)}></IonSearchbar>
26
+
27
+      <IonList inset={true}>
28
+        { results.map(result => (
29
+        <IonNavLink routerDirection="forward" component={() => <Biography/>}>
30
+          <IonItem button>
31
+            { result }
32
+          </IonItem>
33
+        </IonNavLink>
34
+        ))}
35
+      </IonList>
36
+    </>
37
+  );
38
+}
39
+export default SearchBar;

src/components/SearchBar.css → src/components/CapsuleSearchBar.css Dosyayı Görüntüle


+ 54
- 0
src/components/CapsuleSearchBar.tsx Dosyayı Görüntüle

@@ -0,0 +1,54 @@
1
+import React, { useState } from 'react';
2
+import { IonItem, IonList, IonSearchbar, IonNavLink} from '@ionic/react';
3
+import capsules from '../data/Capsule.json'
4
+import Capsule from '../pages/Capsule'
5
+
6
+function SearchBar() {
7
+  const data: string [] = [];
8
+
9
+    for (var i = 0; i < capsules.length; i++){
10
+      data.push(capsules[i].title);
11
+    }
12
+
13
+  let [results, setResults] = useState([...data]);
14
+
15
+  const handleChange = (ev: Event) => {
16
+    let query = "";
17
+    const target = ev.target as HTMLIonSearchbarElement;
18
+    if (target) query = target.value!.toLowerCase();
19
+
20
+    setResults(data.filter(d => d.toLowerCase().indexOf(query) > -1));
21
+  }
22
+
23
+  return (
24
+    <>
25
+      <IonSearchbar debounce={500} onIonChange={(ev) => handleChange(ev)}></IonSearchbar>
26
+
27
+      <IonList inset={true}>
28
+        { results.map(result => (
29
+        <IonNavLink routerDirection="forward" component={() => <Capsule/>}>
30
+          <IonItem button>
31
+            { result }
32
+          </IonItem>
33
+        </IonNavLink>
34
+        ))}
35
+      </IonList>
36
+    </>
37
+  );
38
+}
39
+export default SearchBar;
40
+
41
+/*
42
+ <IonLabel>Breve Historia del baile en Puerto Rico</IonLabel>
43
+<IonNavLink routerDirection="forward" component={() => <Capsule />}>
44
+<IonButton>Visitar</IonButton>
45
+*/
46
+
47
+/*
48
+    <IonItem routerLink={`/message/${message.id}`} detail={true}>
49
+      <div slot="start" className="dot dot-unread"></div>
50
+      <IonLabel className="ion-text-wrap">
51
+
52
+      </IonLabel>
53
+    </IonItem>
54
+*/

+ 0
- 28
src/components/SearchBar.tsx Dosyayı Görüntüle

@@ -1,28 +0,0 @@
1
-import React, { useState } from 'react';
2
-import { IonItem, IonList, IonSearchbar } from '@ionic/react';
3
-
4
-function SearchBar() {
5
-  const data = ['Breve Historia del baile en Puerto Rico', 'Cápsula#2', 'Cápsula#3'];
6
-  let [results, setResults] = useState([...data]);
7
-
8
-  const handleChange = (ev: Event) => {
9
-    let query = "";
10
-    const target = ev.target as HTMLIonSearchbarElement;
11
-    if (target) query = target.value!.toLowerCase();
12
-
13
-    setResults(data.filter(d => d.toLowerCase().indexOf(query) > -1));
14
-  }
15
-
16
-  return (
17
-    <>
18
-      <IonSearchbar debounce={1000} onIonChange={(ev) => handleChange(ev)}></IonSearchbar>
19
-
20
-      <IonList inset={true}>
21
-        { results.map(result => (
22
-          <IonItem>{ result }</IonItem>
23
-        ))}
24
-      </IonList>
25
-    </>
26
-  );
27
-}
28
-export default SearchBar;

+ 20
- 0
src/data/Capsule.json Dosyayı Görüntüle

@@ -0,0 +1,20 @@
1
+[
2
+    {
3
+        "id": 0,
4
+        "title": "Breve Historia del baile en Puerto Rico",
5
+        "content": "Han existido distintas formas de danzar o bailar desde la historia muy antigua de la humanidad. En Puerto Rico el primer baile documentado por los cronistas de Indias es el llamado areito, con las variantes de escritura areyto y areíto. Era un baile coreado y musicalizado, dirigido por un guía. Esta manifestación de movimiento corporal, que Gonzalo Fernández de Oviedo llamó “bailar cantando”, fue común en los grupos indígenas de la región caribeña.",
6
+        "photo": "../assets/BombaPuertorriquena.jpg"
7
+    },
8
+    {
9
+        "id": 1,
10
+        "title": "Capsule#2",
11
+        "content": "Content",
12
+        "photo": "../assets/BombaPuertorriquena.jpg"
13
+    },
14
+    {
15
+        "id": 2,
16
+        "title": "Capsule#3",
17
+        "content": "Content",
18
+        "photo": "../assets/BombaPuertorriquena.jpg"
19
+    }
20
+]

+ 19
- 18
src/pages/ListBiographies.tsx Dosyayı Görüntüle

@@ -28,6 +28,7 @@ import HomePage from './HomePage';
28 28
 import EnciclopediaPR from '../assets/EnciclopediaPR.png';
29 29
 import RobertoClemente from '../assets/RobertoClemente.jpg';
30 30
 import ListBio from '../data/Biograph.json';
31
+import SearchBar from '../components/BiographySearchBar';
31 32
 
32 33
 const ListBiographies: React.FC = () => {
33 34
   return (
@@ -47,8 +48,24 @@ const ListBiographies: React.FC = () => {
47 48
         </IonToolbar>
48 49
       </IonHeader>
49 50
       <IonContent fullscreen>
50
-        <IonSearchbar></IonSearchbar>
51
+        <SearchBar></SearchBar>
52
+      </IonContent>
53
+      <IonFooter>
54
+        <IonToolbar>
55
+          <IonNavLink routerDirection="forward" component={() => <HomePage />}>
56
+            <IonTabButton tab="HomePage" href="/HomePage">
57
+              <IonIcon icon={arrowBack} />
58
+            </IonTabButton>
59
+          </IonNavLink>
60
+        </IonToolbar>
61
+      </IonFooter>
62
+    </IonPage>
63
+  );
64
+};
65
+
66
+export default ListBiographies;
51 67
 
68
+/*
52 69
         {
53 70
           ListBio && ListBio.map(listbio => {
54 71
             return (
@@ -74,20 +91,4 @@ const ListBiographies: React.FC = () => {
74 91
             )
75 92
           })
76 93
         }
77
-
78
-
79
-      </IonContent>
80
-      <IonFooter>
81
-        <IonToolbar>
82
-          <IonNavLink routerDirection="forward" component={() => <HomePage />}>
83
-            <IonTabButton tab="HomePage" href="/HomePage">
84
-              <IonIcon icon={arrowBack} />
85
-            </IonTabButton>
86
-          </IonNavLink>
87
-        </IonToolbar>
88
-      </IonFooter>
89
-    </IonPage>
90
-  );
91
-};
92
-
93
-export default ListBiographies;
94
+*/

+ 4
- 2
src/pages/ListCapsules.tsx Dosyayı Görüntüle

@@ -11,14 +11,16 @@ import {
11 11
   IonIcon,
12 12
   IonGrid,
13 13
   IonRow,
14
-  IonCol
14
+  IonCol,
15
+  IonList,
16
+  IonItem
15 17
 } from '@ionic/react';
16 18
 import { arrowBack } from 'ionicons/icons';
17 19
 import './ListCapsules.css';
18 20
 import HomePage from './HomePage';
19 21
 // import Capsule from './Capsule'
20 22
 import EnciclopediaPR from '../assets/EnciclopediaPR.png';
21
-import SearchBar from '../components/SearchBar';
23
+import SearchBar from '../components/CapsuleSearchBar';
22 24
 
23 25
 const ListCapsules: React.FC = () => {
24 26
   return (