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

Remove unnecessary mutiton

https://youtrack.weseek.co.jp/issue/GW-7957
- Remove unnecessary outside Bookmarks components
- Check putback modal re-rendered after redirect
- Keep mutatePageInfo after delete page from GrowiContextualSubNavigation
- Resolve conflicts
Mudana-Grune 2 лет назад
Родитель
Сommit
d06e71dcf6

+ 2 - 2
apps/app/src/components/Bookmarks/BookmarkFolderTree.tsx

@@ -11,8 +11,8 @@ import {
 } from '~/stores/bookmark';
 } from '~/stores/bookmark';
 import { useSWRxBookmarkFolderAndChild } from '~/stores/bookmark-folder';
 import { useSWRxBookmarkFolderAndChild } from '~/stores/bookmark-folder';
 import { useIsReadOnlyUser } from '~/stores/context';
 import { useIsReadOnlyUser } from '~/stores/context';
-import { usePageDeleteModal } from '~/stores/modal';
-import { useSWRMUTxPageInfo, useSWRxCurrentPage } from '~/stores/page';
+import { usePageDeleteModal, usePutBackPageModal } from '~/stores/modal';
+import { mutateAllPageInfo, useSWRMUTxPageInfo, useSWRxCurrentPage } from '~/stores/page';
 
 
 import { BookmarkFolderItem } from './BookmarkFolderItem';
 import { BookmarkFolderItem } from './BookmarkFolderItem';
 import { BookmarkItem } from './BookmarkItem';
 import { BookmarkItem } from './BookmarkItem';

+ 3 - 20
apps/app/src/components/DescendantsPageList.tsx

@@ -10,10 +10,7 @@ import {
 } from '~/interfaces/page';
 } from '~/interfaces/page';
 import { IPagingResult } from '~/interfaces/paging-result';
 import { IPagingResult } from '~/interfaces/paging-result';
 import { OnDeletedFunction, OnPutBackedFunction } from '~/interfaces/ui';
 import { OnDeletedFunction, OnPutBackedFunction } from '~/interfaces/ui';
