Browse Source

add creating state

ryoji-s 2 years ago
parent
commit
d46e652a18
1 changed files with 8 additions and 0 deletions
  1. 8 0
      apps/app/src/components/Sidebar/PageCreateButton.tsx

+ 8 - 0
apps/app/src/components/Sidebar/PageCreateButton.tsx

@@ -15,6 +15,7 @@ export const PageCreateButton = React.memo((): JSX.Element => {
   const { data: currentPage, isLoading } = useSWRxCurrentPage();
   const { data: currentPage, isLoading } = useSWRxCurrentPage();
 
 
   const [isHovered, setIsHovered] = useState(false);
   const [isHovered, setIsHovered] = useState(false);
+  const [isCreating, setIsCreating] = useState(false);
 
 
   const onMouseEnterHandler = () => {
   const onMouseEnterHandler = () => {
     setIsHovered(true);
     setIsHovered(true);
@@ -29,6 +30,8 @@ export const PageCreateButton = React.memo((): JSX.Element => {
     if (isLoading) return;
     if (isLoading) return;
 
 
     try {
     try {
+      setIsCreating(true);
+
       const parentPath = currentPage == null || isCreatablePage(currentPage.path)
       const parentPath = currentPage == null || isCreatablePage(currentPage.path)
         ? '/'
         ? '/'
         : currentPage.path;
         : currentPage.path;
@@ -50,6 +53,9 @@ export const PageCreateButton = React.memo((): JSX.Element => {
       logger.warn(err);
       logger.warn(err);
       toastError(err);
       toastError(err);
     }
     }
+    finally {
+      setIsCreating(false);
+    }
   }, [currentPage, isLoading, router]);
   }, [currentPage, isLoading, router]);
   const onCreateTodaysButtonHandler = useCallback(() => {
   const onCreateTodaysButtonHandler = useCallback(() => {
     // router.push(`${router.pathname}#edit`);
     // router.push(`${router.pathname}#edit`);
@@ -77,6 +83,7 @@ export const PageCreateButton = React.memo((): JSX.Element => {
           onClick={onCreateNewPageButtonHandler}
           onClick={onCreateNewPageButtonHandler}
           type="button"
           type="button"
           data-testid="grw-sidebar-nav-page-create-button"
           data-testid="grw-sidebar-nav-page-create-button"
+          disabled={isCreating}
         >
         >
           <i className="material-icons">{iconName}</i>
           <i className="material-icons">{iconName}</i>
         </button>
         </button>
@@ -95,6 +102,7 @@ export const PageCreateButton = React.memo((): JSX.Element => {
                 className="dropdown-item"
                 className="dropdown-item"
                 onClick={onCreateNewPageButtonHandler}
                 onClick={onCreateNewPageButtonHandler}
                 type="button"
                 type="button"
+                disabled={isCreating}
               >
               >
                 Create New Page
                 Create New Page
               </button>
               </button>