|
@@ -6,7 +6,7 @@ import { DevidedPagePath, pathUtils } from '@growi/core';
|
|
|
import { useTranslation } from 'react-i18next';
|
|
import { useTranslation } from 'react-i18next';
|
|
|
import { UncontrolledTooltip, DropdownToggle } from 'reactstrap';
|
|
import { UncontrolledTooltip, DropdownToggle } from 'reactstrap';
|
|
|
|
|
|
|
|
-import { unbookmark } from '~/client/services/page-operation';
|
|
|
|
|
|
|
+import { bookmark, unbookmark } from '~/client/services/page-operation';
|
|
|
import { addBookmarkToFolder, renamePage } from '~/client/util/bookmark-utils';
|
|
import { addBookmarkToFolder, renamePage } from '~/client/util/bookmark-utils';
|
|
|
import { ValidationTarget } from '~/client/util/input-validator';
|
|
import { ValidationTarget } from '~/client/util/input-validator';
|
|
|
import { toastError } from '~/client/util/toastr';
|
|
import { toastError } from '~/client/util/toastr';
|
|
@@ -45,8 +45,7 @@ export const BookmarkItem = (props: Props): JSX.Element => {
|
|
|
|
|
|
|
|
const [isRenameInputShown, setRenameInputShown] = useState(false);
|
|
const [isRenameInputShown, setRenameInputShown] = useState(false);
|
|
|
|
|
|
|
|
- const { data: fetchedPageInfo } = useSWRxPageInfo(bookmarkedPage._id);
|
|
|
|
|
-
|
|
|
|
|
|
|
+ const { data: pageInfo, mutate: mutatePageInfo } = useSWRxPageInfo(bookmarkedPage._id);
|
|
|
const dPagePath = new DevidedPagePath(bookmarkedPage.path, false, true);
|
|
const dPagePath = new DevidedPagePath(bookmarkedPage.path, false, true);
|
|
|
const { latter: pageTitle, former: formerPagePath } = dPagePath;
|
|
const { latter: pageTitle, former: formerPagePath } = dPagePath;
|
|
|
const bookmarkItemId = `bookmark-item-${bookmarkedPage._id}`;
|
|
const bookmarkItemId = `bookmark-item-${bookmarkedPage._id}`;
|
|
@@ -65,10 +64,16 @@ export const BookmarkItem = (props: Props): JSX.Element => {
|
|
|
}
|
|
}
|
|
|
}, [bookmarkFolderTreeMutation, bookmarkedPage._id]);
|
|
}, [bookmarkFolderTreeMutation, bookmarkedPage._id]);
|
|
|
|
|
|
|
|
- const bookmarkMenuItemClickHandler = useCallback(async() => {
|
|
|
|
|
- await unbookmark(bookmarkedPage._id);
|
|
|
|
|
|
|
+ const bookmarkMenuItemClickHandler = useCallback(async(pageId: string, shouldBookmark: boolean) => {
|
|
|
|
|
+ if (shouldBookmark) {
|
|
|
|
|
+ await bookmark(pageId);
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ await unbookmark(pageId);
|
|
|
|
|
+ }
|
|
|
bookmarkFolderTreeMutation();
|
|
bookmarkFolderTreeMutation();
|
|
|
- }, [bookmarkedPage._id, bookmarkFolderTreeMutation]);
|
|
|
|
|
|
|
+ mutatePageInfo();
|
|
|
|
|
+ }, [bookmarkFolderTreeMutation, mutatePageInfo]);
|
|
|
|
|
|
|
|
const renameMenuItemClickHandler = useCallback(() => {
|
|
const renameMenuItemClickHandler = useCallback(() => {
|
|
|
setRenameInputShown(true);
|
|
setRenameInputShown(true);
|
|
@@ -86,12 +91,13 @@ export const BookmarkItem = (props: Props): JSX.Element => {
|
|
|
setRenameInputShown(false);
|
|
setRenameInputShown(false);
|
|
|
await renamePage(bookmarkedPage._id, bookmarkedPage.revision, newPagePath);
|
|
await renamePage(bookmarkedPage._id, bookmarkedPage.revision, newPagePath);
|
|
|
bookmarkFolderTreeMutation();
|
|
bookmarkFolderTreeMutation();
|
|
|
|
|
+ mutatePageInfo();
|
|
|
}
|
|
}
|
|
|
catch (err) {
|
|
catch (err) {
|
|
|
setRenameInputShown(true);
|
|
setRenameInputShown(true);
|
|
|
toastError(err);
|
|
toastError(err);
|
|
|
}
|
|
}
|
|
|
- }, [bookmarkedPage, bookmarkFolderTreeMutation]);
|
|
|
|
|
|
|
+ }, [bookmarkedPage.path, bookmarkedPage._id, bookmarkedPage.revision, bookmarkFolderTreeMutation, mutatePageInfo]);
|
|
|
|
|
|
|
|
const deleteMenuItemClickHandler = useCallback(async(_pageId: string, pageInfo: IPageInfoAll | undefined): Promise<void> => {
|
|
const deleteMenuItemClickHandler = useCallback(async(_pageId: string, pageInfo: IPageInfoAll | undefined): Promise<void> => {
|
|
|
if (bookmarkedPage._id == null || bookmarkedPage.path == null) {
|
|
if (bookmarkedPage._id == null || bookmarkedPage.path == null) {
|
|
@@ -137,7 +143,7 @@ export const BookmarkItem = (props: Props): JSX.Element => {
|
|
|
pageId={bookmarkedPage._id}
|
|
pageId={bookmarkedPage._id}
|
|
|
isEnableActions
|
|
isEnableActions
|
|
|
isReadOnlyUser={isReadOnlyUser}
|
|
isReadOnlyUser={isReadOnlyUser}
|
|
|
- pageInfo={fetchedPageInfo}
|
|
|
|
|
|
|
+ pageInfo={pageInfo}
|
|
|
forceHideMenuItems={[MenuItemType.DUPLICATE]}
|
|
forceHideMenuItems={[MenuItemType.DUPLICATE]}
|
|
|
onClickBookmarkMenuItem={bookmarkMenuItemClickHandler}
|
|
onClickBookmarkMenuItem={bookmarkMenuItemClickHandler}
|
|
|
onClickRenameMenuItem={renameMenuItemClickHandler}
|
|
onClickRenameMenuItem={renameMenuItemClickHandler}
|