|
@@ -1,13 +1,30 @@
|
1
|
1
|
import {
|
2
|
2
|
IonContent,
|
3
|
3
|
IonHeader,
|
|
4
|
+ IonLoading,
|
4
|
5
|
IonPage,
|
5
|
6
|
IonTitle,
|
|
7
|
+ IonToast,
|
6
|
8
|
IonToolbar,
|
7
|
9
|
} from "@ionic/react";
|
|
10
|
+import { alertCircleOutline } from "ionicons/icons";
|
|
11
|
+import { useEffect } from "react";
|
|
12
|
+import useSWR from "swr";
|
8
|
13
|
import ListComponent from "../components/ListComponent";
|
|
14
|
+import { fetcher } from "../lib/api";
|
|
15
|
+
|
|
16
|
+interface Topic {
|
|
17
|
+ blockId: string;
|
|
18
|
+ name: string;
|
|
19
|
+}
|
9
|
20
|
|
10
|
21
|
const LawListPage: React.FC = () => {
|
|
22
|
+ const { data, error } = useSWR<Topic[]>(
|
|
23
|
+ "/api/getTopicList?type=laws",
|
|
24
|
+ fetcher
|
|
25
|
+ );
|
|
26
|
+ const isLoading = !data && !error;
|
|
27
|
+
|
11
|
28
|
return (
|
12
|
29
|
<IonPage>
|
13
|
30
|
<IonHeader>
|
|
@@ -21,7 +38,19 @@ const LawListPage: React.FC = () => {
|
21
|
38
|
<IonTitle size="large">Leyes</IonTitle>
|
22
|
39
|
</IonToolbar>
|
23
|
40
|
</IonHeader>
|
24
|
|
- <ListComponent laws={["Law 1", "Law 2"]} />
|
|
41
|
+ {data && <ListComponent laws={data.map((item) => item.name)} />}
|
|
42
|
+ <IonLoading
|
|
43
|
+ isOpen={isLoading}
|
|
44
|
+ duration={isLoading ? 50 : undefined}
|
|
45
|
+ message="Loading..."
|
|
46
|
+ />
|
|
47
|
+ <IonToast
|
|
48
|
+ icon={alertCircleOutline}
|
|
49
|
+ color="danger"
|
|
50
|
+ isOpen={error}
|
|
51
|
+ message="Failed to load items."
|
|
52
|
+ duration={1500}
|
|
53
|
+ />
|
25
|
54
|
</IonContent>
|
26
|
55
|
</IonPage>
|
27
|
56
|
);
|