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

Update page info and bookmark info after put back

https://youtrack.weseek.co.jp/issue/GW-7957
- Fix unique key props error of BookmarkFolderMenu by React.Fragment
- Update toastSuccess messgae format in BookmarkFolderTree
- Apply bookmark folders mutation from DescendantsPageList
- Call page info mutation after delete a page
- Apply bookmark folders mutation from trash page
Mudana-Grune 2 лет назад
Родитель
Сommit
2014779e22

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

@@ -135,7 +135,7 @@ export const BookmarkFolderMenu: React.FC<{children?: React.ReactNode}> = ({ chi
               </div>
             </div>
             {bookmarkFolders?.map(folder => (
-              <>
+               <React.Fragment key={`bookmark-folders-${folder._id}`}>
                 <div key={folder._id}>
                   <div
                     className="dropdown-item grw-bookmark-folder-menu-item list-group-item list-group-item-action border-0 py-0"
@@ -169,7 +169,7 @@ export const BookmarkFolderMenu: React.FC<{children?: React.ReactNode}> = ({ chi
                     </div>
                   ))}
                 </>
-              </>
+              </React.Fragment>
             ))}
           </>
         )}

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

@@ -51,8 +51,7 @@ export const BookmarkFolderTree: React.FC<Props> = (props: Props) => {
     const pageDeletedHandler: OnDeletedFunction = (pathOrPathsToDelete, _isRecursively, isCompletely) => {
       if (typeof pathOrPathsToDelete !== 'string') return;
 
-      toastSuccess(isCompletely ? t('deleted_pages_completely', { pathOrPathsToDelete }) : t('deleted_pages', { pathOrPathsToDelete }));
-
+      toastSuccess(isCompletely ? t('deleted_pages_completely', { path: pathOrPathsToDelete }) : t('deleted_pages', { path: pathOrPathsToDelete }));
       bookmarkFolderTreeMutation();
     };
     openDeleteModal([pageToDelete], { onDeleted: pageDeletedHandler });

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

@@ -11,6 +11,7 @@ import {
 import { IPagingResult } from '~/interfaces/paging-result';
 import { OnDeletedFunction, OnPutBackedFunction } from '~/interfaces/ui';
 import {
+  useCurrentUser,
   useIsGuestUser, useIsReadOnlyUser, useIsSharedUser,
 } from '~/stores/context';
 import {
@@ -21,6 +22,7 @@ import {
 import { ForceHideMenuItems } from './Common/Dropdown/PageItemControl';
 import PageList from './PageList/PageList';
 import PaginationWrapper from './PaginationWrapper';
+import { useSWRxBookmarkFolderAndChild } from '~/stores/bookmark-folder';
 
 
 type SubstanceProps = {
@@ -46,7 +48,8 @@ const DescendantsPageListSubstance = (props: SubstanceProps): JSX.Element => {
 
   const { data: isGuestUser } = useIsGuestUser();
   const { data: isReadOnlyUser } = useIsReadOnlyUser();
-
+  const { data: currentUser } = useCurrentUser();
+  const { mutate: mutateBookmarkFolders } = useSWRxBookmarkFolderAndChild(currentUser?._id);
   const pageIds = pagingResult?.items?.map(page => page._id);
   const { injectTo } = useSWRxPageInfoForList(pageIds, null, true, true);
 
@@ -81,11 +84,11 @@ const DescendantsPageListSubstance = (props: SubstanceProps): JSX.Element => {
     toastSuccess(t('page_has_been_reverted', { path }));
 
     mutatePageTree();
-
+    mutateBookmarkFolders()
     if (onPagePutBacked != null) {
       onPagePutBacked(path);
     }
-  }, [onPagePutBacked, t]);
+  }, [onPagePutBacked, t, mutateBookmarkFolders]);
 
   function setPageNumber(selectedPageNumber) {
     setActivePage(selectedPageNumber);

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

@@ -25,7 +25,7 @@ import {
   usePageDuplicateModal, usePageRenameModal, usePageDeleteModal, usePagePresentationModal,
 } from '~/stores/modal';
 import {
-  useSWRMUTxCurrentPage, useSWRxTagsInfo, useCurrentPageId, useIsNotFound, useTemplateTagData,
+  useSWRMUTxCurrentPage, useSWRxTagsInfo, useCurrentPageId, useIsNotFound, useTemplateTagData, useSWRxPageInfo,
 } from '~/stores/page';
 import {
   EditorMode, useDrawerMode, useEditorMode, useIsAbleToShowPageManagement, useIsAbleToShowTagLabel,
@@ -231,6 +231,7 @@ const GrowiContextualSubNavigation = (props: GrowiContextualSubNavigationProps):
   const { open: openRenameModal } = usePageRenameModal();
   const { open: openDeleteModal } = usePageDeleteModal();
   const { data: templateTagData } = useTemplateTagData();
+  const {mutate: mutatePageInfo} = useSWRxPageInfo(pageId)
 
   const updateStateAfterSave = useUpdateStateAfterSave(pageId);
 
@@ -317,9 +318,10 @@ const GrowiContextualSubNavigation = (props: GrowiContextualSubNavigationProps):
       else if (currentPathname != null) {
         router.push(currentPathname);
       }
+      mutatePageInfo()
     };
     openDeleteModal([pageWithMeta], { onDeleted: deletedHandler });
-  }, [currentPathname, openDeleteModal, router]);
+  }, [currentPathname, openDeleteModal, router, mutatePageInfo]);
 
   const switchContentWidthHandler = useCallback(async(pageId: string, value: boolean) => {
     if (!isSharedPage) {

+ 6 - 3
apps/app/src/components/PageAlert/TrashPageAlert.tsx

@@ -12,6 +12,8 @@ import {
   useCurrentPagePath, useSWRxPageInfo, useSWRxCurrentPage, useIsTrashPage,
 } from '~/stores/page';
 import { useIsAbleToShowTrashPageManagementButtons } from '~/stores/ui';
+import { useCurrentUser } from '~/stores/context';
+import { useSWRxBookmarkFolderAndChild } from '~/stores/bookmark-folder';
 
 
 const onDeletedHandler = (pathOrPathsToDelete) => {
@@ -37,8 +39,8 @@ export const TrashPageAlert = (): JSX.Element => {
   const { open: openDeleteModal } = usePageDeleteModal();
   const { open: openPutBackPageModal } = usePutBackPageModal();
   const { data: currentPagePath } = useCurrentPagePath();
-
-
+  const { data: currentUser } = useCurrentUser();
+  const { mutate: mutateBookmarkFolders } = useSWRxBookmarkFolderAndChild(currentUser?._id);
   const deleteUser = pageData?.deleteUser;
   const deletedAt = pageData?.deletedAt ? format(new Date(pageData?.deletedAt), 'yyyy/MM/dd HH:mm') : '';
   const revisionId = pageData?.revision?._id;
@@ -54,6 +56,7 @@ export const TrashPageAlert = (): JSX.Element => {
       }
       try {
         unlink(currentPagePath);
+        mutateBookmarkFolders();
         router.push(`/${pageId}`);
       }
       catch (err) {
@@ -61,7 +64,7 @@ export const TrashPageAlert = (): JSX.Element => {
       }
     };
     openPutBackPageModal({ pageId, path: pagePath }, { onPutBacked: putBackedHandler });
-  }, [currentPagePath, openPutBackPageModal, pageId, pagePath, router]);
+  }, [currentPagePath, openPutBackPageModal, pageId, pagePath, router, mutateBookmarkFolders]);
 
   const openPageDeleteModalHandler = useCallback(() => {
     if (pageId === undefined || revisionId === undefined || pagePath === undefined) {