From 04122a2d566888928ccf637af2dee7a8c7c3e92c Mon Sep 17 00:00:00 2001 From: fantasticit Date: Mon, 28 Mar 2022 22:51:43 +0800 Subject: [PATCH] feat: improve share link --- .../document/reader/public/index.tsx | 26 ++++++++++-- .../src/components/document/share/index.tsx | 19 +++++++++ .../src/components/wiki/tocs/NavItem.tsx | 15 ++++++- .../client/src/components/wiki/tocs/index.tsx | 42 ++++++++++++++++++- packages/client/src/data/document.ts | 4 +- .../server/src/services/document.service.ts | 3 +- 6 files changed, 99 insertions(+), 10 deletions(-) diff --git a/packages/client/src/components/document/reader/public/index.tsx b/packages/client/src/components/document/reader/public/index.tsx index 52995bc..eec226b 100644 --- a/packages/client/src/components/document/reader/public/index.tsx +++ b/packages/client/src/components/document/reader/public/index.tsx @@ -1,7 +1,20 @@ import React, { useMemo, useEffect } from 'react'; import cls from 'classnames'; -import { Layout, Nav, Space, Button, Typography, Skeleton, Input, Popover, Modal, BackTop } from '@douyinfe/semi-ui'; +import { + Layout, + Nav, + Space, + Button, + Typography, + Skeleton, + Input, + Popover, + Modal, + Breadcrumb, + BackTop, +} from '@douyinfe/semi-ui'; import { IconArticle } from '@douyinfe/semi-icons'; +import Link from 'next/link'; import { Seo } from 'components/seo'; import { LogoImage, LogoText } from 'components/logo'; import { DataRender } from 'components/data-render'; @@ -91,9 +104,14 @@ export const DocumentPublicReader: React.FC = ({ documentId, hideLogo = } loading={true} /> } normalContent={() => ( - - {data.title} - + + + + {data?.wiki?.name} + + + {data.title} + )} /> diff --git a/packages/client/src/components/document/share/index.tsx b/packages/client/src/components/document/share/index.tsx index 6c6f674..24fb9a8 100644 --- a/packages/client/src/components/document/share/index.tsx +++ b/packages/client/src/components/document/share/index.tsx @@ -49,6 +49,25 @@ export const DocumentShare: React.FC = ({ documentId, render }) => { onCancel={() => toggleVisible(false)} maskClosable={false} style={{ maxWidth: '96vw' }} + footer={ + <> + + + {isPublic && ( + + )} + + } > = ({ icon, text, rightNode, href, isActive = false, hoverable = true }) => { +export const NavItem: React.FC = ({ + icon, + text, + rightNode, + href, + isActive = false, + hoverable = true, + openNewTab = false, +}) => { const right = rightNode ? {rightNode} : null; const content = ( <> @@ -32,7 +41,9 @@ export const NavItem: React.FC = ({ icon, text, rightNode, href, isActiv > {href ? ( - {content} + + {content} + ) : (
{content}
diff --git a/packages/client/src/components/wiki/tocs/index.tsx b/packages/client/src/components/wiki/tocs/index.tsx index cb3420c..1b9b618 100644 --- a/packages/client/src/components/wiki/tocs/index.tsx +++ b/packages/client/src/components/wiki/tocs/index.tsx @@ -1,6 +1,6 @@ import { useRouter } from 'next/router'; import { useEffect, useState } from 'react'; -import { Avatar, Button, Typography, Skeleton } from '@douyinfe/semi-ui'; +import { Avatar, Button, Typography, Skeleton, Tooltip } from '@douyinfe/semi-ui'; import { IconPlus } from '@douyinfe/semi-icons'; import { useWikiDetail, useWikiTocs } from 'data/wiki'; import { useToggle } from 'hooks/use-toggle'; @@ -13,6 +13,7 @@ import { EventEmitter } from 'helpers/event-emitter'; import { NavItem } from './NavItem'; import { Tree } from './tree'; import styles from './index.module.scss'; +import { isPublicWiki } from '@think/domains'; const em = new EventEmitter(); const EVENT_KEY = 'REFRESH_TOCS'; @@ -127,6 +128,45 @@ export const WikiTocs: React.FC = ({ isActive={pathname === '/wiki/[wikiId]/setting'} /> + + } + text={} + /> + } + error={wikiError} + normalContent={() => + isPublicWiki(wiki.status) ? ( + } + text={ + + 公开地址 + + } + href={{ + pathname: `/share/wiki/[wikiId]`, + query: { wikiId }, + }} + isActive={pathname === '/share/wiki/[wikiId]'} + openNewTab + /> + ) : null + } + /> + { */ export const usePublicDocument = (documentId: string) => { const [fetch] = useAsyncLoading(getPublicDocumentDetail); - const [document, setDocument] = useState(null); + const [document, setDocument] = useState<(IDocument & { createUse: IUser; wiki: IWiki }) | null>(null); const [error, setError] = useState<(Error & { statusCode?: number }) | null>(null); const loading = !document && !error; diff --git a/packages/server/src/services/document.service.ts b/packages/server/src/services/document.service.ts index 04aa7d7..5469192 100644 --- a/packages/server/src/services/document.service.ts +++ b/packages/server/src/services/document.service.ts @@ -552,8 +552,9 @@ export class DocumentService { await this.viewService.create({ userId: 'public', documentId, userAgent }); const views = await this.viewService.getDocumentTotalViews(documentId); const createUser = await this.userService.findById(document.createUserId); + const wiki = await this.wikiService.getPublicWikiDetail(document.wikiId); - return { ...document, views, createUser }; + return { ...document, views, wiki, createUser }; } /**