Explorar o código

add expandedKeys

visuddhinanda %!s(int64=2) %!d(string=hai) anos
pai
achega
b3ecc9f833
Modificáronse 1 ficheiros con 18 adicións e 13 borrados
  1. 18 13
      dashboard/src/components/anthology/AnthologyTocTree.tsx

+ 18 - 13
dashboard/src/components/anthology/AnthologyTocTree.tsx

@@ -17,6 +17,7 @@ const AnthologyTocTreeWidget = ({
   onArticleSelect,
 }: IWidget) => {
   const [tocData, setTocData] = useState<ListNodeData[]>([]);
+  const [expandedKeys, setExpandedKeys] = useState<string[]>();
 
   useEffect(() => {
     if (typeof anthologyId === "undefined") {
@@ -35,23 +36,27 @@ const AnthologyTocTreeWidget = ({
           };
         });
         setTocData(toc);
+        setExpandedKeys(
+          json.data.rows
+            .filter((value) => value.level === 1)
+            .map((item) => (item.article_id ? item.article_id : item.title))
+        );
       }
     });
   }, [anthologyId]);
   return (
-    <div>
-      <TocTree
-        treeData={tocData}
-        onSelect={(keys: string[]) => {
-          if (
-            typeof onArticleSelect !== "undefined" &&
-            typeof anthologyId !== "undefined"
-          ) {
-            onArticleSelect(anthologyId, keys);
-          }
-        }}
-      />
-    </div>
+    <TocTree
+      treeData={tocData}
+      expandedKeys={expandedKeys}
+      onSelect={(keys: string[]) => {
+        if (
+          typeof onArticleSelect !== "undefined" &&
+          typeof anthologyId !== "undefined"
+        ) {
+          onArticleSelect(anthologyId, keys);
+        }
+      }}
+    />
   );
 };