From 26389a63dd160dd7a339b090ae765a456dd2d8b6 Mon Sep 17 00:00:00 2001 From: ynwd <10122431+ynwd@users.noreply.github.com> Date: Mon, 28 Oct 2024 13:09:28 +0700 Subject: [PATCH] chore: implement loading --- modules/index/index.main.tsx | 93 ++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 40 deletions(-) diff --git a/modules/index/index.main.tsx b/modules/index/index.main.tsx index 796ad2ab..c9ff43cc 100644 --- a/modules/index/index.main.tsx +++ b/modules/index/index.main.tsx @@ -18,7 +18,7 @@ export function Main( name: "global", id: "01JAC4GM721KGRWZHG53SMXZP0", }); - const { data: d } = useFetch( + const { data: d, loading, error } = useFetch( `api/message/${room.id}/${props.username}`, ); const [data, setData] = useState(d as any); @@ -93,45 +93,58 @@ export function Main( return ( <> -
-
-
-
-
    - {data && data.map((item, index) => { - return ( -
      - {item.messages.map((d, x) => { - const idx = x; - return ( - - ); - })} -
    - ); - })} -
-
-
- -
-
+ {loading + ? ( +
+ Loading +
+ ) + : ( +
+
+
+
+
    + {data && data.map((item, index) => { + return ( +
      + {item.messages.map((d, x) => { + const idx = x; + return ( + + ); + })} +
    + ); + })} +
+
+
+ +
+
+ )} ); }