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

impl mutateSearching instead of useFullTextSearchTermManager

Yuki Takei 3 лет назад
Родитель
Сommit
ae97be1d8a

+ 7 - 10
packages/app/src/components/SearchPage/SearchResultContent.tsx

@@ -20,7 +20,7 @@ import {
 } from '~/stores/modal';
 } from '~/stores/modal';
 import { mutateDescendantsPageListForCurrentPath, mutatePageTree } from '~/stores/page-listing';
 import { mutateDescendantsPageListForCurrentPath, mutatePageTree } from '~/stores/page-listing';
 import { useSearchResultOptions } from '~/stores/renderer';
 import { useSearchResultOptions } from '~/stores/renderer';
-import { useFullTextSearchTermManager } from '~/stores/search';
+import { mutateSearching } from '~/stores/search';
 
 
 import { AdditionalMenuItemsRendererProps, ForceHideMenuItems } from '../Common/Dropdown/PageItemControl';
 import { AdditionalMenuItemsRendererProps, ForceHideMenuItems } from '../Common/Dropdown/PageItemControl';
 import { GrowiSubNavigationProps } from '../Navbar/GrowiSubNavigation';
 import { GrowiSubNavigationProps } from '../Navbar/GrowiSubNavigation';
@@ -91,9 +91,6 @@ export const SearchResultContent: FC<Props> = (props: Props) => {
   const [isRevisionLoaded, setRevisionLoaded] = useState(false);
   const [isRevisionLoaded, setRevisionLoaded] = useState(false);
   const [isPageCommentLoaded, setPageCommentLoaded] = useState(false);
   const [isPageCommentLoaded, setPageCommentLoaded] = useState(false);
 
 
-  // for mutation
-  const { advance: advanceFts } = useFullTextSearchTermManager();
-
   // ***************************  Auto Scroll  ***************************
   // ***************************  Auto Scroll  ***************************
   useEffect(() => {
   useEffect(() => {
     const scrollElement = scrollElementRef.current;
     const scrollElement = scrollElementRef.current;
@@ -166,22 +163,22 @@ export const SearchResultContent: FC<Props> = (props: Props) => {
       toastSuccess(t('duplicated_pages', { fromPath }));
       toastSuccess(t('duplicated_pages', { fromPath }));
 
 
       mutatePageTree();
       mutatePageTree();
-      advanceFts();
+      mutateSearching();
       mutateDescendantsPageListForCurrentPath();
       mutateDescendantsPageListForCurrentPath();
     };
     };
     openDuplicateModal(pageToDuplicate, { onDuplicated: duplicatedHandler });
     openDuplicateModal(pageToDuplicate, { onDuplicated: duplicatedHandler });
-  }, [advanceFts, openDuplicateModal, t]);
+  }, [openDuplicateModal, t]);
 
 
   const renameItemClickedHandler = useCallback((pageToRename: IPageToRenameWithMeta) => {
   const renameItemClickedHandler = useCallback((pageToRename: IPageToRenameWithMeta) => {
     const renamedHandler: OnRenamedFunction = (path) => {
     const renamedHandler: OnRenamedFunction = (path) => {
       toastSuccess(t('renamed_pages', { path }));
       toastSuccess(t('renamed_pages', { path }));
 
 
       mutatePageTree();
       mutatePageTree();
-      advanceFts();
+      mutateSearching();
       mutateDescendantsPageListForCurrentPath();
       mutateDescendantsPageListForCurrentPath();
     };
     };
     openRenameModal(pageToRename, { onRenamed: renamedHandler });
     openRenameModal(pageToRename, { onRenamed: renamedHandler });
-  }, [advanceFts, openRenameModal, t]);
+  }, [openRenameModal, t]);
 
 
   const onDeletedHandler: OnDeletedFunction = useCallback((pathOrPathsToDelete, isRecursively, isCompletely) => {
   const onDeletedHandler: OnDeletedFunction = useCallback((pathOrPathsToDelete, isRecursively, isCompletely) => {
     if (typeof pathOrPathsToDelete !== 'string') {
     if (typeof pathOrPathsToDelete !== 'string') {
@@ -196,9 +193,9 @@ export const SearchResultContent: FC<Props> = (props: Props) => {
       toastSuccess(t('deleted_pages', { path }));
       toastSuccess(t('deleted_pages', { path }));
     }
     }
     mutatePageTree();
     mutatePageTree();
-    advanceFts();
+    mutateSearching();
     mutateDescendantsPageListForCurrentPath();
     mutateDescendantsPageListForCurrentPath();
-  }, [advanceFts, t]);
+  }, [t]);
 
 
   const deleteItemClickedHandler = useCallback((pageToDelete: IPageToDeleteWithMeta) => {
   const deleteItemClickedHandler = useCallback((pageToDelete: IPageToDeleteWithMeta) => {
     openDeleteModal([pageToDelete], { onDeleted: onDeletedHandler });
     openDeleteModal([pageToDelete], { onDeleted: onDeletedHandler });

+ 11 - 14
packages/app/src/components/SearchPage/SearchResultList.tsx

@@ -11,10 +11,9 @@ import {
   IPageInfoForListing, IPageWithMeta, isIPageInfoForListing,
   IPageInfoForListing, IPageWithMeta, isIPageInfoForListing,
 } from '~/interfaces/page';
 } from '~/interfaces/page';
 import { IPageSearchMeta, IPageWithSearchMeta } from '~/interfaces/search';
 import { IPageSearchMeta, IPageWithSearchMeta } from '~/interfaces/search';
-import { OnDuplicatedFunction, OnRenamedFunction, OnDeletedFunction } from '~/interfaces/ui';
 import { useIsGuestUser } from '~/stores/context';
 import { useIsGuestUser } from '~/stores/context';
 import { mutatePageTree, useSWRxPageInfoForList } from '~/stores/page-listing';
 import { mutatePageTree, useSWRxPageInfoForList } from '~/stores/page-listing';
-import { useFullTextSearchTermManager } from '~/stores/search';
+import { mutateSearching } from '~/stores/search';
 
 
 import { ForceHideMenuItems } from '../Common/Dropdown/PageItemControl';
 import { ForceHideMenuItems } from '../Common/Dropdown/PageItemControl';
 import { PageListItemL } from '../PageList/PageListItemL';
 import { PageListItemL } from '../PageList/PageListItemL';
@@ -44,9 +43,6 @@ const SearchResultListSubstance: ForwardRefRenderFunction<ISelectableAll, Props>
   const { data: isGuestUser } = useIsGuestUser();
   const { data: isGuestUser } = useIsGuestUser();
   const { data: idToPageInfo } = useSWRxPageInfoForList(pageIdsWithNoSnippet, null, true, true);
   const { data: idToPageInfo } = useSWRxPageInfoForList(pageIdsWithNoSnippet, null, true, true);
 
 
-  // for mutation
-  const { advance: advanceFts } = useFullTextSearchTermManager();
-
   const itemsRef = useRef<(ISelectable|null)[]>([]);
   const itemsRef = useRef<(ISelectable|null)[]>([]);
 
 
   // publish selectAll()
   // publish selectAll()
@@ -94,20 +90,21 @@ const SearchResultListSubstance: ForwardRefRenderFunction<ISelectableAll, Props>
   }
   }
 
 
   // eslint-disable-next-line @typescript-eslint/no-unused-vars
   // eslint-disable-next-line @typescript-eslint/no-unused-vars
-  const duplicatedHandler : OnDuplicatedFunction = (fromPath, toPath) => {
+  const duplicatedHandler = useCallback((fromPath, toPath) => {
     toastSuccess(t('duplicated_pages', { fromPath }));
     toastSuccess(t('duplicated_pages', { fromPath }));
 
 
     mutatePageTree();
     mutatePageTree();
-    advanceFts();
-  };
+    mutateSearching();
+  }, [t]);
 
 
-  const renamedHandler: OnRenamedFunction = (path) => {
+  const renamedHandler = useCallback((path) => {
     toastSuccess(t('renamed_pages', { path }));
     toastSuccess(t('renamed_pages', { path }));
 
 
     mutatePageTree();
     mutatePageTree();
-    advanceFts();
-  };
-  const deletedHandler: OnDeletedFunction = (pathOrPathsToDelete, isRecursively, isCompletely) => {
+    mutateSearching();
+  }, [t]);
+
+  const deletedHandler = useCallback((pathOrPathsToDelete, isRecursively, isCompletely) => {
     if (typeof pathOrPathsToDelete !== 'string') {
     if (typeof pathOrPathsToDelete !== 'string') {
       return;
       return;
     }
     }
@@ -121,8 +118,8 @@ const SearchResultListSubstance: ForwardRefRenderFunction<ISelectableAll, Props>
       toastSuccess(t('deleted_pages', { path }));
       toastSuccess(t('deleted_pages', { path }));
     }
     }
     mutatePageTree();
     mutatePageTree();
-    advanceFts();
-  };
+    mutateSearching();
+  }, [t]);
 
 
   return (
   return (
     <ul data-testid="search-result-list" className="page-list-ul list-group list-group-flush">
     <ul data-testid="search-result-list" className="page-list-ul list-group list-group-flush">

+ 7 - 8
packages/app/src/components/Sidebar/PageTree/ItemsTree.tsx

@@ -20,7 +20,7 @@ import { mutateAllPageInfo, useCurrentPagePath, useSWRMUTxCurrentPage } from '~/
 import {
 import {
   useSWRxPageAncestorsChildren, useSWRxRootPage, mutatePageTree, mutateDescendantsPageListForCurrentPath,
   useSWRxPageAncestorsChildren, useSWRxRootPage, mutatePageTree, mutateDescendantsPageListForCurrentPath,
 } from '~/stores/page-listing';
 } from '~/stores/page-listing';
-import { useFullTextSearchTermManager } from '~/stores/search';
+import { mutateSearching } from '~/stores/search';
 import { usePageTreeDescCountMap, useSidebarScrollerRef } from '~/stores/ui';
 import { usePageTreeDescCountMap, useSidebarScrollerRef } from '~/stores/ui';
 import { useGlobalSocket } from '~/stores/websocket';
 import { useGlobalSocket } from '~/stores/websocket';
 import loggerFactory from '~/utils/logger';
 import loggerFactory from '~/utils/logger';
@@ -118,7 +118,6 @@ const ItemsTree = (props: ItemsTreeProps): JSX.Element => {
 
 
   // for mutation
   // for mutation
   const { trigger: mutateCurrentPage } = useSWRMUTxCurrentPage();
   const { trigger: mutateCurrentPage } = useSWRMUTxCurrentPage();
-  const { advance: advanceFts } = useFullTextSearchTermManager();
 
 
   const [isInitialScrollCompleted, setIsInitialScrollCompleted] = useState(false);
   const [isInitialScrollCompleted, setIsInitialScrollCompleted] = useState(false);
 
 
@@ -149,13 +148,13 @@ const ItemsTree = (props: ItemsTreeProps): JSX.Element => {
 
 
   const onRenamed = useCallback((fromPath: string | undefined, toPath: string) => {
   const onRenamed = useCallback((fromPath: string | undefined, toPath: string) => {
     mutatePageTree();
     mutatePageTree();
-    advanceFts();
+    mutateSearching();
     mutateDescendantsPageListForCurrentPath();
     mutateDescendantsPageListForCurrentPath();
 
 
     if (currentPagePath === fromPath || currentPagePath === toPath) {
     if (currentPagePath === fromPath || currentPagePath === toPath) {
       mutateCurrentPage();
       mutateCurrentPage();
     }
     }
-  }, [advanceFts, currentPagePath, mutateCurrentPage]);
+  }, [currentPagePath, mutateCurrentPage]);
 
 
   const onClickDuplicateMenuItem = useCallback((pageToDuplicate: IPageForPageDuplicateModal) => {
   const onClickDuplicateMenuItem = useCallback((pageToDuplicate: IPageForPageDuplicateModal) => {
     // eslint-disable-next-line @typescript-eslint/no-unused-vars
     // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -163,12 +162,12 @@ const ItemsTree = (props: ItemsTreeProps): JSX.Element => {
       toastSuccess(t('duplicated_pages', { fromPath }));
       toastSuccess(t('duplicated_pages', { fromPath }));
 
 
       mutatePageTree();
       mutatePageTree();
-      advanceFts();
+      mutateSearching();
       mutateDescendantsPageListForCurrentPath();
       mutateDescendantsPageListForCurrentPath();
     };
     };
 
 
     openDuplicateModal(pageToDuplicate, { onDuplicated: duplicatedHandler });
     openDuplicateModal(pageToDuplicate, { onDuplicated: duplicatedHandler });
-  }, [advanceFts, openDuplicateModal, t]);
+  }, [openDuplicateModal, t]);
 
 
   const onClickDeleteMenuItem = useCallback((pageToDelete: IPageToDeleteWithMeta) => {
   const onClickDeleteMenuItem = useCallback((pageToDelete: IPageToDeleteWithMeta) => {
     const onDeletedHandler: OnDeletedFunction = (pathOrPathsToDelete, isRecursively, isCompletely) => {
     const onDeletedHandler: OnDeletedFunction = (pathOrPathsToDelete, isRecursively, isCompletely) => {
@@ -186,7 +185,7 @@ const ItemsTree = (props: ItemsTreeProps): JSX.Element => {
       }
       }
 
 
       mutatePageTree();
       mutatePageTree();
-      advanceFts();
+      mutateSearching();
       mutateDescendantsPageListForCurrentPath();
       mutateDescendantsPageListForCurrentPath();
       mutateAllPageInfo();
       mutateAllPageInfo();
 
 
@@ -197,7 +196,7 @@ const ItemsTree = (props: ItemsTreeProps): JSX.Element => {
     };
     };
 
 
     openDeleteModal([pageToDelete], { onDeleted: onDeletedHandler });
     openDeleteModal([pageToDelete], { onDeleted: onDeletedHandler });
-  }, [advanceFts, currentPagePath, mutateCurrentPage, openDeleteModal, router, t]);
+  }, [currentPagePath, mutateCurrentPage, openDeleteModal, router, t]);
 
 
   // ***************************  Scroll on init ***************************
   // ***************************  Scroll on init ***************************
   const scrollOnInit = useCallback(() => {
   const scrollOnInit = useCallback(() => {

+ 1 - 1
packages/app/src/stores/page-listing.tsx

@@ -75,7 +75,7 @@ export const useSWRxPageList = (
 };
 };
 
 
 const MUTATION_ID_FOR_DESCENDANTS_PAGELIST_FOR_CURRENT_PATH = 'descendantsPageListForCurrentPath';
 const MUTATION_ID_FOR_DESCENDANTS_PAGELIST_FOR_CURRENT_PATH = 'descendantsPageListForCurrentPath';
-export const mutateDescendantsPageListForCurrentPath = async(): Promise<any[]> => {
+export const mutateDescendantsPageListForCurrentPath = async(): Promise<void[]> => {
   return mutate(
   return mutate(
     key => Array.isArray(key) && key[0] === MUTATION_ID_FOR_DESCENDANTS_PAGELIST_FOR_CURRENT_PATH,
     key => Array.isArray(key) && key[0] === MUTATION_ID_FOR_DESCENDANTS_PAGELIST_FOR_CURRENT_PATH,
   );
   );

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

@@ -21,7 +21,6 @@ import { IPageTagsInfo } from '../interfaces/tag';
 import {
 import {
   useCurrentPageId, useCurrentPathname, useShareLinkId, useIsGuestUser,
   useCurrentPageId, useCurrentPathname, useShareLinkId, useIsGuestUser,
 } from './context';
 } from './context';
-import { ITermNumberManagerUtil, useTermNumberManager } from './use-static-swr';
 
 
 const { isPermalink: _isPermalink } = pagePathUtils;
 const { isPermalink: _isPermalink } = pagePathUtils;
 
 
@@ -98,7 +97,7 @@ export const useSWRxTagsInfo = (pageId: Nullable<string>): SWRResponse<IPageTags
   );
   );
 };
 };
 
 
-export const mutateAllPageInfo = (): Promise<any[]> => {
+export const mutateAllPageInfo = (): Promise<void[]> => {
   return mutate(
   return mutate(
     key => Array.isArray(key) && key[0] === '/page/info',
     key => Array.isArray(key) && key[0] === '/page/info',
   );
   );

+ 9 - 12
packages/app/src/stores/search.tsx

@@ -1,16 +1,9 @@
-import { SWRResponse } from 'swr';
+import { mutate, SWRResponse } from 'swr';
 import useSWRImmutable from 'swr/immutable';
 import useSWRImmutable from 'swr/immutable';
 
 
 import { apiGet } from '~/client/util/apiv1-client';
 import { apiGet } from '~/client/util/apiv1-client';
 import { IFormattedSearchResult, SORT_AXIS, SORT_ORDER } from '~/interfaces/search';
 import { IFormattedSearchResult, SORT_AXIS, SORT_ORDER } from '~/interfaces/search';
 
 
-import { ITermNumberManagerUtil, useTermNumberManager } from './use-static-swr';
-
-
-export const useFullTextSearchTermManager = (isDisabled?: boolean) : SWRResponse<number, Error> & ITermNumberManagerUtil => {
-  return useTermNumberManager(isDisabled === true ? null : 'fullTextSearchTermNumber');
-};
-
 
 
 export type ISearchConfigurations = {
 export type ISearchConfigurations = {
   limit: number,
   limit: number,
@@ -49,11 +42,15 @@ const createSearchQuery = (keyword: string, includeTrashPages: boolean, includeU
   return query;
   return query;
 };
 };
 
 
+export const mutateSearching = async(): Promise<void[]> => {
+  return mutate(
+    key => Array.isArray(key) && key[0] === '/search',
+  );
+};
+
 export const useSWRxSearch = (
 export const useSWRxSearch = (
-    keyword: string | null, nqName: string | null, configurations: ISearchConfigurations, disableTermManager = false,
+    keyword: string | null, nqName: string | null, configurations: ISearchConfigurations,
 ): SWRResponse<IFormattedSearchResult, Error> & { conditions: ISearchConditions } => {
 ): SWRResponse<IFormattedSearchResult, Error> & { conditions: ISearchConditions } => {
-  const { data: termNumber } = useFullTextSearchTermManager(disableTermManager);
-
   const {
   const {
     limit, offset, sort, order, includeTrashPages, includeUserPages,
     limit, offset, sort, order, includeTrashPages, includeUserPages,
   } = configurations;
   } = configurations;
@@ -71,7 +68,7 @@ export const useSWRxSearch = (
   const isKeywordValid = keyword != null && keyword.length > 0;
   const isKeywordValid = keyword != null && keyword.length > 0;
 
 
   const swrResult = useSWRImmutable(
   const swrResult = useSWRImmutable(
-    isKeywordValid ? ['/search', keyword, fixedConfigurations, termNumber] : null,
+    isKeywordValid ? ['/search', keyword, fixedConfigurations] : null,
     ([endpoint, , fixedConfigurations]) => {
     ([endpoint, , fixedConfigurations]) => {
       const {
       const {
         limit, offset, sort, order,
         limit, offset, sort, order,

+ 0 - 25
packages/app/src/stores/use-static-swr.tsx

@@ -33,28 +33,3 @@ export function useStaticSWR<Data, Error>(
 
 
   return swrResponse;
   return swrResponse;
 }
 }
-
-
-const ADVANCE_DELAY_MS = 800;
-
-export type ITermNumberManagerUtil = {
-  advance(): void,
-}
-
-export const useTermNumberManager = (key: Key) : SWRResponse<number, Error> & ITermNumberManagerUtil => {
-  const swrResult = useStaticSWR<number, Error>(key, undefined, { fallbackData: 0 });
-
-  return {
-    ...swrResult,
-    advance: () => {
-      const { data: currentNum } = swrResult;
-      if (currentNum == null) {
-        return;
-      }
-
-      setTimeout(() => {
-        swrResult.mutate(currentNum + 1);
-      }, ADVANCE_DELAY_MS);
-    },
-  };
-};