Przeglądaj źródła

Reload bookmark list from pageTree

https://youtrack.weseek.co.jp/issue/GW-7839
- Remove useEffect from Bookmarks component
- Implement mutateCurrentUserBookmarks from page tree item
- Move bookmarkMenuItemClickHandler method in Page Tree Item
Mudana-Grune 3 lat temu
rodzic
commit
8f01f2e779

+ 2 - 6
packages/app/src/components/Sidebar/Bookmarks.tsx

@@ -1,5 +1,5 @@
 
 
-import React, { useEffect } from 'react';
+import React from 'react';
 
 
 import { DevidedPagePath, pathUtils } from '@growi/core';
 import { DevidedPagePath, pathUtils } from '@growi/core';
 import { useTranslation } from 'react-i18next';
 import { useTranslation } from 'react-i18next';
@@ -78,11 +78,7 @@ const BookmarksItem = (props: Props) => {
 const Bookmarks = () : JSX.Element => {
 const Bookmarks = () : JSX.Element => {
   const { t } = useTranslation();
   const { t } = useTranslation();
   const { data: isGuestUser } = useIsGuestUser();
   const { data: isGuestUser } = useIsGuestUser();
-  const { data: pages, mutate: mutateCurrentUserBookmark } = useSWRxCurrentUserBookmarks();
-
-  useEffect(() => {
-    mutateCurrentUserBookmark();
-  }, [mutateCurrentUserBookmark]);
+  const { data: pages } = useSWRxCurrentUserBookmarks();
 
 
   const renderBookmarksItem = () => {
   const renderBookmarksItem = () => {
     if (pages?.length === 0) {
     if (pages?.length === 0) {

+ 8 - 6
packages/app/src/components/Sidebar/PageTree/Item.tsx

@@ -16,6 +16,7 @@ import TriangleIcon from '~/components/Icons/TriangleIcon';
 import {
 import {
   IPageHasId, IPageInfoAll, IPageToDeleteWithMeta,
   IPageHasId, IPageInfoAll, IPageToDeleteWithMeta,
 } from '~/interfaces/page';
 } from '~/interfaces/page';
+import { useSWRxCurrentUserBookmarks } from '~/stores/bookmark';
 import { IPageForPageDuplicateModal } from '~/stores/modal';
 import { IPageForPageDuplicateModal } from '~/stores/modal';
 import { useSWRxPageChildren } from '~/stores/page-listing';
 import { useSWRxPageChildren } from '~/stores/page-listing';
 import { usePageTreeDescCountMap } from '~/stores/ui';
 import { usePageTreeDescCountMap } from '~/stores/ui';
@@ -57,12 +58,6 @@ const markTarget = (children: ItemNode[], targetPathOrId?: string): void => {
   });
   });
 };
 };
 
 
-
-const bookmarkMenuItemClickHandler = async(_pageId: string, _newValue: boolean): Promise<void> => {
-  const bookmarkOperation = _newValue ? bookmark : unbookmark;
-  await bookmarkOperation(_pageId);
-};
-
 /**
 /**
  * Return new page path after the droppedPagePath is moved under the newParentPagePath
  * Return new page path after the droppedPagePath is moved under the newParentPagePath
  * @param droppedPagePath
  * @param droppedPagePath
@@ -111,6 +106,7 @@ const Item: FC<ItemProps> = (props: ItemProps) => {
   const [isCreating, setCreating] = useState(false);
   const [isCreating, setCreating] = useState(false);
 
 
   const { data, mutate: mutateChildren } = useSWRxPageChildren(isOpen ? page._id : null);
   const { data, mutate: mutateChildren } = useSWRxPageChildren(isOpen ? page._id : null);
+  const { mutate: mutateCurrentUserBookmarks } = useSWRxCurrentUserBookmarks();
 
 
   // descendantCount
   // descendantCount
   const { getDescCount } = usePageTreeDescCountMap();
   const { getDescCount } = usePageTreeDescCountMap();
@@ -238,6 +234,12 @@ const Item: FC<ItemProps> = (props: ItemProps) => {
     }
     }
   }, [hasDescendants]);
   }, [hasDescendants]);
 
 
+  const bookmarkMenuItemClickHandler = async(_pageId: string, _newValue: boolean): Promise<void> => {
+    const bookmarkOperation = _newValue ? bookmark : unbookmark;
+    await bookmarkOperation(_pageId);
+    mutateCurrentUserBookmarks();
+  };
+
   const duplicateMenuItemClickHandler = useCallback((): void => {
   const duplicateMenuItemClickHandler = useCallback((): void => {
     if (onClickDuplicateMenuItem == null) {
     if (onClickDuplicateMenuItem == null) {
       return;
       return;