Przeglądaj źródła

Fix put back from search result page and descendant page list

https://youtrack.weseek.co.jp/issue/GW-7957
- Mutate bookmark info , page info and user's bookmark after delete a page from search result
- Implement mutateSearching after put back a page from search result
- Update user's bookmark , bookmark info and page info after delete a page from DescendantsPageList
- Update user's bookmark , bookmark info and page info after put back a page from DescendantsPageList and trash page
Mudana-Grune 2 lat temu
rodzic
commit
27f495c9c4

+ 10 - 4
apps/app/src/components/DescendantsPageList.tsx

@@ -24,6 +24,7 @@ import PageList from './PageList/PageList';
 import PaginationWrapper from './PaginationWrapper';
 import { useSWRxBookmarkFolderAndChild } from '~/stores/bookmark-folder';
 import { useSWRxUserBookmarks } from '~/stores/bookmark';
+import { mutateAllPageInfo } from '~/stores/page';
 
 
 type SubstanceProps = {
@@ -51,7 +52,9 @@ const DescendantsPageListSubstance = (props: SubstanceProps): JSX.Element => {
   const { data: isReadOnlyUser } = useIsReadOnlyUser();
   const { data: currentUser } = useCurrentUser();
   const { mutate: mutateBookmarkFolders } = useSWRxBookmarkFolderAndChild(currentUser?._id);
-  const {  mutate: mutateUserBookmarks } = useSWRxUserBookmarks(currentUser?._id);
+  const { mutate: mutateUserBookmarks } = useSWRxUserBookmarks(currentUser?._id);
+  const { mutate: mutateUserBookmark } = useSWRxUserBookmarks(currentUser?._id);
+
   const pageIds = pagingResult?.items?.map(page => page._id);
   const { injectTo } = useSWRxPageInfoForList(pageIds, null, true, true);
 
@@ -76,11 +79,13 @@ const DescendantsPageListSubstance = (props: SubstanceProps): JSX.Element => {
     }
 
     mutatePageTree();
-
+    mutateBookmarkFolders();
+    mutateUserBookmark();
+    mutateAllPageInfo();
     if (onPagesDeleted != null) {
       onPagesDeleted(...args);
     }
-  }, [onPagesDeleted, t]);
+  }, [onPagesDeleted, t, mutateBookmarkFolders, mutateUserBookmark, mutateAllPageInfo]);
 
   const pagePutBackedHandler: OnPutBackedFunction = useCallback((path) => {
     toastSuccess(t('page_has_been_reverted', { path }));
@@ -88,10 +93,11 @@ const DescendantsPageListSubstance = (props: SubstanceProps): JSX.Element => {
     mutatePageTree();
     mutateBookmarkFolders();
     mutateUserBookmarks();
+    mutateAllPageInfo();
     if (onPagePutBacked != null) {
       onPagePutBacked(path);
     }
-  }, [onPagePutBacked, t, mutateBookmarkFolders]);
+  }, [onPagePutBacked, t, mutateBookmarkFolders, mutateUserBookmarks, mutateAllPageInfo]);
 
   function setPageNumber(selectedPageNumber) {
     setActivePage(selectedPageNumber);

+ 13 - 2
apps/app/src/components/PageList/PageListItemL.tsx

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

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

@@ -11,12 +11,15 @@ import {
   IPageInfoForListing, IPageWithMeta, isIPageInfoForListing,
 } from '~/interfaces/page';
 import { IPageSearchMeta, IPageWithSearchMeta } from '~/interfaces/search';
-import { useIsGuestUser, useIsReadOnlyUser } from '~/stores/context';
+import { useCurrentUser, useIsGuestUser, useIsReadOnlyUser } from '~/stores/context';
 import { mutatePageTree, useSWRxPageInfoForList } from '~/stores/page-listing';
 import { mutateSearching } from '~/stores/search';
 
 import { ForceHideMenuItems } from '../Common/Dropdown/PageItemControl';
 import { PageListItemL } from '../PageList/PageListItemL';
+import { useSWRxPageInfo } from '~/stores/page';
+import { useSWRBookmarkInfo, useSWRxUserBookmarks } from '~/stores/bookmark';
+import { useSWRxBookmarkFolderAndChild } from '~/stores/bookmark-folder';
 
 
 type Props = {
@@ -40,10 +43,15 @@ const SearchResultListSubstance: ForwardRefRenderFunction<ISelectableAll, Props>
     .filter(page => (page.meta?.elasticSearchResult?.snippet?.length ?? 0) === 0)
     .map(page => page.data._id);
 
+  const { data: currentUser } = useCurrentUser();
   const { data: isGuestUser } = useIsGuestUser();
   const { data: isReadOnlyUser } = useIsReadOnlyUser();
   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)[]>([]);
 
   // publish selectAll()
@@ -120,6 +128,10 @@ const SearchResultListSubstance: ForwardRefRenderFunction<ISelectableAll, Props>
     }
     mutatePageTree();
     mutateSearching();
+    mutatePageInfo();
+    mutateUserBookmark();
+    mutateBookmarkInfo();
+    mutateBookmarkFolders();
   }, [t]);
 
   return (