Просмотр исходного кода

add and use usePageInfoTermManager

Yohei-Shiina 3 лет назад
Родитель
Сommit
bee09ec3ed
1 измененных файлов с 8 добавлено и 2 удалено
  1. 8 2
      packages/app/src/stores/page.tsx

+ 8 - 2
packages/app/src/stores/page.tsx

@@ -16,7 +16,7 @@ import { IRevisionsForPagination } from '~/interfaces/revision';
 import { IPageTagsInfo } from '../interfaces/tag';
 import { IPageTagsInfo } from '../interfaces/tag';
 
 
 import { useCurrentPageId, useCurrentPathname, useCurrentRevisionId } from './context';
 import { useCurrentPageId, useCurrentPathname, useCurrentRevisionId } from './context';
-import { useStaticSWR } from './use-static-swr';
+import { ITermNumberManagerUtil, useStaticSWR, useTermNumberManager } from './use-static-swr';
 
 
 const { isPermalink: _isPermalink } = pagePathUtils;
 const { isPermalink: _isPermalink } = pagePathUtils;
 
 
@@ -82,17 +82,23 @@ export const useSWRxTagsInfo = (pageId: Nullable<string>): SWRResponse<IPageTags
   return useSWRImmutable(key, fetcher);
   return useSWRImmutable(key, fetcher);
 };
 };
 
 
+export const usePageInfoTermManager = (isDisabled?: boolean) : SWRResponse<number, Error> & ITermNumberManagerUtil => {
+  return useTermNumberManager(isDisabled === true ? null : 'descendantsPageListForCurrentPathTermNumber');
+};
+
 export const useSWRxPageInfo = (
 export const useSWRxPageInfo = (
     pageId: string | null | undefined,
     pageId: string | null | undefined,
     shareLinkId?: string | null,
     shareLinkId?: string | null,
     initialData?: IPageInfoForEntity,
     initialData?: IPageInfoForEntity,
 ): SWRResponse<IPageInfo | IPageInfoForOperation, Error> => {
 ): SWRResponse<IPageInfo | IPageInfoForOperation, Error> => {
 
 
+  const { data: termNumber } = usePageInfoTermManager();
+
   // assign null if shareLinkId is undefined in order to identify SWR key only by pageId
   // assign null if shareLinkId is undefined in order to identify SWR key only by pageId
   const fixedShareLinkId = shareLinkId ?? null;
   const fixedShareLinkId = shareLinkId ?? null;
 
 
   const swrResult = useSWRImmutable<IPageInfo | IPageInfoForOperation, Error>(
   const swrResult = useSWRImmutable<IPageInfo | IPageInfoForOperation, Error>(
-    pageId != null ? ['/page/info', pageId, fixedShareLinkId] : null,
+    pageId != null && termNumber != null ? ['/page/info', pageId, fixedShareLinkId, termNumber] : null,
     (endpoint, pageId, shareLinkId) => apiv3Get(endpoint, { pageId, shareLinkId }).then(response => response.data),
     (endpoint, pageId, shareLinkId) => apiv3Get(endpoint, { pageId, shareLinkId }).then(response => response.data),
     { fallbackData: initialData },
     { fallbackData: initialData },
   );
   );