Browse Source

[feat] Add proof of concept Notion integration

Sergio Mattei 1 year ago
parent
commit
ba67862d80
6 changed files with 55 additions and 2 deletions
  1. 15
    0
      package-lock.json
  2. 1
    0
      package.json
  3. 4
    1
      src/components/ListComponent.tsx
  4. 1
    0
      src/config.ts
  5. 4
    0
      src/lib/api.ts
  6. 30
    1
      src/pages/LawListPage.tsx

+ 15
- 0
package-lock.json View File

33
         "react-router": "^5.2.0",
33
         "react-router": "^5.2.0",
34
         "react-router-dom": "^5.2.0",
34
         "react-router-dom": "^5.2.0",
35
         "react-scripts": "^5.0.0",
35
         "react-scripts": "^5.0.0",
36
+        "swr": "^1.3.0",
36
         "typescript": "^4.1.3",
37
         "typescript": "^4.1.3",
37
         "web-vitals": "^0.2.4",
38
         "web-vitals": "^0.2.4",
38
         "workbox-background-sync": "^5.1.4",
39
         "workbox-background-sync": "^5.1.4",
14676
         "node": ">=4"
14677
         "node": ">=4"
14677
       }
14678
       }
14678
     },
14679
     },
14680
+    "node_modules/swr": {
14681
+      "version": "1.3.0",
14682
+      "resolved": "https://registry.npmjs.org/swr/-/swr-1.3.0.tgz",
14683
+      "integrity": "sha512-dkghQrOl2ORX9HYrMDtPa7LTVHJjCTeZoB1dqTbnnEDlSvN8JEKpYIYurDfvbQFUUS8Cg8PceFVZNkW0KNNYPw==",
14684
+      "peerDependencies": {
14685
+        "react": "^16.11.0 || ^17.0.0 || ^18.0.0"
14686
+      }
14687
+    },
14679
     "node_modules/symbol-tree": {
14688
     "node_modules/symbol-tree": {
14680
       "version": "3.2.4",
14689
       "version": "3.2.4",
14681
       "resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz",
14690
       "resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz",
26863
         }
26872
         }
26864
       }
26873
       }
26865
     },
26874
     },
26875
+    "swr": {
26876
+      "version": "1.3.0",
26877
+      "resolved": "https://registry.npmjs.org/swr/-/swr-1.3.0.tgz",
26878
+      "integrity": "sha512-dkghQrOl2ORX9HYrMDtPa7LTVHJjCTeZoB1dqTbnnEDlSvN8JEKpYIYurDfvbQFUUS8Cg8PceFVZNkW0KNNYPw==",
26879
+      "requires": {}
26880
+    },
26866
     "symbol-tree": {
26881
     "symbol-tree": {
26867
       "version": "3.2.4",
26882
       "version": "3.2.4",
26868
       "resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz",
26883
       "resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz",

+ 1
- 0
package.json View File

28
     "react-router": "^5.2.0",
28
     "react-router": "^5.2.0",
29
     "react-router-dom": "^5.2.0",
29
     "react-router-dom": "^5.2.0",
30
     "react-scripts": "^5.0.0",
30
     "react-scripts": "^5.0.0",
31
+    "swr": "^1.3.0",
31
     "typescript": "^4.1.3",
32
     "typescript": "^4.1.3",
32
     "web-vitals": "^0.2.4",
33
     "web-vitals": "^0.2.4",
33
     "workbox-background-sync": "^5.1.4",
34
     "workbox-background-sync": "^5.1.4",

+ 4
- 1
src/components/ListComponent.tsx View File

14
 
14
 
15
       {laws.map((lawName: string) => {
15
       {laws.map((lawName: string) => {
16
         return (
16
         return (
17
-          <IonItem routerLink={`/article/${encodeURIComponent(lawName)}`}>
17
+          <IonItem
18
+            key={lawName}
19
+            routerLink={`/article/${encodeURIComponent(lawName)}`}
20
+          >
18
             <p className="ListItemText">{lawName}</p>
21
             <p className="ListItemText">{lawName}</p>
19
           </IonItem>
22
           </IonItem>
20
         );
23
         );

+ 1
- 0
src/config.ts View File

1
+export const API_URL = process.env.API_URL ?? "http://localhost:3000";

+ 4
- 0
src/lib/api.ts View File

1
+import { API_URL } from "../config";
2
+
3
+export const fetcher = (url: string) =>
4
+  fetch(`${API_URL}${url}`).then((r) => r.json());

+ 30
- 1
src/pages/LawListPage.tsx View File

1
 import {
1
 import {
2
   IonContent,
2
   IonContent,
3
   IonHeader,
3
   IonHeader,
4
+  IonLoading,
4
   IonPage,
5
   IonPage,
5
   IonTitle,
6
   IonTitle,
7
+  IonToast,
6
   IonToolbar,
8
   IonToolbar,
7
 } from "@ionic/react";
9
 } from "@ionic/react";
10
+import { alertCircleOutline } from "ionicons/icons";
11
+import { useEffect } from "react";
12
+import useSWR from "swr";
8
 import ListComponent from "../components/ListComponent";
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
 const LawListPage: React.FC = () => {
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
   return (
28
   return (
12
     <IonPage>
29
     <IonPage>
13
       <IonHeader>
30
       <IonHeader>
21
             <IonTitle size="large">Leyes</IonTitle>
38
             <IonTitle size="large">Leyes</IonTitle>
22
           </IonToolbar>
39
           </IonToolbar>
23
         </IonHeader>
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
       </IonContent>
54
       </IonContent>
26
     </IonPage>
55
     </IonPage>
27
   );
56
   );