|
@@ -1,4 +1,4 @@
|
|
|
-import React, { useCallback, useState } from 'react';
|
|
|
|
|
|
|
+import React, { useCallback, useEffect, useState } from 'react';
|
|
|
|
|
|
|
|
import nodePath from 'path';
|
|
import nodePath from 'path';
|
|
|
|
|
|
|
@@ -10,8 +10,9 @@ import { UncontrolledTooltip, DropdownToggle } from 'reactstrap';
|
|
|
import { unbookmark } from '~/client/services/page-operation';
|
|
import { unbookmark } from '~/client/services/page-operation';
|
|
|
import { toastError, toastSuccess } from '~/client/util/apiNotification';
|
|
import { toastError, toastSuccess } from '~/client/util/apiNotification';
|
|
|
import { apiv3Put } from '~/client/util/apiv3-client';
|
|
import { apiv3Put } from '~/client/util/apiv3-client';
|
|
|
|
|
+import { BookmarkFolderItems } from '~/interfaces/bookmark-info';
|
|
|
import { IPageHasId, IPageInfoAll, IPageToDeleteWithMeta } from '~/interfaces/page';
|
|
import { IPageHasId, IPageInfoAll, IPageToDeleteWithMeta } from '~/interfaces/page';
|
|
|
-
|
|
|
|
|
|
|
+import { useSWRxBookamrkFolderAndChild } from '~/stores/bookmark-folder';
|
|
|
|
|
|
|
|
import ClosableTextInput, { AlertInfo, AlertType } from '../Common/ClosableTextInput';
|
|
import ClosableTextInput, { AlertInfo, AlertType } from '../Common/ClosableTextInput';
|
|
|
import { MenuItemType, PageItemControl } from '../Common/Dropdown/PageItemControl';
|
|
import { MenuItemType, PageItemControl } from '../Common/Dropdown/PageItemControl';
|
|
@@ -21,18 +22,29 @@ type Props = {
|
|
|
bookmarkedPage: IPageHasId,
|
|
bookmarkedPage: IPageHasId,
|
|
|
onUnbookmarked: () => void,
|
|
onUnbookmarked: () => void,
|
|
|
onRenamed: () => void,
|
|
onRenamed: () => void,
|
|
|
- onClickDeleteMenuItem: (pageToDelete: IPageToDeleteWithMeta) => void
|
|
|
|
|
|
|
+ onClickDeleteMenuItem: (pageToDelete: IPageToDeleteWithMeta) => void,
|
|
|
|
|
+ parentFolder: BookmarkFolderItems
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const BookmarkItem = (props: Props): JSX.Element => {
|
|
const BookmarkItem = (props: Props): JSX.Element => {
|
|
|
const { t } = useTranslation();
|
|
const { t } = useTranslation();
|
|
|
const {
|
|
const {
|
|
|
- bookmarkedPage, onUnbookmarked, onRenamed, onClickDeleteMenuItem,
|
|
|
|
|
|
|
+ bookmarkedPage, onUnbookmarked, onRenamed, onClickDeleteMenuItem, parentFolder,
|
|
|
} = props;
|
|
} = props;
|
|
|
const [isRenameInputShown, setRenameInputShown] = useState(false);
|
|
const [isRenameInputShown, setRenameInputShown] = useState(false);
|
|
|
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}`;
|
|
|
|
|
+ const [parentId, setParentId] = useState(parentFolder._id);
|
|
|
|
|
+ const { mutate: mutateParentBookmarkData } = useSWRxBookamrkFolderAndChild();
|
|
|
|
|
+ const { mutate: mutateChildFolderData } = useSWRxBookamrkFolderAndChild(parentId);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ if (parentId != null) {
|
|
|
|
|
+ mutateChildFolderData();
|
|
|
|
|
+ }
|
|
|
|
|
+ }, [parentId, mutateChildFolderData]);
|
|
|
|
|
|
|
|
const bookmarkMenuItemClickHandler = useCallback(async() => {
|
|
const bookmarkMenuItemClickHandler = useCallback(async() => {
|
|
|
await unbookmark(bookmarkedPage._id);
|
|
await unbookmark(bookmarkedPage._id);
|
|
@@ -98,6 +110,15 @@ const BookmarkItem = (props: Props): JSX.Element => {
|
|
|
const [, bookmarkItemDragRef] = useDrag({
|
|
const [, bookmarkItemDragRef] = useDrag({
|
|
|
type: 'BOOKMARK',
|
|
type: 'BOOKMARK',
|
|
|
item: bookmarkedPage,
|
|
item: bookmarkedPage,
|
|
|
|
|
+ end: (item) => {
|
|
|
|
|
+ if (parentFolder.parent == null) {
|
|
|
|
|
+ mutateParentBookmarkData();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (parentId != null) {
|
|
|
|
|
+ setParentId(parentFolder.parent);
|
|
|
|
|
+ mutateChildFolderData();
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
collect: monitor => ({
|
|
collect: monitor => ({
|
|
|
isDragging: monitor.isDragging(),
|
|
isDragging: monitor.isDragging(),
|
|
|
canDrag: monitor.canDrag(),
|
|
canDrag: monitor.canDrag(),
|
|
@@ -106,44 +127,46 @@ const BookmarkItem = (props: Props): JSX.Element => {
|
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
- <div className="grw-foldertree-item-container" key={bookmarkedPage._id} ref={(c) => { bookmarkItemDragRef(c) }}>
|
|
|
|
|
- <li className="bookmark-item-list list-group-item list-group-item-action border-0 py-0 pl-5 d-flex align-items-center" id={bookmarkItemId}>
|
|
|
|
|
- { isRenameInputShown ? (
|
|
|
|
|
- <ClosableTextInput
|
|
|
|
|
- value={nodePath.basename(bookmarkedPage.path ?? '')}
|
|
|
|
|
- placeholder={t('Input page name')}
|
|
|
|
|
- onClickOutside={() => { setRenameInputShown(false) }}
|
|
|
|
|
- onPressEnter={pressEnterForRenameHandler}
|
|
|
|
|
- inputValidator={inputValidator}
|
|
|
|
|
- />
|
|
|
|
|
- ) : (
|
|
|
|
|
- <a href={`/${bookmarkedPage._id}`} className="grw-foldertree-title-anchor flex-grow-1 pr-3">
|
|
|
|
|
- <p className={`text-truncate m-auto ${bookmarkedPage.isEmpty && 'grw-sidebar-text-muted'}`}>{pageTitle}</p>
|
|
|
|
|
- </a>
|
|
|
|
|
- )}
|
|
|
|
|
- <PageItemControl
|
|
|
|
|
- pageId={bookmarkedPage._id}
|
|
|
|
|
- isEnableActions
|
|
|
|
|
- forceHideMenuItems={[MenuItemType.DUPLICATE]}
|
|
|
|
|
- onClickBookmarkMenuItem={bookmarkMenuItemClickHandler}
|
|
|
|
|
- onClickRenameMenuItem={renameMenuItemClickHandler}
|
|
|
|
|
- onClickDeleteMenuItem={deleteMenuItemClickHandler}
|
|
|
|
|
- >
|
|
|
|
|
- <DropdownToggle color="transparent" className="border-0 rounded btn-page-item-control p-0 grw-visible-on-hover mr-1">
|
|
|
|
|
- <i className="icon-options fa fa-rotate-90 p-1"></i>
|
|
|
|
|
- </DropdownToggle>
|
|
|
|
|
- </PageItemControl>
|
|
|
|
|
- <UncontrolledTooltip
|
|
|
|
|
- modifiers={{ preventOverflow: { boundariesElement: 'window' } }}
|
|
|
|
|
- autohide={false}
|
|
|
|
|
- placement="right"
|
|
|
|
|
- target={bookmarkItemId}
|
|
|
|
|
- fade={false}
|
|
|
|
|
- >
|
|
|
|
|
- { formerPagePath !== null ? `${formerPagePath}/` : '/' }
|
|
|
|
|
- </UncontrolledTooltip>
|
|
|
|
|
- </li>
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+ <li
|
|
|
|
|
+ className="bookmark-item-list list-group-item list-group-item-action border-0 py-0 pr-3 d-flex align-items-center"
|
|
|
|
|
+ key={bookmarkedPage._id} ref={(c) => { bookmarkItemDragRef(c) }}
|
|
|
|
|
+ id={bookmarkItemId}
|
|
|
|
|
+ >
|
|
|
|
|
+ { isRenameInputShown ? (
|
|
|
|
|
+ <ClosableTextInput
|
|
|
|
|
+ value={nodePath.basename(bookmarkedPage.path ?? '')}
|
|
|
|
|
+ placeholder={t('Input page name')}
|
|
|
|
|
+ onClickOutside={() => { setRenameInputShown(false) }}
|
|
|
|
|
+ onPressEnter={pressEnterForRenameHandler}
|
|
|
|
|
+ inputValidator={inputValidator}
|
|
|
|
|
+ />
|
|
|
|
|
+ ) : (
|
|
|
|
|
+ <a href={`/${bookmarkedPage._id}`} className="grw-foldertree-title-anchor flex-grow-1 pr-3">
|
|
|
|
|
+ <p className={`text-truncate m-auto ${bookmarkedPage.isEmpty && 'grw-sidebar-text-muted'}`}>{pageTitle}</p>
|
|
|
|
|
+ </a>
|
|
|
|
|
+ )}
|
|
|
|
|
+ <PageItemControl
|
|
|
|
|
+ pageId={bookmarkedPage._id}
|
|
|
|
|
+ isEnableActions
|
|
|
|
|
+ forceHideMenuItems={[MenuItemType.DUPLICATE]}
|
|
|
|
|
+ onClickBookmarkMenuItem={bookmarkMenuItemClickHandler}
|
|
|
|
|
+ onClickRenameMenuItem={renameMenuItemClickHandler}
|
|
|
|
|
+ onClickDeleteMenuItem={deleteMenuItemClickHandler}
|
|
|
|
|
+ >
|
|
|
|
|
+ <DropdownToggle color="transparent" className="border-0 rounded btn-page-item-control p-0 grw-visible-on-hover mr-1">
|
|
|
|
|
+ <i className="icon-options fa fa-rotate-90 p-1"></i>
|
|
|
|
|
+ </DropdownToggle>
|
|
|
|
|
+ </PageItemControl>
|
|
|
|
|
+ <UncontrolledTooltip
|
|
|
|
|
+ modifiers={{ preventOverflow: { boundariesElement: 'window' } }}
|
|
|
|
|
+ autohide={false}
|
|
|
|
|
+ placement="right"
|
|
|
|
|
+ target={bookmarkItemId}
|
|
|
|
|
+ fade={false}
|
|
|
|
|
+ >
|
|
|
|
|
+ { formerPagePath !== null ? `${formerPagePath}/` : '/' }
|
|
|
|
|
+ </UncontrolledTooltip>
|
|
|
|
|
+ </li>
|
|
|
);
|
|
);
|
|
|
};
|
|
};
|
|
|
|
|
|