Просмотр исходного кода

create isNewlyCreatedPage constant

kosei-n 2 лет назад
Родитель
Сommit
dc9831952d
1 измененных файлов с 21 добавлено и 4 удалено
  1. 21 4
      apps/app/src/components/PageHeader/PageTitleHeader.tsx

+ 21 - 4
apps/app/src/components/PageHeader/PageTitleHeader.tsx

@@ -1,5 +1,5 @@
 import type { FC } from 'react';
 import type { FC } from 'react';
-import { useState, useCallback } from 'react';
+import { useState, useCallback, useEffect } from 'react';
 
 
 import nodePath from 'path';
 import nodePath from 'path';
 
 
@@ -29,12 +29,21 @@ export const PageTitleHeader: FC<Props> = (props) => {
 
 
   const currentPagePath = currentPage.path;
   const currentPagePath = currentPage.path;
 
 
+  const untitledPageRegex = /^Untitled-\d+$/;
+
+  const isNewlyCreatedPage = currentPage.wip && currentPage.latestRevision == null && untitledPageRegex.test(nodePath.basename(currentPagePath));
+
+  // console.log(isNewlyCreatedPage);
+
   const dPagePath = new DevidedPagePath(currentPage.path, true);
   const dPagePath = new DevidedPagePath(currentPage.path, true);
   const pageTitle = dPagePath.latter;
   const pageTitle = dPagePath.latter;
 
 
-  const [isRenameInputShown, setRenameInputShown] = useState(false);
+  const [isRenameInputShown, setRenameInputShown] = useState(true);
   const [editedPagePath, setEditedPagePath] = useState(currentPagePath);
   const [editedPagePath, setEditedPagePath] = useState(currentPagePath);
 
 
+  // console.log(isNewlyCreatedPage);
+  // console.log(isRenameInputShown);
+
   const pagePathRenameHandler = usePagePathRenameHandler(currentPage);
   const pagePathRenameHandler = usePagePathRenameHandler(currentPage);
 
 
   const editedPageTitle = nodePath.basename(editedPagePath);
   const editedPageTitle = nodePath.basename(editedPagePath);
@@ -69,15 +78,23 @@ export const PageTitleHeader: FC<Props> = (props) => {
     setRenameInputShown(true);
     setRenameInputShown(true);
   }, [currentPagePath]);
   }, [currentPagePath]);
 
 
+  // useEffect(() => {
+  //   if (isNewlyCreatedPage) {
+  //     setRenameInputShown(true);
+  //   }
+  // });
+
+  // console.dir(currentPage);
 
 
   return (
   return (
     <div className={`d-flex align-items-center ${moduleClass} ${props.className ?? ''}`}>
     <div className={`d-flex align-items-center ${moduleClass} ${props.className ?? ''}`}>
       <div className="me-1">
       <div className="me-1">
-        { isRenameInputShown && (
+        {/* { (isRenameInputShown || isNewlyCreatedPage) && ( */}
+        { (isRenameInputShown) && (
           <div className="position-absolute">
           <div className="position-absolute">
             <ClosableTextInput
             <ClosableTextInput
               useAutosizeInput
               useAutosizeInput
-              value={editedPageTitle}
+              value={isNewlyCreatedPage ? '' : editedPageTitle}
               placeholder={t('Input page name')}
               placeholder={t('Input page name')}
               inputClassName="fs-4"
               inputClassName="fs-4"
               onPressEnter={onPressEnter}
               onPressEnter={onPressEnter}