Przeglądaj źródła

If descendant pages exist, force open when the + button is pressed

Shun Miyazawa 4 lat temu
rodzic
commit
331c825636

+ 7 - 9
packages/app/src/components/Sidebar/PageTree/Item.tsx

@@ -241,7 +241,11 @@ const Item: FC<ItemProps> = (props: ItemProps) => {
 
   const onClickPlusButton = useCallback(() => {
     setNewPageInputShown(true);
-  }, []);
+
+    if (hasDescendants) {
+      setIsOpen(true);
+    }
+  }, [hasDescendants]);
 
   const duplicateMenuItemClickHandler = useCallback((): void => {
     if (onClickDuplicateMenuItem == null) {
@@ -337,9 +341,6 @@ const Item: FC<ItemProps> = (props: ItemProps) => {
     }
 
     try {
-      // force open
-      setIsOpen(true);
-
       setCreating(true);
 
       await apiv3Post('/pages/', {
@@ -350,6 +351,8 @@ const Item: FC<ItemProps> = (props: ItemProps) => {
         createFromPageTree: true,
       });
 
+      setCreating(false);
+
       mutateChildren();
 
       toastSuccess(t('successfully_saved_the_page'));
@@ -357,11 +360,6 @@ const Item: FC<ItemProps> = (props: ItemProps) => {
     catch (err) {
       toastError(err);
     }
-    finally {
-      setTimeout(() => {
-        setCreating(false);
-      }, 500);
-    }
   };
 
   const inputValidator = (title: string | null): AlertInfo | null => {