|
@@ -34,36 +34,31 @@ type Props = {
|
|
|
|
|
|
|
|
export const TextInputForPageTitleAndPath: FC<Props> = (props) => {
|
|
export const TextInputForPageTitleAndPath: FC<Props> = (props) => {
|
|
|
const {
|
|
const {
|
|
|
- currentPage, stateHandler, inputValue, CustomComponent, onInputChange,
|
|
|
|
|
|
|
+ currentPage, stateHandler, inputValue, CustomComponent, onInputChange, onPressEscape,
|
|
|
} = props;
|
|
} = props;
|
|
|
|
|
|
|
|
const { t } = useTranslation();
|
|
const { t } = useTranslation();
|
|
|
|
|
|
|
|
const { isRenameInputShown, setRenameInputShown } = stateHandler;
|
|
const { isRenameInputShown, setRenameInputShown } = stateHandler;
|
|
|
|
|
|
|
|
- const onRenameFinish = () => {
|
|
|
|
|
- setRenameInputShown(false);
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- const onRenameFailure = () => {
|
|
|
|
|
- setRenameInputShown(true);
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- const pagePathRenameHandler = usePagePathRenameHandler(currentPage, onRenameFinish, onRenameFailure);
|
|
|
|
|
|
|
+ const pagePathRenameHandler = usePagePathRenameHandler(currentPage);
|
|
|
|
|
|
|
|
const onPressEnter = useCallback((inputPagePath: string) => {
|
|
const onPressEnter = useCallback((inputPagePath: string) => {
|
|
|
|
|
|
|
|
const parentPath = pathUtils.addTrailingSlash(nodePath.dirname(currentPage.path ?? ''));
|
|
const parentPath = pathUtils.addTrailingSlash(nodePath.dirname(currentPage.path ?? ''));
|
|
|
const newPagePath = nodePath.resolve(parentPath, inputPagePath);
|
|
const newPagePath = nodePath.resolve(parentPath, inputPagePath);
|
|
|
|
|
|
|
|
- pagePathRenameHandler(newPagePath);
|
|
|
|
|
|
|
+ const onRenameFinish = () => {
|
|
|
|
|
+ setRenameInputShown(false);
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const onRenameFailure = () => {
|
|
|
|
|
+ setRenameInputShown(true);
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
- }, [currentPage.path, pagePathRenameHandler]);
|
|
|
|
|
|
|
+ pagePathRenameHandler(newPagePath, onRenameFinish, onRenameFailure);
|
|
|
|
|
|
|
|
- // const onPressEscape = useCallback(() => {
|
|
|
|
|
- // setEditedPagePath(currentPage.path);
|
|
|
|
|
- // setRenameInputShown(false);
|
|
|
|
|
- // }, [currentPage.path, setEditedPagePath, setRenameInputShown]);
|
|
|
|
|
|
|
+ }, [currentPage.path, pagePathRenameHandler, setRenameInputShown]);
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<>
|
|
<>
|
|
@@ -73,7 +68,7 @@ export const TextInputForPageTitleAndPath: FC<Props> = (props) => {
|
|
|
value={inputValue}
|
|
value={inputValue}
|
|
|
placeholder={t('Input page name')}
|
|
placeholder={t('Input page name')}
|
|
|
onPressEnter={onPressEnter}
|
|
onPressEnter={onPressEnter}
|
|
|
- onPressEscape={props.onPressEscape}
|
|
|
|
|
|
|
+ onPressEscape={onPressEscape}
|
|
|
validationTarget={ValidationTarget.PAGE}
|
|
validationTarget={ValidationTarget.PAGE}
|
|
|
handleInputChange={onInputChange}
|
|
handleInputChange={onInputChange}
|
|
|
/>
|
|
/>
|