-import {
-  useCurrentUser,
-  useIsGuestUser, useIsReadOnlyUser, useIsSharedUser,
-} from '~/stores/context';
+import { useIsGuestUser, useIsReadOnlyUser, useIsSharedUser } from '~/stores/context';
 import {
 import {
   mutatePageTree,
   mutatePageTree,
   useSWRxPageInfoForList, useSWRxPageList,
   useSWRxPageInfoForList, useSWRxPageList,
@@ -22,10 +19,6 @@ import {
 import { ForceHideMenuItems } from './Common/Dropdown/PageItemControl';
 import { ForceHideMenuItems } from './Common/Dropdown/PageItemControl';
 import PageList from './PageList/PageList';
 import PageList from './PageList/PageList';
 import PaginationWrapper from './PaginationWrapper';
 import PaginationWrapper from './PaginationWrapper';
-import { useSWRxBookmarkFolderAndChild } from '~/stores/bookmark-folder';
-import { useSWRxUserBookmarks } from '~/stores/bookmark';
-import { mutateAllPageInfo } from '~/stores/page';
-
 
 
 type SubstanceProps = {
 type SubstanceProps = {
   pagingResult: IPagingResult<IPageHasId> | undefined,
   pagingResult: IPagingResult<IPageHasId> | undefined,
@@ -50,10 +43,6 @@ const DescendantsPageListSubstance = (props: SubstanceProps): JSX.Element => {
 
 
   const { data: isGuestUser } = useIsGuestUser();
   const { data: isGuestUser } = useIsGuestUser();
   const { data: isReadOnlyUser } = useIsReadOnlyUser();
   const { data: isReadOnlyUser } = useIsReadOnlyUser();
-  const { data: currentUser } = useCurrentUser();
-  const { mutate: mutateBookmarkFolders } = useSWRxBookmarkFolderAndChild(currentUser?._id);
-  const { mutate: mutateUserBookmarks } = useSWRxUserBookmarks(currentUser?._id);
-  const { mutate: mutateUserBookmark } = useSWRxUserBookmarks(currentUser?._id);
 
 
   const pageIds = pagingResult?.items?.map(page => page._id);
   const pageIds = pagingResult?.items?.map(page => page._id);
   const { injectTo } = useSWRxPageInfoForList(pageIds, null, true, true);
   const { injectTo } = useSWRxPageInfoForList(pageIds, null, true, true);
@@ -79,25 +68,19 @@ const DescendantsPageListSubstance = (props: SubstanceProps): JSX.Element => {
     }
     }
 
 
     mutatePageTree();
     mutatePageTree();
-    mutateBookmarkFolders();
-    mutateUserBookmark();
-    mutateAllPageInfo();
     if (onPagesDeleted != null) {
     if (onPagesDeleted != null) {
       onPagesDeleted(...args);
       onPagesDeleted(...args);
     }
     }
-  }, [onPagesDeleted, t, mutateBookmarkFolders, mutateUserBookmark, mutateAllPageInfo]);
+  }, [onPagesDeleted, t]);
 
 
   const pagePutBackedHandler: OnPutBackedFunction = useCallback((path) => {
   const pagePutBackedHandler: OnPutBackedFunction = useCallback((path) => {
     toastSuccess(t('page_has_been_reverted', { path }));
     toastSuccess(t('page_has_been_reverted', { path }));
 
 
     mutatePageTree();
     mutatePageTree();
-    mutateBookmarkFolders();
-    mutateUserBookmarks();
-    mutateAllPageInfo();
     if (onPagePutBacked != null) {
     if (onPagePutBacked != null) {
       onPagePutBacked(path);
       onPagePutBacked(path);
     }
     }
-  }, [onPagePutBacked, t, mutateBookmarkFolders, mutateUserBookmarks, mutateAllPageInfo]);
+  }, [onPagePutBacked, t]);
 
 
   function setPageNumber(selectedPageNumber) {
   function setPageNumber(selectedPageNumber) {
     setActivePage(selectedPageNumber);
     setActivePage(selectedPageNumber);

+ 2 - 5
apps/app/src/components/Navbar/GrowiContextualSubNavigation.tsx

@@ -46,8 +46,6 @@ import type { SubNavButtonsProps } from './SubNavButtons';
 
 
 import AuthorInfoStyles from './AuthorInfo.module.scss';
 import AuthorInfoStyles from './AuthorInfo.module.scss';
 import PageEditorModeManagerStyles from './PageEditorModeManager.module.scss';
 import PageEditorModeManagerStyles from './PageEditorModeManager.module.scss';
-import { useSWRxBookmarkFolderAndChild } from '~/stores/bookmark-folder';
-import { useSWRxUserBookmarks } from '~/stores/bookmark';
 
 
 const { isUsersHomePage } = pagePathUtils;
 const { isUsersHomePage } = pagePathUtils;
 
 
@@ -225,8 +223,6 @@ const GrowiContextualSubNavigation = (props: GrowiContextualSubNavigationProps):
   const { data: isAbleToShowPageAuthors } = useIsAbleToShowPageAuthors();
   const { data: isAbleToShowPageAuthors } = useIsAbleToShowPageAuthors();
 
 
   const { mutate: mutateSWRTagsInfo, data: tagsInfoData } = useSWRxTagsInfo(currentPage?._id);
   const { mutate: mutateSWRTagsInfo, data: tagsInfoData } = useSWRxTagsInfo(currentPage?._id);
-  const { mutate: mutateBookmarkFolders } = useSWRxBookmarkFolderAndChild(currentUser?._id);
-  const { mutate: mutateUserBookmarks } = useSWRxUserBookmarks(currentUser?._id);
 
 
   // eslint-disable-next-line max-len
   // eslint-disable-next-line max-len
   const { data: tagsForEditors, mutate: mutatePageTagsForEditors, sync: syncPageTagsForEditors } = usePageTagsForEditors(!isSharedPage ? currentPage?._id : undefined);
   const { data: tagsForEditors, mutate: mutatePageTagsForEditors, sync: syncPageTagsForEditors } = usePageTagsForEditors(!isSharedPage ? currentPage?._id : undefined);
@@ -324,9 +320,10 @@ const GrowiContextualSubNavigation = (props: GrowiContextualSubNavigationProps):
       }
       }
 
 
       mutateCurrentPage();
       mutateCurrentPage();
+      mutatePageInfo();
     };
     };
     openDeleteModal([pageWithMeta], { onDeleted: deletedHandler });
     openDeleteModal([pageWithMeta], { onDeleted: deletedHandler });
