mirror of https://github.com/fantasticit/think.git
client: update layout
This commit is contained in:
parent
1c782e23ad
commit
19924b740b
|
@ -1,12 +1,12 @@
|
||||||
import { IconLink } from '@douyinfe/semi-icons';
|
import { IconLink } from '@douyinfe/semi-icons';
|
||||||
import { Button, Input, Modal, Toast, Typography } from '@douyinfe/semi-ui';
|
import { Button, Input, Popover, Space, Toast, Typography } from '@douyinfe/semi-ui';
|
||||||
import { isPublicDocument } from '@think/domains';
|
import { isPublicDocument } from '@think/domains';
|
||||||
import { DataRender } from 'components/data-render';
|
|
||||||
import { useDocumentDetail } from 'data/document';
|
import { useDocumentDetail } from 'data/document';
|
||||||
import { getDocumentShareURL } from 'helpers/url';
|
import { getDocumentShareURL } from 'helpers/url';
|
||||||
|
import { IsOnMobile } from 'hooks/use-on-mobile';
|
||||||
import { useToggle } from 'hooks/use-toggle';
|
import { useToggle } from 'hooks/use-toggle';
|
||||||
import { ShareIllustration } from 'illustrations/share';
|
import { ShareIllustration } from 'illustrations/share';
|
||||||
import React, { useEffect, useMemo, useState } from 'react';
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
documentId: string;
|
documentId: string;
|
||||||
|
@ -17,63 +17,60 @@ interface IProps {
|
||||||
const { Text } = Typography;
|
const { Text } = Typography;
|
||||||
|
|
||||||
export const DocumentShare: React.FC<IProps> = ({ documentId, disabled = false, render }) => {
|
export const DocumentShare: React.FC<IProps> = ({ documentId, disabled = false, render }) => {
|
||||||
|
const { isMobile } = IsOnMobile.useHook();
|
||||||
|
const ref = useRef<HTMLInputElement>();
|
||||||
const [visible, toggleVisible] = useToggle(false);
|
const [visible, toggleVisible] = useToggle(false);
|
||||||
const { data, loading, error, toggleStatus } = useDocumentDetail(documentId, { enabled: visible });
|
const { data, loading, toggleStatus } = useDocumentDetail(documentId, { enabled: visible });
|
||||||
const [sharePassword, setSharePassword] = useState('');
|
const [sharePassword, setSharePassword] = useState('');
|
||||||
const isPublic = useMemo(() => data && isPublicDocument(data.document.status), [data]);
|
const isPublic = useMemo(() => data && isPublicDocument(data.document.status), [data]);
|
||||||
const shareUrl = useMemo(() => data && getDocumentShareURL(data.document.id), [data]);
|
const shareUrl = useMemo(() => data && getDocumentShareURL(data.document.id), [data]);
|
||||||
|
|
||||||
const handleOk = () => {
|
const copyable = useMemo(
|
||||||
|
() => ({
|
||||||
|
onCopy: () => Toast.success({ content: '复制文本成功' }),
|
||||||
|
}),
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
|
const prevent = useCallback((e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const viewUrl = useCallback(() => {
|
||||||
|
window.open(shareUrl, '_blank');
|
||||||
|
}, [shareUrl]);
|
||||||
|
|
||||||
|
const handleOk = useCallback(() => {
|
||||||
toggleStatus({ sharePassword: isPublic ? '' : sharePassword });
|
toggleStatus({ sharePassword: isPublic ? '' : sharePassword });
|
||||||
};
|
}, [isPublic, sharePassword, toggleStatus]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (loading || !data) return;
|
if (loading || !data) return;
|
||||||
setSharePassword(data.document && data.document.sharePassword);
|
setSharePassword(data.document && data.document.sharePassword);
|
||||||
}, [loading, data]);
|
}, [loading, data]);
|
||||||
|
|
||||||
return (
|
useEffect(() => {
|
||||||
<>
|
if (visible) {
|
||||||
{render ? (
|
setTimeout(() => ref.current?.focus(), 100);
|
||||||
render({ isPublic, disabled, toggleVisible })
|
|
||||||
) : (
|
|
||||||
<Button disabled={disabled} type="primary" theme="light" onClick={toggleVisible}>
|
|
||||||
{isPublic ? '分享中' : '分享'}
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
<Modal
|
|
||||||
title={isPublic ? '关闭分享' : '开启分享'}
|
|
||||||
okText={isPublic ? '关闭分享' : '开启分享'}
|
|
||||||
visible={visible}
|
|
||||||
onOk={handleOk}
|
|
||||||
onCancel={() => toggleVisible(false)}
|
|
||||||
style={{ maxWidth: '96vw' }}
|
|
||||||
footer={
|
|
||||||
<>
|
|
||||||
<Button onClick={() => toggleVisible(false)}>取消</Button>
|
|
||||||
<Button theme="solid" type={isPublic ? 'danger' : 'primary'} onClick={handleOk}>
|
|
||||||
{isPublic ? '关闭分享' : '开启分享'}
|
|
||||||
</Button>
|
|
||||||
{isPublic && (
|
|
||||||
<Button
|
|
||||||
theme="solid"
|
|
||||||
type="primary"
|
|
||||||
onClick={() => {
|
|
||||||
window.open(shareUrl, '_blank');
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
查看文档
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
}
|
}
|
||||||
>
|
}, [visible]);
|
||||||
<DataRender
|
|
||||||
loading={loading}
|
|
||||||
error={error}
|
|
||||||
normalContent={() => {
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<Popover
|
||||||
|
showArrow
|
||||||
|
visible={visible}
|
||||||
|
onVisibleChange={toggleVisible}
|
||||||
|
trigger="click"
|
||||||
|
position={isMobile ? 'top' : 'bottomLeft'}
|
||||||
|
style={{ width: 376, maxWidth: '80vw' }}
|
||||||
|
content={
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
maxHeight: '70vh',
|
||||||
|
overflow: 'auto',
|
||||||
|
}}
|
||||||
|
onClick={prevent}
|
||||||
|
>
|
||||||
<div style={{ textAlign: 'center' }}>
|
<div style={{ textAlign: 'center' }}>
|
||||||
<ShareIllustration />
|
<ShareIllustration />
|
||||||
</div>
|
</div>
|
||||||
|
@ -81,18 +78,16 @@ export const DocumentShare: React.FC<IProps> = ({ documentId, disabled = false,
|
||||||
<Text
|
<Text
|
||||||
ellipsis
|
ellipsis
|
||||||
icon={<IconLink />}
|
icon={<IconLink />}
|
||||||
copyable={{
|
copyable={copyable}
|
||||||
onCopy: () => Toast.success({ content: '复制文本成功' }),
|
|
||||||
}}
|
|
||||||
style={{
|
style={{
|
||||||
width: 320,
|
width: 240,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{shareUrl}
|
{shareUrl}
|
||||||
</Text>
|
</Text>
|
||||||
) : (
|
) : (
|
||||||
<Input
|
<Input
|
||||||
autofocus
|
ref={ref}
|
||||||
mode="password"
|
mode="password"
|
||||||
placeholder="设置访问密码"
|
placeholder="设置访问密码"
|
||||||
value={sharePassword}
|
value={sharePassword}
|
||||||
|
@ -106,11 +101,27 @@ export const DocumentShare: React.FC<IProps> = ({ documentId, disabled = false,
|
||||||
: ' 分享关闭后,其他人将不能继续访问该页面'}
|
: ' 分享关闭后,其他人将不能继续访问该页面'}
|
||||||
</Text>
|
</Text>
|
||||||
</div>
|
</div>
|
||||||
|
<Space style={{ width: '100%', justifyContent: 'end', margin: '12px 0' }}>
|
||||||
|
<Button onClick={() => toggleVisible(false)}>取消</Button>
|
||||||
|
<Button theme="solid" type={isPublic ? 'danger' : 'primary'} onClick={handleOk}>
|
||||||
|
{isPublic ? '关闭分享' : '开启分享'}
|
||||||
|
</Button>
|
||||||
|
{isPublic && (
|
||||||
|
<Button theme="solid" type="primary" onClick={viewUrl}>
|
||||||
|
查看文档
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</Space>
|
||||||
</div>
|
</div>
|
||||||
);
|
}
|
||||||
}}
|
>
|
||||||
/>
|
{render ? (
|
||||||
</Modal>
|
render({ isPublic, disabled, toggleVisible })
|
||||||
</>
|
) : (
|
||||||
|
<Button disabled={disabled} type="primary" theme="light" onClick={toggleVisible}>
|
||||||
|
{isPublic ? '分享中' : '分享'}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</Popover>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue