feat: improve data fetch

This commit is contained in:
fantasticit 2022-05-24 18:50:39 +08:00
parent 4b2722757d
commit 0c37cdf403
6 changed files with 22 additions and 17 deletions

View File

@ -66,7 +66,7 @@ export const toggleCollectWiki = (wikiId, cookie = null): Promise<boolean> => {
* @returns
*/
export const useWikiCollectToggle = (wikiId) => {
const { data, error, refetch } = useQuery(`${CollectorApiDefinition.check.client()}?wikiId=${wikiId}`, () =>
const { data, error, refetch } = useQuery([CollectorApiDefinition.check.client(), wikiId], () =>
getWikiIsCollected(wikiId)
);

View File

@ -296,7 +296,11 @@ export const getDocumentChildren = (data, cookie = null): Promise<Array<IDocumen
*/
export const useChildrenDocument = ({ wikiId, documentId, isShare = false }) => {
const { data, error, refetch } = useQuery(
[
isShare ? DocumentApiDefinition.getPublicChildren.client() : DocumentApiDefinition.getChildren.client(),
wikiId,
documentId,
],
() => getDocumentChildren({ wikiId, documentId, isShare })
);
const loading = !data && !error;

View File

@ -13,7 +13,15 @@ import { Hydrate, QueryClient, QueryClientProvider } from 'react-query';
class MyApp extends App<{ isMobile: boolean }> {
state = {
queryClient: new QueryClient(),
queryClient: new QueryClient({
defaultOptions: {
queries: {
refetchOnWindowFocus: true,
retry: false,
staleTime: 30000,
},
},
}),
};
static getInitialProps = async ({ Component, ctx }) => {

View File

@ -65,7 +65,6 @@ const RecentDocs = () => {
}}
/>,
<Column title="访问时间" dataIndex="visitedAt" key="visitedAt" render={(date) => <LocaleTime date={date} />} />,
<Column title="更新时间" dataIndex="updatedAt" key="updatedAt" render={(date) => <LocaleTime date={date} />} />,
<Column
title="操作"
dataIndex="operate"

View File

@ -8,7 +8,6 @@ import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, use
import { IndexeddbPersistence } from 'tiptap/core/y-indexeddb';
import { Editor } from '../../react';
import { ReaderEditor } from '../reader';
import { EditorInstance } from './editor';
import styles from './index.module.scss';
import { ICollaborationEditorProps, ProviderStatus } from './type';
@ -27,7 +26,6 @@ export const CollaborationEditor = forwardRef((props: ICollaborationEditorProps,
onTitleUpdate,
user,
menubar,
initialContent,
renderInEditorPortal,
onAwarenessUpdate,
} = props;
@ -100,16 +98,12 @@ export const CollaborationEditor = forwardRef((props: ICollaborationEditorProps,
<DataRender
loading={loading}
loadingContent={
initialContent ? (
<ReaderEditor content={initialContent} />
) : (
<div style={{ width: 174, margin: 'auto' }}>
<Spin tip="正在为您加载编辑器中...">
<Spin tip="正在加载中...">
{/* FIXME: semi-design 的问题,不加 div文字会换行! */}
<div></div>
</Spin>
</div>
)
}
error={error}
errorContent={(error) => (

View File

@ -3,7 +3,7 @@ import { Injectable } from '@nestjs/common';
import * as cluster from 'cluster';
import * as os from 'os';
const numCPUs = os.cpus().length;
const numCPUs = os.cpus().length - 2;
@Injectable()
export class AppClusterService {