Browse Source

[feat] Add multiple categories

Sergio Mattei 2 years ago
parent
commit
f93263078e
1 changed files with 24 additions and 7 deletions
  1. 24
    7
      src/pages/AdviceListPage.tsx

+ 24
- 7
src/pages/AdviceListPage.tsx View File

8
 } from "@ionic/react";
8
 } from "@ionic/react";
9
 import { alertCircleOutline } from "ionicons/icons";
9
 import { alertCircleOutline } from "ionicons/icons";
10
 import useSWR from "swr";
10
 import useSWR from "swr";
11
-import DropdownComponent from "../components/DropdownComponent";
12
 import TopicList from "../components/TopicList";
11
 import TopicList from "../components/TopicList";
13
 import { fetcher } from "../lib/api";
12
 import { fetcher } from "../lib/api";
14
 import { Topic } from "../types";
13
 import { Topic } from "../types";
15
 
14
 
16
 const AdviceListPage: React.FC = () => {
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
     fetcher
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
   return (
30
   return (
24
     <IonPage>
31
     <IonPage>
34
           </IonToolbar>
41
           </IonToolbar>
35
         </IonHeader>
42
         </IonHeader>
36
         <TopicList
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
         <IonToast
58
         <IonToast
42
           icon={alertCircleOutline}
59
           icon={alertCircleOutline}