소스 검색

fire setShouldHide(true) when dropResult.dropTarget is 'PAGE_TREE'

Shun Miyazawa 4 년 전
부모
커밋
381051ab51
1개의 변경된 파일16개의 추가작업 그리고 5개의 파일을 삭제
  1. 16 5
      packages/app/src/components/Sidebar/PageTree/Item.tsx

+ 16 - 5
packages/app/src/components/Sidebar/PageTree/Item.tsx

@@ -24,6 +24,13 @@ import ClosableTextInput, { AlertInfo, AlertType } from '../../Common/ClosableTe
 import { PageItemControl } from '../../Common/Dropdown/PageItemControl';
 import { PageItemControl } from '../../Common/Dropdown/PageItemControl';
 import { ItemNode } from './ItemNode';
 import { ItemNode } from './ItemNode';
 
 
+const DROP_TARGET = 'PAGE_TREE';
+
+type DropResult = {
+  dropEffect: string
+  dropTarget: string
+}
+
 interface ItemProps {
 interface ItemProps {
   isEnableActions: boolean
   isEnableActions: boolean
   itemNode: ItemNode
   itemNode: ItemNode
@@ -106,11 +113,12 @@ const Item: FC<ItemProps> = (props: ItemProps) => {
   }, []);
   }, []);
 
 
   const [{ isDragging }, drag] = useDrag(() => ({
   const [{ isDragging }, drag] = useDrag(() => ({
-    type: 'PAGE_TREE',
+    type: DROP_TARGET,
     item: { page },
     item: { page },
     end: (item, monitor) => {
     end: (item, monitor) => {
       // in order to set d-none to dropped Item
       // in order to set d-none to dropped Item
-      if (monitor.getDropResult() != null) {
+      const dropResult = monitor.getDropResult() as DropResult;
+      if (dropResult != null && dropResult.dropTarget === 'PAGE_TREE') {
         setShouldHide(true);
         setShouldHide(true);
       }
       }
     },
     },
@@ -119,7 +127,7 @@ const Item: FC<ItemProps> = (props: ItemProps) => {
     }),
     }),
   }));
   }));
 
 
-  const pageItemDropHandler = async(item, monitor) => {
+  const pageItemDropHandler = async(item) => {
     if (page == null || page.path == null) {
     if (page == null || page.path == null) {
       return;
       return;
     }
     }
@@ -160,8 +168,11 @@ const Item: FC<ItemProps> = (props: ItemProps) => {
   };
   };
 
 
   const [{ isOver }, drop] = useDrop(() => ({
   const [{ isOver }, drop] = useDrop(() => ({
-    accept: 'PAGE_TREE',
-    drop: pageItemDropHandler,
+    accept: DROP_TARGET,
+    drop: (item) => {
+      pageItemDropHandler(item);
+      return { dropTarget: DROP_TARGET };
+    },
     hover: (item, monitor) => {
     hover: (item, monitor) => {
       // when a drag item is overlapped more than 1 sec, the drop target item will be opened.
       // when a drag item is overlapped more than 1 sec, the drop target item will be opened.
       if (monitor.isOver()) {
       if (monitor.isOver()) {