Просмотр исходного кода

don't show edit button if editor has revision diff

reiji-h 1 год назад
Родитель
Сommit
f42189dd5c

+ 5 - 0
apps/app/src/client/components/PageEditor/PageEditor.tsx

@@ -44,6 +44,7 @@ import { mutatePageTree } from '~/stores/page-listing';
 import { usePreviewOptions } from '~/stores/renderer';
 import { useIsUntitledPage, useSelectedGrant } from '~/stores/ui';
 import { useEditingUsers } from '~/stores/use-editing-users';
+import { useCurrentPageYjsData } from '~/stores/yjs';
 import loggerFactory from '~/utils/logger';
 
 import { EditorNavbar } from './EditorNavbar';
@@ -107,6 +108,7 @@ export const PageEditor = React.memo((props: Props): JSX.Element => {
   const { data: editorSettings } = useEditorSettings();
   const { mutate: mutateIsGrantNormalized } = useSWRxCurrentGrantData(currentPage?._id);
   const { data: user } = useCurrentUser();
+  const { data: currentPageYjsData } = useCurrentPageYjsData();
   const { onEditorsUpdated } = useEditingUsers();
   const onConflict = useConflictResolver();
 
@@ -301,6 +303,9 @@ export const PageEditor = React.memo((props: Props): JSX.Element => {
   // set handler to set caret line
   useEffect(() => {
     const handler = (lineNumber?: number) => {
+      if (currentPageYjsData?.hasRevisionBodyDiff) {
+        return;
+      }
       codeMirrorEditor?.setCaretLineInit(lineNumber);
     };
     globalEmitter.on('setCaretLine', handler);

+ 3 - 1
apps/app/src/client/components/ReactMarkdownComponents/Header.tsx

@@ -9,6 +9,7 @@ import { NextLink } from '~/components/ReactMarkdownComponents/NextLink';
 import {
   useIsGuestUser, useIsReadOnlyUser, useIsSharedUser, useShareLinkId,
 } from '~/stores-universal/context';
+import { useCurrentPageYjsData } from '~/stores/yjs';
 import loggerFactory from '~/utils/logger';
 
 
@@ -69,6 +70,7 @@ export const Header = (props: HeaderProps): JSX.Element => {
   const { data: isReadOnlyUser } = useIsReadOnlyUser();
   const { data: isSharedUser } = useIsSharedUser();
   const { data: shareLinkId } = useShareLinkId();
+  const { data: currentPageYjsData } = useCurrentPageYjsData();
 
   const router = useRouter();
 
@@ -114,7 +116,7 @@ export const Header = (props: HeaderProps): JSX.Element => {
     };
   }, [activateByHash, router.events]);
 
-  const showEditButton = !isGuestUser && !isReadOnlyUser && !isSharedUser && shareLinkId == null;
+  const showEditButton = !isGuestUser && !isReadOnlyUser && !isSharedUser && shareLinkId == null && currentPageYjsData?.hasRevisionBodyDiff === true;
 
   return (
     <>