fix: fix reorder documnets

This commit is contained in:
fantasticit 2022-05-10 11:44:06 +08:00
parent 2a6a82936f
commit e6ef6df7d5
2 changed files with 53 additions and 49 deletions

View File

@ -2,7 +2,7 @@
margin-top: 5px; margin-top: 5px;
.tocsWrap { .tocsWrap {
height: 420px; height: 560px;
overflow: auto; overflow: auto;
border: 1px solid var(--semi-color-border); border: 1px solid var(--semi-color-border);
border-radius: var(--border-radius); border-radius: var(--border-radius);

View File

@ -1,6 +1,7 @@
import React, { useEffect, useState } from 'react'; import React, { useCallback, useEffect, useState } from 'react';
import { Banner, Tree, Button, Toast, Typography } from '@douyinfe/semi-ui'; import { Banner, Tree, Button, Toast, Typography } from '@douyinfe/semi-ui';
import { DataRender } from 'components/data-render'; import { DataRender } from 'components/data-render';
import { Resizeable } from 'components/resizeable';
import { useWikiTocs } from 'data/wiki'; import { useWikiTocs } from 'data/wiki';
import styles from './index.module.scss'; import styles from './index.module.scss';
@ -32,7 +33,7 @@ const extractRelation = (treeData: Array<IDataNode>) => {
}); });
index++; index++;
if (node.children && node.children.length) { if (node.children && node.children.length) {
data.push(...node.children.map((sub, j) => ({ ...sub, index: j }))); data.push(...node.children.map((sub, j) => ({ ...sub, index: j, parentDocumentId: node.id })));
} }
} }
@ -50,7 +51,8 @@ export const WikiTocsManager: React.FC<IProps> = ({ wikiId }) => {
setTreeData(tocs); setTreeData(tocs);
}, [tocs]); }, [tocs]);
function onDrop(info) { const onDrop = useCallback(
(info) => {
const { dropToGap, node, dragNode } = info; const { dropToGap, node, dragNode } = info;
const dropKey = node.key; const dropKey = node.key;
const dragKey = dragNode.key; const dragKey = dragNode.key;
@ -98,15 +100,17 @@ export const WikiTocsManager: React.FC<IProps> = ({ wikiId }) => {
} }
setTreeData(data); setTreeData(data);
setChanged(true); setChanged(true);
} },
[treeData]
);
const submit = () => { const submit = useCallback(() => {
const data = extractRelation(treeData); const data = extractRelation(treeData);
updateTocs(data).then(() => { updateTocs(data).then(() => {
setChanged(false); setChanged(false);
Toast.success('目录已更新'); Toast.success('目录已更新');
}); });
}; }, [treeData, updateTocs]);
return ( return (
<div className={styles.wrap}> <div className={styles.wrap}>