mirror of https://github.com/fantasticit/think.git
client: imrpove data fetch
This commit is contained in:
parent
b44c8f831d
commit
f2e4722557
|
@ -51,7 +51,9 @@ export const DocumentCollaboration: React.FC<IProps> = ({ wikiId, documentId, di
|
||||||
const toastedUsersRef = useRef<Array<IUser['id']>>([]);
|
const toastedUsersRef = useRef<Array<IUser['id']>>([]);
|
||||||
const { user: currentUser } = useUser();
|
const { user: currentUser } = useUser();
|
||||||
const [visible, toggleVisible] = useToggle(false);
|
const [visible, toggleVisible] = useToggle(false);
|
||||||
const { users, loading, error, addUser, updateUser, deleteUser } = useDoumentMembers(documentId);
|
const { users, loading, error, addUser, updateUser, deleteUser } = useDoumentMembers(documentId, {
|
||||||
|
enabled: visible,
|
||||||
|
});
|
||||||
const [inviteUser, setInviteUser] = useState('');
|
const [inviteUser, setInviteUser] = useState('');
|
||||||
const [collaborationUsers, setCollaborationUsers] = useState([]);
|
const [collaborationUsers, setCollaborationUsers] = useState([]);
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ const { Text } = Typography;
|
||||||
|
|
||||||
export const DocumentShare: React.FC<IProps> = ({ documentId, disabled = false, render }) => {
|
export const DocumentShare: React.FC<IProps> = ({ documentId, disabled = false, render }) => {
|
||||||
const [visible, toggleVisible] = useToggle(false);
|
const [visible, toggleVisible] = useToggle(false);
|
||||||
const { data, loading, error, toggleStatus } = useDocumentDetail(documentId);
|
const { data, loading, error, 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]);
|
||||||
|
|
|
@ -17,6 +17,7 @@ export const DocumentStyle = () => {
|
||||||
return (
|
return (
|
||||||
<Popover
|
<Popover
|
||||||
key="style"
|
key="style"
|
||||||
|
trigger="click"
|
||||||
zIndex={1061}
|
zIndex={1061}
|
||||||
position={isMobile ? 'topRight' : 'bottomLeft'}
|
position={isMobile ? 'topRight' : 'bottomLeft'}
|
||||||
visible={visible}
|
visible={visible}
|
||||||
|
|
|
@ -59,9 +59,11 @@ export const getDocumentMembers = (documentId, cookie = null): Promise<Array<{ u
|
||||||
* @param documentId
|
* @param documentId
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export const useDoumentMembers = (documentId) => {
|
export const useDoumentMembers = (documentId, options?: UseQueryOptions<Array<{ user: IUser; auth: IAuthority }>>) => {
|
||||||
const { data, error, isLoading, refetch } = useQuery(DocumentApiDefinition.getMemberById.client(documentId), () =>
|
const { data, error, isLoading, refetch } = useQuery(
|
||||||
getDocumentMembers(documentId)
|
DocumentApiDefinition.getMemberById.client(documentId),
|
||||||
|
() => getDocumentMembers(documentId),
|
||||||
|
options
|
||||||
);
|
);
|
||||||
|
|
||||||
const addUser = useCallback(
|
const addUser = useCallback(
|
||||||
|
@ -135,11 +137,11 @@ export const getDocumentDetail = (documentId, cookie = null): Promise<IDocumentW
|
||||||
* @param documentId
|
* @param documentId
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export const useDocumentDetail = (documentId) => {
|
export const useDocumentDetail = (documentId, options: UseQueryOptions<IDocumentWithAuth> = {}) => {
|
||||||
const { data, error, isLoading, refetch } = useQuery(
|
const { data, error, isLoading, refetch } = useQuery(
|
||||||
DocumentApiDefinition.getDetailById.client(documentId),
|
DocumentApiDefinition.getDetailById.client(documentId),
|
||||||
() => getDocumentDetail(documentId),
|
() => getDocumentDetail(documentId),
|
||||||
{ staleTime: 3000, refetchOnReconnect: true, refetchOnMount: true, refetchOnWindowFocus: true }
|
{ ...options, staleTime: 3000 }
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue