mirror of https://github.com/fantasticit/think.git
client: add navigator button
parent
1b2843f185
commit
9d13ffccd4
|
@ -1,13 +1,5 @@
|
||||||
import {
|
import { Breadcrumb, Button, Form, Layout, Nav, Skeleton, Space, Tooltip, Typography } from '@douyinfe/semi-ui';
|
||||||
Breadcrumb,
|
import { IconExport, IconImport } from '@douyinfe/semi-icons';
|
||||||
Button,
|
|
||||||
Form,
|
|
||||||
Layout,
|
|
||||||
Nav,
|
|
||||||
Skeleton,
|
|
||||||
Space,
|
|
||||||
Typography,
|
|
||||||
} from '@douyinfe/semi-ui';
|
|
||||||
import { FormApi } from '@douyinfe/semi-ui/lib/es/form';
|
import { FormApi } from '@douyinfe/semi-ui/lib/es/form';
|
||||||
import { DataRender } from 'components/data-render';
|
import { DataRender } from 'components/data-render';
|
||||||
import { Divider } from 'components/divider';
|
import { Divider } from 'components/divider';
|
||||||
|
@ -28,6 +20,9 @@ import { CollaborationEditor } from 'tiptap/editor';
|
||||||
|
|
||||||
import { Author } from '../author';
|
import { Author } from '../author';
|
||||||
import styles from './index.module.scss';
|
import styles from './index.module.scss';
|
||||||
|
import Router from 'next/router';
|
||||||
|
import { useRouterQuery } from 'hooks/use-router-query';
|
||||||
|
import { IDocument, IWiki } from '@think/domains';
|
||||||
|
|
||||||
const { Header } = Layout;
|
const { Header } = Layout;
|
||||||
const { Text } = Typography;
|
const { Text } = Typography;
|
||||||
|
@ -39,7 +34,8 @@ interface IProps {
|
||||||
|
|
||||||
export const DocumentPublicReader: React.FC<IProps> = ({ documentId, hideLogo = false }) => {
|
export const DocumentPublicReader: React.FC<IProps> = ({ documentId, hideLogo = false }) => {
|
||||||
const $form = useRef<FormApi>();
|
const $form = useRef<FormApi>();
|
||||||
const mounted = useMount()
|
const mounted = useMount();
|
||||||
|
const { wikiId: currentWikiId } = useRouterQuery<{ wikiId: IWiki['id']; documentId: IDocument['id'] }>();
|
||||||
const { data, loading, error, query } = usePublicDocumentDetail(documentId);
|
const { data, loading, error, query } = usePublicDocumentDetail(documentId);
|
||||||
const { width, fontSize } = useDocumentStyle();
|
const { width, fontSize } = useDocumentStyle();
|
||||||
const { isMobile } = IsOnMobile.useHook();
|
const { isMobile } = IsOnMobile.useHook();
|
||||||
|
@ -68,7 +64,12 @@ export const DocumentPublicReader: React.FC<IProps> = ({ documentId, hideLogo =
|
||||||
});
|
});
|
||||||
}, [query]);
|
}, [query]);
|
||||||
|
|
||||||
if (!documentId) return null;
|
const toPublicWikiOrDocumentURL = useCallback(() => {
|
||||||
|
Router.push({
|
||||||
|
pathname: currentWikiId ? '/share/document/[documentId]' : '/share/wiki/[wikiId]/document/[documentId]',
|
||||||
|
query: currentWikiId ? { documentId } : { wikiId: data.wikiId, documentId },
|
||||||
|
});
|
||||||
|
}, [data, currentWikiId]);
|
||||||
|
|
||||||
const content = useMemo(() => {
|
const content = useMemo(() => {
|
||||||
if (error) {
|
if (error) {
|
||||||
|
@ -94,36 +95,40 @@ export const DocumentPublicReader: React.FC<IProps> = ({ documentId, hideLogo =
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return (<div
|
return (
|
||||||
style={{
|
<div
|
||||||
margin: '10%',
|
style={{
|
||||||
display: 'flex',
|
margin: '10%',
|
||||||
justifyContent: 'center',
|
display: 'flex',
|
||||||
flexDirection: 'column',
|
justifyContent: 'center',
|
||||||
alignItems: 'center',
|
flexDirection: 'column',
|
||||||
}}
|
alignItems: 'center',
|
||||||
>
|
}}
|
||||||
<SecureDocumentIllustration />
|
>
|
||||||
<Text style={{ marginTop: 12 }} type="danger">
|
<SecureDocumentIllustration />
|
||||||
{(error && (error as Error).message) || '未知错误'}
|
<Text style={{ marginTop: 12 }} type="danger">
|
||||||
</Text>
|
{(error && (error as Error).message) || '未知错误'}
|
||||||
</div>);
|
</Text>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{data && <Seo title={data.title} />}
|
{data && <Seo title={data.title} />}
|
||||||
{mounted && <CollaborationEditor
|
{mounted && (
|
||||||
menubar={false}
|
<CollaborationEditor
|
||||||
editable={false}
|
menubar={false}
|
||||||
user={null}
|
editable={false}
|
||||||
id={documentId}
|
user={null}
|
||||||
type="document"
|
id={documentId}
|
||||||
renderInEditorPortal={renderAuthor}
|
type="document"
|
||||||
/>}
|
renderInEditorPortal={renderAuthor}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
)
|
);
|
||||||
}, [error, data, mounted, editorWrapClassNames, fontSize])
|
}, [error, data, mounted, editorWrapClassNames, fontSize]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout className={styles.wrap}>
|
<Layout className={styles.wrap}>
|
||||||
|
@ -143,6 +148,26 @@ export const DocumentPublicReader: React.FC<IProps> = ({ documentId, hideLogo =
|
||||||
}
|
}
|
||||||
footer={
|
footer={
|
||||||
<Space>
|
<Space>
|
||||||
|
{currentWikiId ? (
|
||||||
|
<Tooltip content="独立模式">
|
||||||
|
<Button
|
||||||
|
theme="borderless"
|
||||||
|
type="tertiary"
|
||||||
|
icon={<IconExport />}
|
||||||
|
onClick={toPublicWikiOrDocumentURL}
|
||||||
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
) : (
|
||||||
|
<Tooltip content="嵌入模式">
|
||||||
|
<Button
|
||||||
|
theme="borderless"
|
||||||
|
type="tertiary"
|
||||||
|
icon={<IconImport />}
|
||||||
|
onClick={toPublicWikiOrDocumentURL}
|
||||||
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
)}
|
||||||
|
|
||||||
<DocumentStyle />
|
<DocumentStyle />
|
||||||
<Theme />
|
<Theme />
|
||||||
<User />
|
<User />
|
||||||
|
@ -154,7 +179,7 @@ export const DocumentPublicReader: React.FC<IProps> = ({ documentId, hideLogo =
|
||||||
error={error}
|
error={error}
|
||||||
loadingContent={<Skeleton active placeholder={<Skeleton.Title style={{ width: 80 }} />} loading={true} />}
|
loadingContent={<Skeleton active placeholder={<Skeleton.Title style={{ width: 80 }} />} loading={true} />}
|
||||||
normalContent={() => (
|
normalContent={() => (
|
||||||
<Breadcrumb >
|
<Breadcrumb>
|
||||||
<Breadcrumb.Item>
|
<Breadcrumb.Item>
|
||||||
<Link href="/share/wiki/[wikiId]" as={`/share/wiki/${data.wikiId}`}>
|
<Link href="/share/wiki/[wikiId]" as={`/share/wiki/${data.wikiId}`}>
|
||||||
<a>{data?.wiki?.name}</a>
|
<a>{data?.wiki?.name}</a>
|
||||||
|
|
Loading…
Reference in New Issue