jam411 3 лет назад
Родитель
Сommit
88ada287aa

+ 11 - 21
packages/app/src/components/PageHistory/RevisionDiff.tsx

@@ -20,30 +20,20 @@ export const RevisionDiff = (props: RevisioinDiffProps): JSX.Element => {
 
   const { currentRevision, previousRevision, revisionDiffOpened } = props;
 
-  let diffViewHTML = '';
-  if (currentRevision.body
-    && previousRevision.body
-    && revisionDiffOpened) {
+  const previousText = (currentRevision._id === previousRevision._id) ? '' : previousRevision.body;
 
-    let previousText = previousRevision.body;
-    // comparing ObjectId
-    // eslint-disable-next-line eqeqeq
-    if (currentRevision._id == previousRevision._id) {
-      previousText = '';
-    }
+  const patch = createPatch(
+    currentRevision.pageId, // currentRevision.path is DEPRECATED
+    previousText,
+    currentRevision.body,
+  );
 
-    const patch = createPatch(
-      currentRevision.pageId, // currentRevision.path is DEPRECATED
-      previousText,
-      currentRevision.body,
-    );
-    const option: Diff2HtmlConfig = {
-      outputFormat: 'side-by-side',
-      drawFileList: false,
-    };
+  const option: Diff2HtmlConfig = {
+    outputFormat: 'side-by-side',
+    drawFileList: false,
+  };
 
-    diffViewHTML = html(patch, option);
-  }
+  const diffViewHTML = (currentRevision.body && previousRevision.body && revisionDiffOpened) ? html(patch, option) : '';
 
   const diffView = { __html: diffViewHTML };
 

+ 4 - 10
packages/app/src/components/RevisionComparer/RevisionComparer.tsx

@@ -38,11 +38,11 @@ export const RevisionComparer = (props: RevisionComparerProps): JSX.Element => {
   const { data: currentPagePath } = useCurrentPagePath();
   const [dropdownOpen, setDropdownOpen] = useState(false);
 
-  function toggleDropdown() {
+  const toggleDropdown = () => {
     setDropdownOpen(!dropdownOpen);
-  }
+  };
 
-  const generateURL = (pathName) => {
+  const generateURL = (pathName: string) => {
     const { origin } = window.location;
 
     const url = new URL(pathName, origin);
@@ -55,13 +55,7 @@ export const RevisionComparer = (props: RevisionComparerProps): JSX.Element => {
     return encodeSpaces(decodeURI(url.href));
   };
 
-  let isNodiff: boolean;
-  if (sourceRevision == null || targetRevision == null) {
-    isNodiff = true;
-  }
-  else {
-    isNodiff = sourceRevision._id === targetRevision._id;
-  }
+  const isNodiff = (sourceRevision == null || targetRevision == null) ? true : sourceRevision._id === targetRevision._id;
 
   if (currentPageId == null || currentPagePath == null) {
     return <>{ t('not_found_page.page_not_exist')}</>;