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

Merge branch 'feat/140128-enable-saving-as-a-wip-page' into feat/140129-turn-existing-pages-into-wip-pages

Shun Miyazawa 2 лет назад
Родитель
Сommit
3a1a1b9099

+ 1 - 2
apps/app/src/client/services/create-page/use-create-page-and-transit.tsx

@@ -1,6 +1,5 @@
 import { useCallback, useState } from 'react';
 
-import { shouldCreateWipPage } from '@growi/core/dist/utils';
 import { useRouter } from 'next/router';
 
 import { createPage, exist } from '~/client/services/page-operation';
@@ -87,7 +86,7 @@ export const useCreatePageAndTransit: UseCreatePageAndTransit = () => {
       setCreating(true);
       onCreationStart?.();
 
-      const response = await createPage({ ...params, wip: shouldCreateWipPage(params.path) });
+      const response = await createPage(params);
 
       await router.push(`/${response.page._id}#edit`);
       mutateEditorMode(EditorMode.Editor);

+ 1 - 1
apps/app/src/client/services/create-page/use-create-template-page.ts

@@ -25,7 +25,7 @@ export const useCreateTemplatePage: UseCreateTemplatePage = () => {
     if (isLoadingPagePath || !isCreatable) return;
 
     return createAndTransit(
-      { path: normalizePath(`${currentPagePath}/${label}`) },
+      { path: normalizePath(`${currentPagePath}/${label}`), wip: false },
       { shouldCheckPageExists: true },
     );
   }, [currentPagePath, isCreatable, isLoadingPagePath, createAndTransit]);

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

@@ -7,6 +7,8 @@ import { toastError } from '~/client/util/toastr';
 import { useIsNotFound } from '~/stores/page';
 import { EditorMode, useEditorMode, useIsDeviceLargerThanMd } from '~/stores/ui';
 
+import { shouldCreateWipPage } from '../../utils/should-create-wip-page';
+
 
 import styles from './PageEditorModeManager.module.scss';
 
@@ -72,7 +74,7 @@ export const PageEditorModeManager = (props: Props): JSX.Element => {
 
     try {
       await createAndTransit(
-        { path },
+        { path, wip: shouldCreateWipPage(path) },
         { shouldCheckPageExists: true },
       );
     }

+ 13 - 4
apps/app/src/components/Sidebar/Custom/CustomSidebarNotFound.tsx

@@ -1,16 +1,25 @@
-import Link from 'next/link';
+import { useCallback } from 'react';
+
 import { useTranslation } from 'react-i18next';
 
+import { useCreatePageAndTransit } from '~/client/services/create-page';
+
 export const SidebarNotFound = (): JSX.Element => {
   const { t } = useTranslation();
 
+  const { createAndTransit } = useCreatePageAndTransit();
+
+  const clickCreateButtonHandler = useCallback(async() => {
+    createAndTransit({ path: '/Sidebar', wip: false });
+  }, [createAndTransit]);
+
   return (
-    <div className="grw-sidebar-content-header h5 text-center py-3">
-      <Link href="/Sidebar#edit">
+    <div>
+      <button type="button" className="btn btn-lg btn-link" onClick={clickCreateButtonHandler}>
         <span className="material-symbols-outlined">edit_note</span>
         {/* eslint-disable-next-line react/no-danger */}
         <span dangerouslySetInnerHTML={{ __html: t('Create Sidebar Page') }}></span>
-      </Link>
+      </button>
     </div>
   );
 };

+ 1 - 1
apps/app/src/components/Sidebar/PageCreateButton/hooks/use-create-new-page.ts

@@ -18,7 +18,7 @@ export const useCreateNewPage: UseCreateNewPage = () => {
     if (isLoadingPagePath) return;
 
     return createAndTransit(
-      { parentPath: currentPagePath, optionalParentPath: '/' },
+      { parentPath: currentPagePath, optionalParentPath: '/', wip: true },
     );
   }, [createAndTransit, currentPagePath, isLoadingPagePath]);
 

+ 1 - 1
apps/app/src/components/Sidebar/PageCreateButton/hooks/use-create-todays-memo.tsx

@@ -32,7 +32,7 @@ export const useCreateTodaysMemo: UseCreateTodaysMemo = () => {
     if (!isCreatable || todaysPath == null) return;
 
     return createAndTransit(
-      { path: todaysPath },
+      { path: todaysPath, wip: true },
       { shouldCheckPageExists: true },
     );
   }, [createAndTransit, isCreatable, todaysPath]);

+ 1 - 1
apps/app/src/components/TreeItem/NewPageInput/use-new-page-input.tsx

@@ -1,11 +1,11 @@
 import React, { useState, type FC, useCallback } from 'react';
 
-import { shouldCreateWipPage } from '@growi/core/dist/utils';
 
 import { apiv3Post } from '~/client/util/apiv3-client';
 import { useSWRxPageChildren } from '~/stores/page-listing';
 import { usePageTreeDescCountMap } from '~/stores/ui';
 
+import { shouldCreateWipPage } from '../../../utils/should-create-wip-page';
 import type { TreeItemToolProps } from '../interfaces';
 
 import { NewPageCreateButton } from './NewPageCreateButton';

+ 6 - 5
apps/app/src/server/models/page.ts

@@ -1054,16 +1054,17 @@ schema.methods.calculateAndUpdateLatestRevisionBodyLength = async function(this:
 };
 
 schema.methods.publish = function() {
-  this.wip = false;
+  this.wip = undefined;
   this.wipExpiredAt = undefined;
 };
 
-schema.methods.unpublish = function(isNewPage: boolean) {
+schema.methods.unpublish = function() {
   this.wip = true;
+  this.wipExpiredAt = new Date();
+};
 
-  if (isNewPage) {
-    this.wipExpiredAt = new Date();
-  }
+schema.methods.makeWip = function() {
+  this.wip = true;
 };
 
 /*

+ 2 - 4
apps/app/src/server/service/page/index.ts

@@ -3793,7 +3793,7 @@ class PageService implements IPageService {
 
     // Set wip
     if (options.wip) {
-      page.unpublish(true); // isNewPage = true
+      page.unpublish();
     }
 
     // Save
@@ -4109,9 +4109,7 @@ class PageService implements IPageService {
     const newPageData = pageData;
 
     // Do not consider it for automatic deletion if updated at least once
-    if (newPageData.wipExpiredAt != null) {
-      newPageData.wipExpiredAt = null;
-    }
+    newPageData.wipExpiredAt = undefined;
 
     // use the previous data if absent
     const grant = options.grant ?? clonedPageData.grant;

+ 1 - 1
packages/core/src/utils/should-create-wip-page.ts → apps/app/src/utils/should-create-wip-page.ts

@@ -1,4 +1,4 @@
-import { checkTemplatePath } from './template-checker';
+import { checkTemplatePath } from '@growi/core/dist/utils/template-checker';
 
 /**
  * Returns Whether to create pages with the wip flag

+ 1 - 1
packages/core/src/interfaces/page.ts

@@ -40,7 +40,7 @@ export type IPage = {
   latestRevisionBodyLength?: number,
   expandContentWidth?: boolean,
   wip?: boolean,
-  wipExpiredAt?: Date,
+  wipExpiredAt?: Date
 }
 
 export type IPagePopulatedToList = Omit<IPageHasId, 'lastUpdateUser'> & {

+ 0 - 1
packages/core/src/utils/index.ts

@@ -13,4 +13,3 @@ export * as pageUtils from './page-utils';
 export * from './basic-interceptor';
 export * from './browser-utils';
 export * from './growi-theme-metadata';
-export * from './should-create-wip-page';