瀏覽代碼

将 MyDict 提取为外部组件

visuddhinanda 2 年之前
父節點
當前提交
ff2b9f0d15
共有 1 個文件被更改,包括 50 次插入47 次删除
  1. 50 47
      dashboard/src/components/dict/DictContent.tsx

+ 50 - 47
dashboard/src/components/dict/DictContent.tsx

@@ -1,4 +1,4 @@
-import { Button, Col, Divider, Row, Tabs } from "antd";
+import { Col, Divider, Row, Tabs } from "antd";
 
 
 import type { IAnchorData } from "./DictList";
 import type { IAnchorData } from "./DictList";
 import type { IWidgetWordCardData } from "./WordCard";
 import type { IWidgetWordCardData } from "./WordCard";
@@ -33,6 +33,54 @@ export interface IApiDictContentData {
   data: IDictContentData;
   data: IDictContentData;
 }
 }
 
 
+interface IMyDict {
+  word?: string;
+}
+const MyDict = ({ word }: IMyDict) => {
+  const user = useAppSelector(currentUser);
+  const [myTab, setMyTab] = useState<string>("list");
+  const [myRefresh, setMyRefresh] = useState(false);
+  return (
+    <div>
+      <Tabs
+        size="small"
+        type="card"
+        style={{ backgroundColor: "white" }}
+        activeKey={myTab}
+        onChange={(activeKey: string) => setMyTab(activeKey)}
+        items={[
+          {
+            label: "列表",
+            key: "list",
+            children: (
+              <UserDictList
+                studioName={user?.realName}
+                word={word}
+                compact={true}
+                refresh={myRefresh}
+                onRefresh={(value: boolean) => setMyRefresh(value)}
+              />
+            ),
+          },
+          {
+            label: "新建",
+            key: "new",
+            children: (
+              <MyCreate
+                word={word}
+                onSave={() => {
+                  setMyRefresh(true);
+                  setMyTab("list");
+                }}
+              />
+            ),
+          },
+        ]}
+      />
+    </div>
+  );
+};
+
 interface IWidget {
 interface IWidget {
   word?: string;
   word?: string;
   data: IDictContentData;
   data: IDictContentData;
@@ -41,51 +89,6 @@ interface IWidget {
 
 
 const DictContentWidget = ({ word, data, compact }: IWidget) => {
 const DictContentWidget = ({ word, data, compact }: IWidget) => {
   const intl = useIntl();
   const intl = useIntl();
-  const user = useAppSelector(currentUser);
-  const [myRefresh, setMyRefresh] = useState(false);
-
-  const MyDict = () => {
-    const [myTab, setMyTab] = useState<string>("list");
-    return (
-      <div>
-        <Tabs
-          size="small"
-          type="card"
-          style={{ backgroundColor: "white" }}
-          activeKey={myTab}
-          onChange={(activeKey: string) => setMyTab(activeKey)}
-          items={[
-            {
-              label: "列表",
-              key: "list",
-              children: (
-                <UserDictList
-                  studioName={user?.realName}
-                  word={word}
-                  compact={true}
-                  refresh={myRefresh}
-                  onRefresh={(value: boolean) => setMyRefresh(value)}
-                />
-              ),
-            },
-            {
-              label: "新建",
-              key: "new",
-              children: (
-                <MyCreate
-                  word={word}
-                  onSave={() => {
-                    setMyRefresh(true);
-                    setMyTab("list");
-                  }}
-                />
-              ),
-            },
-          ]}
-        />
-      </div>
-    );
-  };
 
 
   return (
   return (
     <>
     <>
@@ -151,7 +154,7 @@ const DictContentWidget = ({ word, data, compact }: IWidget) => {
               {
               {
                 label: `单词本`,
                 label: `单词本`,
                 key: "my",
                 key: "my",
-                children: <MyDict />,
+                children: <MyDict word={word} />,
               },
               },
             ]}
             ]}
           />
           />