diff --git a/packages/client/src/components/document/delete/index.tsx b/packages/client/src/components/document/delete/index.tsx index 4f6f29d..933fe33 100644 --- a/packages/client/src/components/document/delete/index.tsx +++ b/packages/client/src/components/document/delete/index.tsx @@ -3,7 +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'; +import { triggerRefreshTocs } from 'components/wiki/tocs/event'; interface IProps { wikiId: string; diff --git a/packages/client/src/components/wiki/tocs/event.ts b/packages/client/src/components/wiki/tocs/event.ts new file mode 100644 index 0000000..363096f --- /dev/null +++ b/packages/client/src/components/wiki/tocs/event.ts @@ -0,0 +1,20 @@ +import { IDocument, IWiki } from '@think/domains'; +import { event } from 'helpers/event-emitter'; + +export const REFRESH_TOCS = `REFRESH_TOCS`; // 刷新知识库目录 +export const CREATE_DOCUMENT = `CREATE_DOCUMENT`; + +/** + * 刷新知识库目录 + */ +export const triggerRefreshTocs = () => { + event.emit(REFRESH_TOCS); +}; + +/** + * 新建文档 + * @param data + */ +export const triggerCreateDocument = (data: { wikiId: IWiki['id']; documentId: IDocument['id'] | null }) => { + event.emit(CREATE_DOCUMENT, data); +}; diff --git a/packages/client/src/components/wiki/tocs/index.tsx b/packages/client/src/components/wiki/tocs/index.tsx index e82e33c..93d4639 100644 --- a/packages/client/src/components/wiki/tocs/index.tsx +++ b/packages/client/src/components/wiki/tocs/index.tsx @@ -2,25 +2,18 @@ import { useRouter } from 'next/router'; import { useEffect, useState } from 'react'; import { Avatar, Button, Typography, Skeleton, Tooltip } from '@douyinfe/semi-ui'; import { IconPlus } from '@douyinfe/semi-icons'; +import { isPublicWiki } from '@think/domains'; import { useWikiDetail, useWikiTocs } from 'data/wiki'; import { useToggle } from 'hooks/use-toggle'; import { Seo } from 'components/seo'; import { findParents } from 'components/wiki/tocs/utils'; import { IconDocument, IconSetting, IconOverview, IconGlobe } from 'components/icons'; -import { DocumentCreator } from 'components/document/create'; import { DataRender } from 'components/data-render'; -import { EventEmitter } from 'helpers/event-emitter'; +import { event } from 'helpers/event-emitter'; +import { REFRESH_TOCS, triggerCreateDocument } from './event'; import { NavItem } from './nav-item'; import { Tree } from './tree'; import styles from './index.module.scss'; -import { isPublicWiki } from '@think/domains'; - -const em = new EventEmitter(); -const EVENT_KEY = 'REFRESH_TOCS'; - -export const triggerRefreshTocs = () => { - em.emit(EVENT_KEY); -}; interface IProps { wikiId: string; @@ -52,12 +45,11 @@ export const WikiTocs: React.FC = ({ }, [tocs, documentId]); useEffect(() => { - em.on(EVENT_KEY, () => { - refresh(); - }); + const handler = () => refresh(); + event.on(REFRESH_TOCS, handler); return () => { - em.destroy(); + event.off(REFRESH_TOCS, handler); }; }, []); @@ -197,17 +189,16 @@ export const WikiTocs: React.FC = ({ }} isActive={pathname === '/wiki/[wikiId]/documents'} rightNode={ - <> -