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

fix transition to the editor mode

Yuki Takei 5 месяцев назад
Родитель
Сommit
d4a1225d2f

+ 4 - 1
apps/app/src/client/components/Navbar/PageEditorModeManager.tsx

@@ -74,11 +74,12 @@ export const PageEditorModeManager = (props: Props): JSX.Element => {
   const { isCreating, create } = useCreatePage();
 
   const editButtonClickedHandler = useCallback(async () => {
-    if (isNotFound === false) {
+    if (!isNotFound) {
       setEditorMode(EditorMode.Editor);
       return;
     }
 
+    // Create a new page if it does not exist and transit to the editor mode
     try {
       const parentPath = path != null ? getParentPath(path) : undefined; // does not have to exist
       await create(
@@ -86,6 +87,8 @@ export const PageEditorModeManager = (props: Props): JSX.Element => {
           path, parentPath, wip: shouldCreateWipPage(path), origin: Origin.View,
         },
       );
+
+      setEditorMode(EditorMode.Editor);
     }
     catch (err) {
       toastError(t('toaster.create_failed', { target: path }));

+ 1 - 3
apps/app/src/states/ui/editor/editor-mode.ts

@@ -40,12 +40,10 @@ export const editorModeAtom = atom(
 
 export const useEditorMode = (): UseEditorModeReturn => {
   const isEditable = useIsEditable();
-  const isNotFound = usePageNotFound();
   const [editorMode, setEditorModeRaw] = useAtom(editorModeAtom);
 
   // Check if editor mode should be prevented
-  const preventModeEditor =
-    !isEditable || isNotFound === undefined || isNotFound === true;
+  const preventModeEditor = !isEditable;
 
   // Ensure View mode when editing is not allowed
   const finalMode = preventModeEditor ? EditorMode.View : editorMode;