From c4e2a82493ade1783282b45afcd4af95fd1c7bdb Mon Sep 17 00:00:00 2001 From: fantasticit Date: Mon, 30 May 2022 17:32:34 +0800 Subject: [PATCH] client: use popover instead of modal --- .../document/collaboration/index.tsx | 164 +++++++++--------- 1 file changed, 85 insertions(+), 79 deletions(-) diff --git a/packages/client/src/components/document/collaboration/index.tsx b/packages/client/src/components/document/collaboration/index.tsx index 27a04926..11466727 100644 --- a/packages/client/src/components/document/collaboration/index.tsx +++ b/packages/client/src/components/document/collaboration/index.tsx @@ -7,6 +7,7 @@ import { Input, Modal, Popconfirm, + Popover, Spin, Table, TabPane, @@ -21,8 +22,9 @@ import { DocumentLinkCopyer } from 'components/document/link'; import { useDoumentMembers } from 'data/document'; import { useUser } from 'data/user'; import { event, JOIN_USER } from 'event'; +import { IsOnMobile } from 'hooks/use-on-mobile'; import { useToggle } from 'hooks/use-toggle'; -import React, { useEffect, useRef, useState } from 'react'; +import React, { useCallback, useEffect, useRef, useState } from 'react'; interface IProps { wikiId: string; @@ -48,7 +50,9 @@ const renderChecked = (onChange, authKey: 'readable' | 'editable') => (checked, }; export const DocumentCollaboration: React.FC = ({ wikiId, documentId, disabled = false }) => { + const { isMobile } = IsOnMobile.useHook(); const toastedUsersRef = useRef>([]); + const ref = useRef(); const { user: currentUser } = useUser(); const [visible, toggleVisible] = useToggle(false); const { users, loading, error, addUser, updateUser, deleteUser } = useDoumentMembers(documentId, { @@ -57,20 +61,29 @@ export const DocumentCollaboration: React.FC = ({ wikiId, documentId, di const [inviteUser, setInviteUser] = useState(''); const [collaborationUsers, setCollaborationUsers] = useState([]); - const handleOk = () => { + const handleOk = useCallback(() => { addUser(inviteUser).then(() => { Toast.success('添加成功'); setInviteUser(''); }); - }; + }, [addUser, inviteUser]); - const handleDelete = (docAuth) => { - const data = { - ...docAuth.auth, - userName: docAuth.user.name, - }; - deleteUser(data); - }; + const handleDelete = useCallback( + (docAuth) => { + const data = { + ...docAuth.auth, + userName: docAuth.user.name, + }; + deleteUser(data); + }, + [deleteUser] + ); + + useEffect(() => { + if (visible) { + setTimeout(() => ref.current?.focus(), 100); + } + }, [visible]); useEffect(() => { const handler = (mentionUsers) => { @@ -126,77 +139,70 @@ export const DocumentCollaboration: React.FC = ({ wikiId, documentId, di ); })} - - - - toggleVisible(false)} - style={{ maxWidth: '96vw' }} - footer={null} + onVisibleChange={toggleVisible} + trigger="click" + position={isMobile ? 'top' : 'bottomLeft'} + style={{ width: 376, maxWidth: '80vw' }} + content={ + + +
+ + + 邀请成功后,请将该链接发送给对方。 + + + + + +
+
+ + } + normalContent={() => ( + + + + + ( + handleDelete(document)}> +
+ )} + /> +
+
+ } > - - -
- - - 邀请成功后,请将该链接发送给对方。 - - - - - -
-
- - } - normalContent={() => ( - - - - - ( - handleDelete(document)}> -
- )} - /> -
-
-
+