fix: fix get active documents ids

This commit is contained in:
fantasticit 2022-05-05 10:32:30 +08:00
parent 2d9f7f202a
commit 59b5fc3539
1 changed files with 10 additions and 7 deletions

View File

@ -16,11 +16,15 @@ interface IProps {
export const Documents: React.FC<IProps> = ({ wikiId }) => { export const Documents: React.FC<IProps> = ({ wikiId }) => {
const { data: wiki, loading: wikiLoading, toggleStatus: toggleWorkspaceStatus } = useWikiDetail(wikiId); const { data: wiki, loading: wikiLoading, toggleStatus: toggleWorkspaceStatus } = useWikiDetail(wikiId);
const { data: tocs, loading } = useWikiTocs(wikiId); const { data: tocs, loading } = useWikiTocs(wikiId);
const documents = flattenTree2Array(tocs).map((d) => { const documents = useMemo(
d.label = d.title; () =>
d.value = d.id; flattenTree2Array(tocs).map((d) => {
return d; d.label = d.title;
}); d.value = d.id;
return d;
}),
[tocs]
);
const [nextStatus, setNextStatus] = useState(''); const [nextStatus, setNextStatus] = useState('');
const isPublic = useMemo(() => wiki && isPublicWiki(wiki.status), [wiki]); const isPublic = useMemo(() => wiki && isPublicWiki(wiki.status), [wiki]);
const [publicDocumentIds, setPublicDocumentIds] = useState([]); // 公开的 const [publicDocumentIds, setPublicDocumentIds] = useState([]); // 公开的
@ -47,7 +51,6 @@ export const Documents: React.FC<IProps> = ({ wikiId }) => {
}} }}
key={item.label} key={item.label}
checked={item.checked} checked={item.checked}
style={{ height: 52 }}
> >
<Text>{item.title}</Text> <Text>{item.title}</Text>
</Checkbox> </Checkbox>
@ -77,7 +80,7 @@ export const Documents: React.FC<IProps> = ({ wikiId }) => {
if (!documents.length) return; if (!documents.length) return;
const activeIds = documents.filter((doc) => isPublicDocument(doc.status)).map((doc) => doc.id); const activeIds = documents.filter((doc) => isPublicDocument(doc.status)).map((doc) => doc.id);
setPublicDocumentIds(activeIds); setPublicDocumentIds(activeIds);
}, [tocs, documents]); }, [documents]);
return ( return (
<div className={styles.wrap}> <div className={styles.wrap}>