|
@@ -10,7 +10,7 @@ import { useRouter } from 'next/router';
|
|
|
import { useTranslation } from 'react-i18next';
|
|
import { useTranslation } from 'react-i18next';
|
|
|
import urljoin from 'url-join';
|
|
import urljoin from 'url-join';
|
|
|
|
|
|
|
|
-import { useSaveOrUpdate } from '~/client/services/page-operation';
|
|
|
|
|
|
|
+import { useUpdateStateAfterSave, useSaveOrUpdate } from '~/client/services/page-operation';
|
|
|
import { toastError, toastSuccess } from '~/client/util/apiNotification';
|
|
import { toastError, toastSuccess } from '~/client/util/apiNotification';
|
|
|
import { apiPost } from '~/client/util/apiv1-client';
|
|
import { apiPost } from '~/client/util/apiv1-client';
|
|
|
import { IResHackmdIntegrated, IResHackmdDiscard } from '~/interfaces/hackmd';
|
|
import { IResHackmdIntegrated, IResHackmdDiscard } from '~/interfaces/hackmd';
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
usePageIdOnHackmd, useHasDraftOnHackmd, useRevisionIdHackmdSynced, useIsHackmdDraftUpdatingInRealtime,
|
|
usePageIdOnHackmd, useHasDraftOnHackmd, useRevisionIdHackmdSynced, useIsHackmdDraftUpdatingInRealtime,
|
|
|
} from '~/stores/hackmd';
|
|
} from '~/stores/hackmd';
|
|
|
import { useCurrentPagePath, useSWRxCurrentPage, useSWRxTagsInfo } from '~/stores/page';
|
|
import { useCurrentPagePath, useSWRxCurrentPage, useSWRxTagsInfo } from '~/stores/page';
|
|
|
-import { useRemoteRevisionId } from '~/stores/remote-latest-page';
|
|
|
|
|
|
|
+import { useRemoteRevisionId, useSetRemoteLatestPageData } from '~/stores/remote-latest-page';
|
|
|
import {
|
|
import {
|
|
|
EditorMode,
|
|
EditorMode,
|
|
|
useEditorMode, useSelectedGrant,
|
|
useEditorMode, useSelectedGrant,
|
|
@@ -86,7 +86,9 @@ export const PageEditorByHackmd = (): JSX.Element => {
|
|
|
const { data: revisionIdHackmdSynced, mutate: mutateRevisionIdHackmdSynced } = useRevisionIdHackmdSynced();
|
|
const { data: revisionIdHackmdSynced, mutate: mutateRevisionIdHackmdSynced } = useRevisionIdHackmdSynced();
|
|
|
const { mutate: mutateIsEnabledUnsavedWarning } = useIsEnabledUnsavedWarning();
|
|
const { mutate: mutateIsEnabledUnsavedWarning } = useIsEnabledUnsavedWarning();
|
|
|
const { data: isHackmdDraftUpdatingInRealtime, mutate: mutateIsHackmdDraftUpdatingInRealtime } = useIsHackmdDraftUpdatingInRealtime();
|
|
const { data: isHackmdDraftUpdatingInRealtime, mutate: mutateIsHackmdDraftUpdatingInRealtime } = useIsHackmdDraftUpdatingInRealtime();
|
|
|
- const { data: remoteRevisionId, mutate: mutateRemoteRevisionId } = useRemoteRevisionId(revision?._id);
|
|
|
|
|
|
|
+ const { data: remoteRevisionId, mutate: mutateRemoteRevisionId } = useRemoteRevisionId();
|
|
|
|
|
+
|
|
|
|
|
+ const updateStateAfterSave = useUpdateStateAfterSave();
|
|
|
|
|
|
|
|
const hackmdEditorRef = useRef<HackEditorRef>(null);
|
|
const hackmdEditorRef = useRef<HackEditorRef>(null);
|
|
|
|
|
|
|
@@ -123,8 +125,7 @@ export const PageEditorByHackmd = (): JSX.Element => {
|
|
|
await router.push(`/${page._id}`);
|
|
await router.push(`/${page._id}`);
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
- await mutateCurrentPageId(page._id);
|
|
|
|
|
- await mutatePageData();
|
|
|
|
|
|
|
+ updateStateAfterSave(page._id);
|
|
|
}
|
|
}
|
|
|
setIsInitialized(false);
|
|
setIsInitialized(false);
|
|
|
mutateEditorMode(EditorMode.View);
|
|
mutateEditorMode(EditorMode.View);
|
|
@@ -134,7 +135,7 @@ export const PageEditorByHackmd = (): JSX.Element => {
|
|
|
toastError(error.message);
|
|
toastError(error.message);
|
|
|
}
|
|
}
|
|
|
// eslint-disable-next-line max-len
|
|
// eslint-disable-next-line max-len
|
|
|
- }, [editorMode, isSlackEnabled, currentPathname, slackChannels, grant, revision, revisionIdHackmdSynced, pageTags, saveOrUpdate, pageId, currentPagePath, mutatePageData, mutateTagsInfo, isNotFound, mutateEditorMode, router, mutateCurrentPageId]);
|
|
|
|
|
|
|
+ }, [editorMode, isSlackEnabled, currentPathname, slackChannels, grant, revision, revisionIdHackmdSynced, pageTags, saveOrUpdate, pageId, currentPagePath, mutatePageData, mutateTagsInfo, isNotFound, mutateEditorMode, router, useUpdateStateAfterSave]);
|
|
|
|
|
|
|
|
// set handler to save and reload Page
|
|
// set handler to save and reload Page
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
@@ -255,9 +256,7 @@ export const PageEditorByHackmd = (): JSX.Element => {
|
|
|
mutatePageData(res);
|
|
mutatePageData(res);
|
|
|
|
|
|
|
|
// set updated data
|
|
// set updated data
|
|
|
- mutateRemoteRevisionId(res.revision._id);
|
|
|
|
|
- mutateRevisionIdHackmdSynced(res.page.revisionHackmdSynced);
|
|
|
|
|
- mutateHasDraftOnHackmd(res.page.hasDraftOnHackmd);
|
|
|
|
|
|
|
+ updateStateAfterSave(res._id);
|
|
|
mutateTagsInfo();
|
|
mutateTagsInfo();
|
|
|
|
|
|
|
|
logger.debug('success to save');
|
|
logger.debug('success to save');
|
|
@@ -269,8 +268,9 @@ export const PageEditorByHackmd = (): JSX.Element => {
|
|
|
toastError(error.message);
|
|
toastError(error.message);
|
|
|
}
|
|
}
|
|
|
}, [
|
|
}, [
|
|
|
- currentPagePath, currentPathname, isSlackEnabled, grant, slackChannels, pageId, revisionIdHackmdSynced, pageTags,
|
|
|
|
|
- saveOrUpdate, mutatePageData, mutateRemoteRevisionId, mutateRevisionIdHackmdSynced, mutateHasDraftOnHackmd, mutateTagsInfo, t]);
|
|
|
|
|
|
|
+ currentPagePath, currentPathname, isSlackEnabled, grant, slackChannels, pageId, revisionIdHackmdSynced,
|
|
|
|
|
+ pageTags, saveOrUpdate, mutatePageData, useUpdateStateAfterSave, mutateTagsInfo, t,
|
|
|
|
|
+ ]);
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* onChange event of HackmdEditor handler
|
|
* onChange event of HackmdEditor handler
|