|
@@ -34,7 +34,6 @@ import {
|
|
|
import {
|
|
import {
|
|
|
useEditorSettings,
|
|
useEditorSettings,
|
|
|
useCurrentIndentSize, usePageTagsForEditors,
|
|
useCurrentIndentSize, usePageTagsForEditors,
|
|
|
- useIsConflict,
|
|
|
|
|
useEditingMarkdown,
|
|
useEditingMarkdown,
|
|
|
useWaitingSaveProcessing,
|
|
useWaitingSaveProcessing,
|
|
|
} from '~/stores/editor';
|
|
} from '~/stores/editor';
|
|
@@ -129,10 +128,7 @@ export const PageEditor = React.memo((props: Props): JSX.Element => {
|
|
|
const { data: user } = useCurrentUser();
|
|
const { data: user } = useCurrentUser();
|
|
|
const { onEditorsUpdated } = useEditingUsers();
|
|
const { onEditorsUpdated } = useEditingUsers();
|
|
|
|
|
|
|
|
- const { data: socket } = useGlobalSocket();
|
|
|
|
|
-
|
|
|
|
|
const { data: rendererOptions } = usePreviewOptions();
|
|
const { data: rendererOptions } = usePreviewOptions();
|
|
|
- const { mutate: mutateIsConflict } = useIsConflict();
|
|
|
|
|
|
|
|
|
|
const { mutate: mutateResolvedTheme } = useResolvedThemeForEditor();
|
|
const { mutate: mutateResolvedTheme } = useResolvedThemeForEditor();
|
|
|
|
|
|
|
@@ -182,26 +178,6 @@ export const PageEditor = React.memo((props: Props): JSX.Element => {
|
|
|
const { data: codeMirrorEditor } = useCodeMirrorEditorIsolated(GlobalCodeMirrorEditorKey.MAIN);
|
|
const { data: codeMirrorEditor } = useCodeMirrorEditorIsolated(GlobalCodeMirrorEditorKey.MAIN);
|
|
|
|
|
|
|
|
|
|
|
|
|
- const checkIsConflict = useCallback((data) => {
|
|
|
|
|
- const { s2cMessagePageUpdated } = data;
|
|
|
|
|
-
|
|
|
|
|
- const isConflict = markdownToPreview !== s2cMessagePageUpdated.revisionBody;
|
|
|
|
|
-
|
|
|
|
|
- mutateIsConflict(isConflict);
|
|
|
|
|
-
|
|
|
|
|
- }, [markdownToPreview, mutateIsConflict]);
|
|
|
|
|
-
|
|
|
|
|
- useEffect(() => {
|
|
|
|
|
- if (socket == null) { return }
|
|
|
|
|
-
|
|
|
|
|
- socket.on(SocketEventName.PageUpdated, checkIsConflict);
|
|
|
|
|
-
|
|
|
|
|
- return () => {
|
|
|
|
|
- socket.off(SocketEventName.PageUpdated, checkIsConflict);
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- }, [socket, checkIsConflict]);
|
|
|
|
|
-
|
|
|
|
|
const save: Save = useCallback(async(revisionId, markdown, opts, onConflict) => {
|
|
const save: Save = useCallback(async(revisionId, markdown, opts, onConflict) => {
|
|
|
if (pageId == null || grantData == null) {
|
|
if (pageId == null || grantData == null) {
|
|
|
logger.error('Some materials to save are invalid', {
|
|
logger.error('Some materials to save are invalid', {
|
|
@@ -372,23 +348,6 @@ export const PageEditor = React.memo((props: Props): JSX.Element => {
|
|
|
|
|
|
|
|
const scrollPreviewHandlerThrottle = useMemo(() => throttle(25, scrollPreviewHandler), [scrollPreviewHandler]);
|
|
const scrollPreviewHandlerThrottle = useMemo(() => throttle(25, scrollPreviewHandler), [scrollPreviewHandler]);
|
|
|
|
|
|
|
|
- const afterResolvedHandler = useCallback(async() => {
|
|
|
|
|
- // get page data from db
|
|
|
|
|
- const pageData = await mutateCurrentPage();
|
|
|
|
|
-
|
|
|
|
|
- // update tag
|
|
|
|
|
- await mutateTagsInfo(); // get from DB
|
|
|
|
|
- syncTagsInfoForEditor(); // sync global state for client
|
|
|
|
|
-
|
|
|
|
|
- // clear isConflict
|
|
|
|
|
- mutateIsConflict(false);
|
|
|
|
|
-
|
|
|
|
|
- // set resolved markdown in editing markdown
|
|
|
|
|
- const markdown = pageData?.revision?.body ?? '';
|
|
|
|
|
- mutateEditingMarkdown(markdown);
|
|
|
|
|
-
|
|
|
|
|
- }, [mutateCurrentPage, mutateEditingMarkdown, mutateIsConflict, mutateTagsInfo, syncTagsInfoForEditor]);
|
|
|
|
|
-
|
|
|
|
|
// initial caret line
|
|
// initial caret line
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
codeMirrorEditor?.setCaretLine();
|
|
codeMirrorEditor?.setCaretLine();
|