Kaynağa Gözat

接收netStatus消息

visuddhinanda 2 yıl önce
ebeveyn
işleme
bdcfc06c02
1 değiştirilmiş dosya ile 27 ekleme ve 1 silme
  1. 27 1
      dashboard/src/components/general/NetStatus.tsx

+ 27 - 1
dashboard/src/components/general/NetStatus.tsx

@@ -1,6 +1,10 @@
 import { Button } from "antd";
 import { CloudOutlined } from "@ant-design/icons";
-import { useState } from "react";
+import { useEffect, useState } from "react";
+import { useAppSelector } from "../../hooks";
+import { netStatus } from "../../reducers/net-status";
+
+export type ENetStatus = "loading" | "success" | "fail";
 
 interface IWidget {
   style?: React.CSSProperties;
@@ -8,6 +12,28 @@ interface IWidget {
 const Widget = ({ style }: IWidget) => {
   const [loading, setLoading] = useState(false);
   const [label, setLabel] = useState("online");
+
+  const _netStatus = useAppSelector(netStatus);
+
+  useEffect(() => {
+    console.log("net status", _netStatus);
+    switch (_netStatus?.status) {
+      case "loading":
+        setLoading(true);
+        break;
+      case "success":
+        setLoading(false);
+        break;
+      case "fail":
+        setLoading(false);
+        break;
+      default:
+        break;
+    }
+    if (_netStatus?.message) {
+      setLabel(_netStatus?.message);
+    }
+  }, [_netStatus]);
   return (
     <>
       <Button