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