|
@@ -8,16 +8,18 @@ import { toastSuccess, toastError } from '~/client/util/toastr';
|
|
|
import { useSWRMUTxCurrentPage } from '~/stores/page';
|
|
import { useSWRMUTxCurrentPage } from '~/stores/page';
|
|
|
import { mutatePageTree, mutatePageList } from '~/stores/page-listing';
|
|
import { mutatePageTree, mutatePageList } from '~/stores/page-listing';
|
|
|
|
|
|
|
|
|
|
+type PagePathRenameHandler = (newPagePath: string, onRenameFinish?: () => void, onRenameFailure?: () => void) => Promise<void>
|
|
|
|
|
+
|
|
|
export const usePagePathRenameHandler = (
|
|
export const usePagePathRenameHandler = (
|
|
|
- currentPage: IPagePopulatedToShowRevision, onRenameFinish?: () => void, onRenameFailure?: () => void,
|
|
|
|
|
-): (newPagePath: string) => Promise<void> => {
|
|
|
|
|
|
|
+ currentPage: IPagePopulatedToShowRevision,
|
|
|
|
|
+): PagePathRenameHandler => {
|
|
|
|
|
|
|
|
const { trigger: mutateCurrentPage } = useSWRMUTxCurrentPage();
|
|
const { trigger: mutateCurrentPage } = useSWRMUTxCurrentPage();
|
|
|
const { t } = useTranslation();
|
|
const { t } = useTranslation();
|
|
|
|
|
|
|
|
const currentPagePath = currentPage.path;
|
|
const currentPagePath = currentPage.path;
|
|
|
|
|
|
|
|
- const pagePathRenameHandler = useCallback(async(newPagePath: string) => {
|
|
|
|
|
|
|
+ const pagePathRenameHandler = useCallback(async(newPagePath, onRenameFinish, onRenameFailure) => {
|
|
|
|
|
|
|
|
const onRenamed = (fromPath: string | undefined, toPath: string) => {
|
|
const onRenamed = (fromPath: string | undefined, toPath: string) => {
|
|
|
mutatePageTree();
|
|
mutatePageTree();
|
|
@@ -34,7 +36,6 @@ export const usePagePathRenameHandler = (
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- onRenameFinish?.();
|
|
|
|
|
await apiv3Put('/pages/rename', {
|
|
await apiv3Put('/pages/rename', {
|
|
|
pageId: currentPage._id,
|
|
pageId: currentPage._id,
|
|
|
revisionId: currentPage.revision._id,
|
|
revisionId: currentPage.revision._id,
|
|
@@ -42,6 +43,7 @@ export const usePagePathRenameHandler = (
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
onRenamed(currentPage.path, newPagePath);
|
|
onRenamed(currentPage.path, newPagePath);
|
|
|
|
|
+ onRenameFinish?.();
|
|
|
|
|
|
|
|
toastSuccess(t('renamed_pages', { path: currentPage.path }));
|
|
toastSuccess(t('renamed_pages', { path: currentPage.path }));
|
|
|
}
|
|
}
|
|
@@ -49,7 +51,7 @@ export const usePagePathRenameHandler = (
|
|
|
onRenameFailure?.();
|
|
onRenameFailure?.();
|
|
|
toastError(err);
|
|
toastError(err);
|
|
|
}
|
|
}
|
|
|
- }, [currentPage._id, currentPage.path, currentPage.revision._id, currentPagePath, mutateCurrentPage, onRenameFailure, onRenameFinish, t]);
|
|
|
|
|
|
|
+ }, [currentPage._id, currentPage.path, currentPage.revision._id, currentPagePath, mutateCurrentPage, t]);
|
|
|
|
|
|
|
|
return pagePathRenameHandler;
|
|
return pagePathRenameHandler;
|
|
|
};
|
|
};
|