Просмотр исходного кода

Merge pull request #1566 from visuddhinanda/agile

Agile修正article 修改 文集目录不更新的问题
visuddhinanda 2 лет назад
Родитель
Сommit
73be717782

+ 2 - 0
dashboard/src/components/anthology/EditableTocTree.tsx

@@ -127,6 +127,7 @@ const EditableTocTreeWidget = ({
           node: TreeNodeData
         ): Promise<TreeNodeData | undefined> => {
           if (typeof studioName === "undefined") {
+            console.log("studio", studioName);
             return;
           }
           const res = await post<IArticleCreateRequest, IArticleResponse>(
@@ -135,6 +136,7 @@ const EditableTocTreeWidget = ({
               title: "new article",
               lang: getUiLang(),
               studio: studioName,
+              anthologyId: anthologyId,
             }
           );
 

+ 1 - 0
dashboard/src/components/api/Article.ts

@@ -120,6 +120,7 @@ export interface IArticleCreateRequest {
   title: string;
   lang: string;
   studio: string;
+  anthologyId?: string;
 }
 
 export interface IAnthologyCreateRequest {

+ 9 - 9
dashboard/src/components/article/AnthologyInfoEdit.tsx

@@ -18,9 +18,9 @@ interface IFormData {
 
 interface IWidget {
   anthologyId?: string;
-  onTitleChange?: Function;
+  onLoad?: Function;
 }
-const AnthologyInfoEditWidget = ({ anthologyId, onTitleChange }: IWidget) => {
+const AnthologyInfoEditWidget = ({ anthologyId, onLoad }: IWidget) => {
   const intl = useIntl();
 
   return anthologyId ? (
@@ -39,8 +39,8 @@ const AnthologyInfoEditWidget = ({ anthologyId, onTitleChange }: IWidget) => {
         );
         console.log(res);
         if (res.ok) {
-          if (typeof onTitleChange !== "undefined") {
-            onTitleChange(res.data.title);
+          if (typeof onLoad !== "undefined") {
+            onLoad(res.data);
           }
           message.success(
             intl.formatMessage({
@@ -52,13 +52,13 @@ const AnthologyInfoEditWidget = ({ anthologyId, onTitleChange }: IWidget) => {
         }
       }}
       request={async () => {
-        const res = await get<IAnthologyResponse>(
-          `/v2/anthology/${anthologyId}`
-        );
+        const url = `/v2/anthology/${anthologyId}`;
+        console.log("url", url);
+        const res = await get<IAnthologyResponse>(url);
         console.log("文集get", res);
         if (res.ok) {
-          if (typeof onTitleChange !== "undefined") {
-            onTitleChange(res.data.title);
+          if (typeof onLoad !== "undefined") {
+            onLoad(res.data);
           }
 
           return {

+ 1 - 1
dashboard/src/components/article/EditableTree.tsx

@@ -172,7 +172,7 @@ const EditableTreeWidget = ({
     }
     const update = (_node: TreeNodeData[]) => {
       _node.forEach((value, index, array) => {
-        if (value.key === updatedNode.key) {
+        if (value.id === updatedNode.id) {
           array[index].title = updatedNode.title;
           console.log("key found");
           return;

+ 10 - 5
dashboard/src/pages/studio/anthology/edit.tsx

@@ -5,16 +5,17 @@ import { Button, Card, Space, Tabs } from "antd";
 import { TeamOutlined } from "@ant-design/icons";
 
 import GoBack from "../../../components/studio/GoBack";
-import TocTree from "../../../components/anthology/EditableTocTree";
+import EditableTocTree from "../../../components/anthology/EditableTocTree";
 import AnthologyInfoEdit from "../../../components/article/AnthologyInfoEdit";
 import ShareModal from "../../../components/share/ShareModal";
 import { EResType } from "../../../components/share/Share";
+import { IAnthologyDataResponse } from "../../../components/api/Article";
 
 const Widget = () => {
   const intl = useIntl();
   const [title, setTitle] = useState("");
   const { studioname, anthology_id } = useParams(); //url 参数
-
+  const [anthologyInfo, setAnthologyInfo] = useState<IAnthologyDataResponse>();
   return (
     <>
       <Card
@@ -50,8 +51,9 @@ const Widget = () => {
               children: (
                 <AnthologyInfoEdit
                   anthologyId={anthology_id}
-                  onTitleChange={(title: string) => {
-                    setTitle(title);
+                  onLoad={(value: IAnthologyDataResponse) => {
+                    setTitle(value.title);
+                    setAnthologyInfo(value);
                   }}
                 />
               ),
@@ -60,7 +62,10 @@ const Widget = () => {
               key: "toc",
               label: `目录`,
               children: (
-                <TocTree studioName={studioname} anthologyId={anthology_id} />
+                <EditableTocTree
+                  studioName={anthologyInfo?.studio.realName}
+                  anthologyId={anthology_id}
+                />
               ),
             },
           ]}