mirror of https://github.com/fantasticit/think.git
fix: fix refresh tocs
parent
f99d766e15
commit
5735222778
|
@ -3,6 +3,7 @@ import Router from 'next/router';
|
|||
import { Typography, Space, Modal } from '@douyinfe/semi-ui';
|
||||
import { IconDelete } from '@douyinfe/semi-icons';
|
||||
import { useDeleteDocument } from 'data/document';
|
||||
import { triggerRefreshTocs } from 'components/wiki/tocs';
|
||||
|
||||
interface IProps {
|
||||
wikiId: string;
|
||||
|
@ -26,6 +27,7 @@ export const DocumentDeletor: React.FC<IProps> = ({ wikiId, documentId, onDelete
|
|||
: Router.push({
|
||||
pathname: `/wiki/${wikiId}`,
|
||||
});
|
||||
triggerRefreshTocs();
|
||||
});
|
||||
},
|
||||
okButtonProps: { loading, type: 'danger' },
|
||||
|
|
|
@ -9,10 +9,18 @@ import { findParents } from 'components/wiki/tocs/utils';
|
|||
import { IconDocument, IconSetting, IconOverview } from 'components/icons';
|
||||
import { DocumentCreator } from 'components/document/create';
|
||||
import { DataRender } from 'components/data-render';
|
||||
import { EventEmitter } from 'helpers/event-emitter';
|
||||
import { NavItem } from './NavItem';
|
||||
import { Tree } from './tree';
|
||||
import styles from './index.module.scss';
|
||||
|
||||
const em = new EventEmitter();
|
||||
const EVENT_KEY = 'REFRESH_TOCS';
|
||||
|
||||
export const triggerRefreshTocs = () => {
|
||||
em.emit(EVENT_KEY);
|
||||
};
|
||||
|
||||
interface IProps {
|
||||
wikiId: string;
|
||||
documentId?: string;
|
||||
|
@ -33,7 +41,7 @@ export const WikiTocs: React.FC<IProps> = ({
|
|||
const { pathname } = useRouter();
|
||||
const [visible, toggleVisible] = useToggle(false);
|
||||
const { data: wiki, loading: wikiLoading, error: wikiError } = useWikiDetail(wikiId);
|
||||
const { data: tocs, loading: tocsLoading, error: tocsError } = useWikiTocs(wikiId);
|
||||
const { data: tocs, loading: tocsLoading, error: tocsError, refresh } = useWikiTocs(wikiId);
|
||||
const [parentIds, setParentIds] = useState<Array<string>>([]);
|
||||
|
||||
useEffect(() => {
|
||||
|
@ -42,6 +50,16 @@ export const WikiTocs: React.FC<IProps> = ({
|
|||
setParentIds(parentIds);
|
||||
}, [tocs, documentId]);
|
||||
|
||||
useEffect(() => {
|
||||
em.on(EVENT_KEY, () => {
|
||||
refresh();
|
||||
});
|
||||
|
||||
return () => {
|
||||
em.destroy();
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className={styles.wrap}>
|
||||
<DataRender
|
||||
|
|
Loading…
Reference in New Issue