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 * @returns
*/ */
export const useWikiCollectToggle = (wikiId) => { 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) getWikiIsCollected(wikiId)
); );

View File

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

View File

@ -13,7 +13,15 @@ import { Hydrate, QueryClient, QueryClientProvider } from 'react-query';
class MyApp extends App<{ isMobile: boolean }> { class MyApp extends App<{ isMobile: boolean }> {
state = { state = {
queryClient: new QueryClient(), queryClient: new QueryClient({
defaultOptions: {
queries: {
refetchOnWindowFocus: true,
retry: false,
staleTime: 30000,
},
},
}),
}; };
static getInitialProps = async ({ Component, ctx }) => { 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="visitedAt" key="visitedAt" render={(date) => <LocaleTime date={date} />} />,
<Column title="更新时间" dataIndex="updatedAt" key="updatedAt" render={(date) => <LocaleTime date={date} />} />,
<Column <Column
title="操作" title="操作"
dataIndex="operate" dataIndex="operate"

View File

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

View File

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