|
@@ -11,11 +11,14 @@ import {
|
|
|
} from 'reactstrap';
|
|
} from 'reactstrap';
|
|
|
import { debounce } from 'throttle-debounce';
|
|
import { debounce } from 'throttle-debounce';
|
|
|
|
|
|
|
|
|
|
+import { useCreateTemplatePage } from '~/client/services/create-page';
|
|
|
|
|
+import { useCreatePageAndTransit } from '~/client/services/create-page/use-create-page-and-transit';
|
|
|
import { toastError } from '~/client/util/toastr';
|
|
import { toastError } from '~/client/util/toastr';
|
|
|
import { useCurrentUser, useIsSearchServiceReachable } from '~/stores/context';
|
|
import { useCurrentUser, useIsSearchServiceReachable } from '~/stores/context';
|
|
|
import { usePageCreateModal } from '~/stores/modal';
|
|
import { usePageCreateModal } from '~/stores/modal';
|
|
|
import { EditorMode, useEditorMode } from '~/stores/ui';
|
|
import { EditorMode, useEditorMode } from '~/stores/ui';
|
|
|
|
|
|
|
|
|
|
+
|
|
|
import PagePathAutoComplete from './PagePathAutoComplete';
|
|
import PagePathAutoComplete from './PagePathAutoComplete';
|
|
|
|
|
|
|
|
import styles from './PageCreateModal.module.scss';
|
|
import styles from './PageCreateModal.module.scss';
|
|
@@ -33,6 +36,9 @@ const PageCreateModal = () => {
|
|
|
const { data: pageCreateModalData, close: closeCreateModal } = usePageCreateModal();
|
|
const { data: pageCreateModalData, close: closeCreateModal } = usePageCreateModal();
|
|
|
const { isOpened, path } = pageCreateModalData;
|
|
const { isOpened, path } = pageCreateModalData;
|
|
|
|
|
|
|
|
|
|
+ const { isCreating, createAndTransit } = useCreatePageAndTransit();
|
|
|
|
|
+ const { createTemplate } = useCreateTemplatePage();
|
|
|
|
|
+
|
|
|
const { data: isReachable } = useIsSearchServiceReachable();
|
|
const { data: isReachable } = useIsSearchServiceReachable();
|
|
|
const pathname = path || '';
|
|
const pathname = path || '';
|
|
|
const userHomepagePath = pagePathUtils.userHomepagePath(currentUser);
|
|
const userHomepagePath = pagePathUtils.userHomepagePath(currentUser);
|
|
@@ -124,32 +130,53 @@ const PageCreateModal = () => {
|
|
|
/**
|
|
/**
|
|
|
* access today page
|
|
* access today page
|
|
|
*/
|
|
*/
|
|
|
- function createTodayPage() {
|
|
|
|
|
|
|
+ const createTodayPage = useCallback(async() => {
|
|
|
let tmpTodayInput1 = todayInput1;
|
|
let tmpTodayInput1 = todayInput1;
|
|
|
if (tmpTodayInput1 === '') {
|
|
if (tmpTodayInput1 === '') {
|
|
|
tmpTodayInput1 = t('Memo');
|
|
tmpTodayInput1 = t('Memo');
|
|
|
}
|
|
}
|
|
|
- redirectToEditor(userHomepagePath, tmpTodayInput1, now, todayInput2);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ const joinedPath = [userHomepagePath, tmpTodayInput1, now, todayInput2].join('/');
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ await createAndTransit(
|
|
|
|
|
+ { path: joinedPath, wip: true },
|
|
|
|
|
+ { shouldCheckPageExists: true },
|
|
|
|
|
+ );
|
|
|
|
|
+ closeCreateModal();
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (err) {
|
|
|
|
|
+ //
|
|
|
|
|
+ }
|
|
|
|
|
+ }, [closeCreateModal, createAndTransit, now, t, todayInput1, todayInput2, userHomepagePath]);
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* access input page
|
|
* access input page
|
|
|
*/
|
|
*/
|
|
|
- function createInputPage() {
|
|
|
|
|
- redirectToEditor(pageNameInput);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- const ppacSubmitHandler = useCallback((input) => {
|
|
|
|
|
- redirectToEditor(input);
|
|
|
|
|
- }, [redirectToEditor]);
|
|
|
|
|
|
|
+ const createInoutPage = useCallback(async() => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ await createAndTransit({ path: pageNameInput, optionalParentPath: '/', wip: true });
|
|
|
|
|
+ closeCreateModal();
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (err) {
|
|
|
|
|
+ //
|
|
|
|
|
+ }
|
|
|
|
|
+ }, [closeCreateModal, createAndTransit, pageNameInput]);
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* access template page
|
|
* access template page
|
|
|
*/
|
|
*/
|
|
|
- function createTemplatePage(e) {
|
|
|
|
|
- const pageName = (template === 'children') ? '_template' : '__template';
|
|
|
|
|
- redirectToEditor(pathname, pageName);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ const createTemplatePage = useCallback(async() => {
|
|
|
|
|
+ const label = (template === 'children') ? '_template' : '__template';
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ await createTemplate(label);
|
|
|
|
|
+ closeCreateModal();
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (err) {
|
|
|
|
|
+ //
|
|
|
|
|
+ }
|
|
|
|
|
+ }, [closeCreateModal, createTemplate, template]);
|
|
|
|
|
|
|
|
function renderCreateTodayForm() {
|
|
function renderCreateTodayForm() {
|
|
|
if (!isOpened) {
|
|
if (!isOpened) {
|
|
@@ -221,13 +248,13 @@ const PageCreateModal = () => {
|
|
|
<PagePathAutoComplete
|
|
<PagePathAutoComplete
|
|
|
initializedPath={pageNameInputInitialValue}
|
|
initializedPath={pageNameInputInitialValue}
|
|
|
addTrailingSlash
|
|
addTrailingSlash
|
|
|
- onSubmit={ppacSubmitHandler}
|
|
|
|
|
|
|
+ onSubmit={createInoutPage}
|
|
|
onInputChange={value => setPageNameInput(value)}
|
|
onInputChange={value => setPageNameInput(value)}
|
|
|
autoFocus
|
|
autoFocus
|
|
|
/>
|
|
/>
|
|
|
)
|
|
)
|
|
|
: (
|
|
: (
|
|
|
- <form onSubmit={e => transitBySubmitEvent(e, createInputPage)}>
|
|
|
|
|
|
|
+ <form onSubmit={createInoutPage}>
|
|
|
<input
|
|
<input
|
|
|
type="text"
|
|
type="text"
|
|
|
value={pageNameInput}
|
|
value={pageNameInput}
|
|
@@ -245,7 +272,7 @@ const PageCreateModal = () => {
|
|
|
type="button"
|
|
type="button"
|
|
|
data-testid="btn-create-page-under-below"
|
|
data-testid="btn-create-page-under-below"
|
|
|
className="grw-btn-create-page btn btn-outline-primary rounded-pill text-nowrap ms-3"
|
|
className="grw-btn-create-page btn btn-outline-primary rounded-pill text-nowrap ms-3"
|
|
|
- onClick={createInputPage}
|
|
|
|
|
|
|
+ onClick={createInoutPage}
|
|
|
disabled={isMatchedWithUserHomepagePath}
|
|
disabled={isMatchedWithUserHomepagePath}
|
|
|
>
|
|
>
|
|
|
<span className="material-symbols-outlined">description</span>{t('Create')}
|
|
<span className="material-symbols-outlined">description</span>{t('Create')}
|