Przeglądaj źródła

[feat] Add multiple categories

Sergio Mattei 2 lat temu
rodzic
commit
f93263078e
1 zmienionych plików z 24 dodań i 7 usunięć
  1. 24
    7
      src/pages/AdviceListPage.tsx

+ 24
- 7
src/pages/AdviceListPage.tsx Wyświetl plik

@@ -8,17 +8,24 @@ import {
8 8
 } from "@ionic/react";
9 9
 import { alertCircleOutline } from "ionicons/icons";
10 10
 import useSWR from "swr";
11
-import DropdownComponent from "../components/DropdownComponent";
12 11
 import TopicList from "../components/TopicList";
13 12
 import { fetcher } from "../lib/api";
14 13
 import { Topic } from "../types";
15 14
 
16 15
 const AdviceListPage: React.FC = () => {
17
-  const { data, error } = useSWR<Topic[]>(
18
-    "/api/getTopicList?type=advice",
16
+  const { data: paternidad, error: paternidadError } = useSWR<Topic[]>(
17
+    "/api/getTopicList?type=advice&category=Paternidad",
19 18
     fetcher
20 19
   );
21
-  const isLoading = !data && !error;
20
+  const { data: matrimonio, error: matrimonioError } = useSWR<Topic[]>(
21
+    "/api/getTopicList?type=advice&category=Matrimonio",
22
+    fetcher
23
+  );
24
+  const { data: abuso, error: abusoError } = useSWR<Topic[]>(
25
+    "/api/getTopicList?type=advice&category=Abuso%20Sexual",
26
+    fetcher
27
+  );
28
+  const error = paternidadError || matrimonioError || abusoError;
22 29
 
23 30
   return (
24 31
     <IonPage>
@@ -34,9 +41,19 @@ const AdviceListPage: React.FC = () => {
34 41
           </IonToolbar>
35 42
         </IonHeader>
36 43
         <TopicList
37
-          title="Parentesco"
38
-          loading={isLoading}
39
-          topics={data ? (data as Topic[]) : []}
44
+          title="Paternidad"
45
+          loading={!paternidad && !paternidadError}
46
+          topics={paternidad ? (paternidad as Topic[]) : []}
47
+        />
48
+        <TopicList
49
+          title="Matrimonio"
50
+          loading={!matrimonio && !matrimonioError}
51
+          topics={matrimonio ? (matrimonio as Topic[]) : []}
52
+        />
53
+        <TopicList
54
+          title="Abuso Sexual"
55
+          loading={!abuso && !abusoError}
56
+          topics={abuso ? (abuso as Topic[]) : []}
40 57
         />
41 58
         <IonToast
42 59
           icon={alertCircleOutline}