kaori 4 лет назад
Родитель
Сommit
f959208786

+ 2 - 2
packages/app/src/components/Common/Dropdown/PageItemControl.tsx

@@ -25,7 +25,7 @@ const PageItemControl: FC<PageItemControlProps> = (props: PageItemControlProps)
   } = props;
   const { t } = useTranslation('');
   const [isOpen, setIsOpen] = useState(false);
-  const { data: bookmarkInfo, error: bookmarkInfoError, mutate: mutateBookmarkInfo } = useSWRBookmarkInfo(page._id);
+  const { data: bookmarkInfo, error: bookmarkInfoError, mutate: mutateBookmarkInfo } = useSWRBookmarkInfo(page._id, isOpen);
 
   const deleteButtonHandler = () => {
     if (onClickDeleteButton != null && page._id != null) {
@@ -46,7 +46,7 @@ const PageItemControl: FC<PageItemControlProps> = (props: PageItemControlProps)
   });
 
   if (bookmarkInfoError != null || bookmarkInfo == null) {
-    return <></>;
+    return <>hoge</>;
   }
 
   const dropdownToggle = () => {

+ 12 - 9
packages/app/src/stores/bookmark.ts

@@ -3,13 +3,16 @@ import { apiv3Get } from '../client/util/apiv3-client';
 import { IBookmarkInfo } from '../interfaces/bookmark-info';
 
 
-export const useSWRBookmarkInfo = (pageId: string | null | undefined): SWRResponse<IBookmarkInfo, Error> => {
-  return useSWR(pageId != null
-    ? `/bookmarks/info?pageId=${pageId}` : null,
-  endpoint => apiv3Get(endpoint).then((response) => {
-    return {
-      sumOfBookmarks: response.data.sumOfBookmarks,
-      isBookmarked: response.data.isBookmarked,
-    };
-  }));
+export const useSWRBookmarkInfo = (pageId: string | null | undefined, isOpen = true): SWRResponse<IBookmarkInfo, Error> => {
+  return useSWR(
+    pageId != null && isOpen
+      ? `/bookmarks/info?pageId=${pageId}` : null,
+    endpoint => apiv3Get(endpoint).then((response) => {
+      console.log('isOpen_swr', isOpen);
+      return {
+        sumOfBookmarks: response.data.sumOfBookmarks,
+        isBookmarked: response.data.isBookmarked,
+      };
+    }),
+  );
 };