diff --git a/packages/client/src/components/document/collaboration/index.tsx b/packages/client/src/components/document/collaboration/index.tsx index de4dfb3..7ab8951 100644 --- a/packages/client/src/components/document/collaboration/index.tsx +++ b/packages/client/src/components/document/collaboration/index.tsx @@ -15,17 +15,19 @@ import { Tooltip, Typography, } from '@douyinfe/semi-ui'; +import { IUser } from '@think/domains'; import { DataRender } from 'components/data-render'; import { DocumentLinkCopyer } from 'components/document/link'; import { useDoumentMembers } from 'data/document'; import { useUser } from 'data/user'; import { event, JOIN_USER } from 'event'; import { useToggle } from 'hooks/use-toggle'; -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useRef, useState } from 'react'; interface IProps { wikiId: string; documentId: string; + disabled?: boolean; } const { Paragraph } = Typography; @@ -45,7 +47,8 @@ const renderChecked = (onChange, authKey: 'readable' | 'editable') => (checked, return ; }; -export const DocumentCollaboration: React.FC = ({ wikiId, documentId }) => { +export const DocumentCollaboration: React.FC = ({ wikiId, documentId, disabled = false }) => { + const toastedUsersRef = useRef>([]); const { user: currentUser } = useUser(); const [visible, toggleVisible] = useToggle(false); const { users, loading, error, addUser, updateUser, deleteUser } = useDoumentMembers(documentId); @@ -84,8 +87,9 @@ export const DocumentCollaboration: React.FC = ({ wikiId, documentId }) } newCollaborationUsers.forEach((newUser) => { - if (currentUser && newUser.name !== currentUser.name) { + if (currentUser && newUser.name !== currentUser.name && !toastedUsersRef.current.includes(newUser.id)) { Toast.info(`${newUser.name}加入文档`); + toastedUsersRef.current.push(newUser.id); } }); @@ -95,6 +99,7 @@ export const DocumentCollaboration: React.FC = ({ wikiId, documentId }) event.on(JOIN_USER, handler); return () => { + toastedUsersRef.current = []; event.off(JOIN_USER, handler); }; }, [collaborationUsers, currentUser]); @@ -120,7 +125,13 @@ export const DocumentCollaboration: React.FC = ({ wikiId, documentId }) })} - + = ({ documentId }) => { const { user } = useUser(); const { data: documentAndAuth, loading: docAuthLoading, error: docAuthError } = useDocumentDetail(documentId); const { document, authority } = documentAndAuth || {}; + const [readable, editable] = useMemo(() => { + if (!authority) return [false, false]; + return [authority.readable, authority.editable]; + }, [authority]); const renderAuthor = useCallback( (element) => { if (!document) return null; - const target = element && element.querySelector('.ProseMirror .title'); if (target) { @@ -75,29 +78,28 @@ export const DocumentReader: React.FC = ({ documentId }) => { Router.push(`/wiki/${document.wikiId}/document/${document.id}/edit`); }, [document]); - const actions = useMemo( - () => ( + const actions = useMemo(() => { + console.log({ readable, editable }); + return ( - {document && authority.readable && ( - - )} - {authority && authority.editable && ( - - )} diff --git a/packages/client/src/components/document/star/index.tsx b/packages/client/src/components/document/star/index.tsx index 4572106..8e2c9ef 100644 --- a/packages/client/src/components/document/star/index.tsx +++ b/packages/client/src/components/document/star/index.tsx @@ -5,17 +5,23 @@ import React from 'react'; interface IProps { documentId: string; - render?: (arg: { star: boolean; text: string; toggleStar: () => Promise }) => React.ReactNode; + disabled?: boolean; + render?: (arg: { + star: boolean; + disabled: boolean; + text: string; + toggleStar: () => Promise; + }) => React.ReactNode; } -export const DocumentStar: React.FC = ({ documentId, render }) => { +export const DocumentStar: React.FC = ({ documentId, disabled = false, render }) => { const { data, toggle: toggleStar } = useDocumentCollectToggle(documentId); const text = data ? '取消收藏' : '收藏文档'; return ( <> {render ? ( - render({ star: data, toggleStar, text }) + render({ star: data, disabled, toggleStar, text }) ) : ( = ({ documentId, onSelect }) => { theme="light" type="primary" style={{ marginRight: 8 }} - disabled={loading || error} + disabled={loading || !!error} loading={loading} onClick={() => refresh()} > diff --git a/packages/client/src/data/document.tsx b/packages/client/src/data/document.tsx index e9aad94..762b7c1 100644 --- a/packages/client/src/data/document.tsx +++ b/packages/client/src/data/document.tsx @@ -139,7 +139,7 @@ export const useDocumentDetail = (documentId) => { const { data, error, isLoading, refetch } = useQuery( DocumentApiDefinition.getDetailById.client(documentId), () => getDocumentDetail(documentId), - { staleTime: 3000 } + { staleTime: 3000, refetchOnReconnect: true, refetchOnMount: true, refetchOnWindowFocus: true } ); /** diff --git a/packages/client/src/tiptap/editor/collaboration/collaboration/index.module.scss b/packages/client/src/tiptap/editor/collaboration/collaboration/index.module.scss index 7fa735a..10a6f85 100644 --- a/packages/client/src/tiptap/editor/collaboration/collaboration/index.module.scss +++ b/packages/client/src/tiptap/editor/collaboration/collaboration/index.module.scss @@ -2,6 +2,7 @@ display: flex; width: 100%; height: 100%; + min-height: 100px; overflow: hidden; flex-direction: column;