-  }, [currentPathname, mutateCurrentPage, openDeleteModal, router]);
+  }, [currentPathname, mutateCurrentPage, openDeleteModal, router, mutatePageInfo]);
 
 
   const switchContentWidthHandler = useCallback(async (pageId: string, value: boolean) => {
   const switchContentWidthHandler = useCallback(async (pageId: string, value: boolean) => {
     if (!isSharedPage) {
     if (!isSharedPage) {

+ 0 - 5
apps/app/src/components/PageAlert/TrashPageAlert.tsx

@@ -12,9 +12,6 @@ import {
   useCurrentPagePath, useSWRxPageInfo, useSWRxCurrentPage, useIsTrashPage, useSWRMUTxCurrentPage,
   useCurrentPagePath, useSWRxPageInfo, useSWRxCurrentPage, useIsTrashPage, useSWRMUTxCurrentPage,
 } from '~/stores/page';
 } from '~/stores/page';
 import { useIsAbleToShowTrashPageManagementButtons } from '~/stores/ui';
 import { useIsAbleToShowTrashPageManagementButtons } from '~/stores/ui';
-import { useCurrentUser } from '~/stores/context';
-import { useSWRxBookmarkFolderAndChild } from '~/stores/bookmark-folder';
-import { useSWRxUserBookmarks } from '~/stores/bookmark';
 
 
 
 
 const onDeletedHandler = (pathOrPathsToDelete) => {
 const onDeletedHandler = (pathOrPathsToDelete) => {
@@ -57,8 +54,6 @@ export const TrashPageAlert = (): JSX.Element => {
       }
       }
       try {
       try {
         unlink(currentPagePath);
         unlink(currentPagePath);
-        mutateBookmarkFolders();
-        mutateUserBookmarks();
         router.push(`/${pageId}`);
         router.push(`/${pageId}`);
         mutateCurrentPage();
         mutateCurrentPage();
       }
       }

+ 1 - 10
apps/app/src/components/PageList/PageListItemL.tsx

@@ -33,9 +33,6 @@ import { useIsDeviceSmallerThanLg } from '~/stores/ui';
 import { useSWRMUTxPageInfo, useSWRxPageInfo } from '../../stores/page';
 import { useSWRMUTxPageInfo, useSWRxPageInfo } from '../../stores/page';
 import { ForceHideMenuItems, PageItemControl } from '../Common/Dropdown/PageItemControl';
 import { ForceHideMenuItems, PageItemControl } from '../Common/Dropdown/PageItemControl';
 import PagePathHierarchicalLink from '../PagePathHierarchicalLink';
 import PagePathHierarchicalLink from '../PagePathHierarchicalLink';
-import { useCurrentUser } from '~/stores/context';
-import { useSWRxBookmarkFolderAndChild } from '~/stores/bookmark-folder';
-import { mutateSearching } from '~/stores/search';
 
 
 type Props = {
 type Props = {
   page: IPageWithSearchMeta | IPageWithMeta<IPageInfoForListing & IPageSearchMeta>,
   page: IPageWithSearchMeta | IPageWithMeta<IPageInfoForListing & IPageSearchMeta>,
@@ -91,7 +88,6 @@ const PageListItemLSubstance: ForwardRefRenderFunction<ISelectable, Props> = (pr
   const { open: openDeleteModal } = usePageDeleteModal();
   const { open: openDeleteModal } = usePageDeleteModal();
   const { open: openPutBackPageModal } = usePutBackPageModal();
   const { open: openPutBackPageModal } = usePutBackPageModal();
 
 
-  const { data: currentUser } = useCurrentUser();
   const shouldFetch = isSelected && (pageData != null || pageMeta != null);
   const shouldFetch = isSelected && (pageData != null || pageMeta != null);
   const { data: pageInfo } = useSWRxPageInfo(shouldFetch ? pageData?._id : null);
   const { data: pageInfo } = useSWRxPageInfo(shouldFetch ? pageData?._id : null);
   const { trigger: mutatePageInfo } = useSWRMUTxPageInfo(pageData?._id ?? null);
   const { trigger: mutatePageInfo } = useSWRMUTxPageInfo(pageData?._id ?? null);
@@ -164,11 +160,6 @@ const PageListItemLSubstance: ForwardRefRenderFunction<ISelectable, Props> = (pr
       try {
       try {
         // pageData path should be `/trash/fuga` (`/trash` should be included to the prefix)
         // pageData path should be `/trash/fuga` (`/trash` should be included to the prefix)
         await unlink(pageData.path);
         await unlink(pageData.path);
-        mutateSearching();
-        mutatePageInfo();
-        mutateUserBookmark();
-        mutateBookmarkInfo();
-        mutateBookmarkFolders();
       }
       }
       catch (err) {
       catch (err) {
         toastError(err);
         toastError(err);
@@ -180,7 +171,7 @@ const PageListItemLSubstance: ForwardRefRenderFunction<ISelectable, Props> = (pr
       }
       }
     };
     };
     openPutBackPageModal({ pageId, path }, { onPutBacked: putBackedHandler });
     openPutBackPageModal({ pageId, path }, { onPutBacked: putBackedHandler });
-  }, [onPagePutBacked, openPutBackPageModal, pageData, mutateSearching, mutatePageInfo, mutateUserBookmark, mutateBookmarkInfo, mutateBookmarkFolders]);
+  }, [onPagePutBacked, openPutBackPageModal, pageData]);
 
 
   const styleListGroupItem = (!isDeviceSmallerThanLg && onClickItem != null) ? 'list-group-item-action' : '';
   const styleListGroupItem = (!isDeviceSmallerThanLg && onClickItem != null) ? 'list-group-item-action' : '';
   // background color of list item changes when class "active" exists under 'list-group-item'
   // background color of list item changes when class "active" exists under 'list-group-item'

+ 1 - 14
apps/app/src/components/SearchPage/SearchResultList.tsx

@@ -11,16 +11,12 @@ 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 { useCurrentUser, useIsGuestUser, useIsReadOnlyUser } from '~/stores/context';
+import { useIsGuestUser, useIsReadOnlyUser } from '~/stores/context';
 import { mutatePageTree, useSWRxPageInfoForList } from '~/stores/page-listing';
 import { mutatePageTree, useSWRxPageInfoForList } from '~/stores/page-listing';
 import { mutateSearching } 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';
-import { useSWRxPageInfo } from '~/stores/page';
-import { useSWRBookmarkInfo, useSWRxUserBookmarks } from '~/stores/bookmark';
-import { useSWRxBookmarkFolderAndChild } from '~/stores/bookmark-folder';
-
 
 
 type Props = {
 type Props = {
   pages: IPageWithSearchMeta[],
   pages: IPageWithSearchMeta[],
@@ -43,15 +39,10 @@ const SearchResultListSubstance: ForwardRefRenderFunction<ISelectableAll, Props>
     .filter(page => (page.meta?.elasticSearchResult?.snippet?.length ?? 0) === 0)
     .filter(page => (page.meta?.elasticSearchResult?.snippet?.length ?? 0) === 0)
     .map(page => page.data._id);
     .map(page => page.data._id);
 
 
-  const { data: currentUser } = useCurrentUser();
   const { data: isGuestUser } = useIsGuestUser();
   const { data: isGuestUser } = useIsGuestUser();
   const { data: isReadOnlyUser } = useIsReadOnlyUser();
   const { data: isReadOnlyUser } = useIsReadOnlyUser();
   const { data: idToPageInfo } = useSWRxPageInfoForList(pageIdsWithNoSnippet, null, true, true);
   const { data: idToPageInfo } = useSWRxPageInfoForList(pageIdsWithNoSnippet, null, true, true);
 
 
-  const { mutate: mutatePageInfo } = useSWRxPageInfo(selectedPageId);
-  const { mutate: mutateUserBookmark } = useSWRxUserBookmarks(currentUser?._id);
-  const { mutate: mutateBookmarkInfo } = useSWRBookmarkInfo(selectedPageId);
-  const { mutate: mutateBookmarkFolders } = useSWRxBookmarkFolderAndChild(currentUser?._id);
   const itemsRef = useRef<(ISelectable|null)[]>([]);
   const itemsRef = useRef<(ISelectable|null)[]>([]);
 
 
   // publish selectAll()
   // publish selectAll()
@@ -128,10 +119,6 @@ const SearchResultListSubstance: ForwardRefRenderFunction<ISelectableAll, Props>
     }
     }
     mutatePageTree();
     mutatePageTree();
     mutateSearching();
     mutateSearching();
-    mutatePageInfo();
-    mutateUserBookmark();
-    mutateBookmarkInfo();
-    mutateBookmarkFolders();
   }, [t]);
   }, [t]);
 
 
   return (
   return (