From b72411a021704a5f0ecb9e84c085632a79c99fc4 Mon Sep 17 00:00:00 2001 From: Tilman Vatteroth Date: Fri, 22 Sep 2023 10:13:42 +0200 Subject: [PATCH] fix(frontend): type of revision-viewer.tsx Signed-off-by: Tilman Vatteroth --- .../revisions-modal/revision-viewer.tsx | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/frontend/src/components/editor-page/sidebar/specific-sidebar-entries/revisions-sidebar-entry/revisions-modal/revision-viewer.tsx b/frontend/src/components/editor-page/sidebar/specific-sidebar-entries/revisions-sidebar-entry/revisions-modal/revision-viewer.tsx index a7374f1c9..ae43db013 100644 --- a/frontend/src/components/editor-page/sidebar/specific-sidebar-entries/revisions-sidebar-entry/revisions-modal/revision-viewer.tsx +++ b/frontend/src/components/editor-page/sidebar/specific-sidebar-entries/revisions-sidebar-entry/revisions-modal/revision-viewer.tsx @@ -8,9 +8,8 @@ import { useApplicationState } from '../../../../../../hooks/common/use-applicat import { useDarkModeState } from '../../../../../../hooks/dark-mode/use-dark-mode-state' import { AsyncLoadingBoundary } from '../../../../../common/async-loading-boundary/async-loading-boundary' import { invertUnifiedPatch } from './invert-unified-patch' -import { Optional } from '@mrdrogdrog/optional' import { applyPatch, parsePatch } from 'diff' -import React, { useMemo } from 'react' +import React, { Fragment, useMemo } from 'react' import ReactDiffViewer, { DiffMethod } from 'react-diff-viewer' import { useAsync } from 'react-use' @@ -28,7 +27,11 @@ export const RevisionViewer: React.FC = ({ selectedRevision const noteId = useApplicationState((state) => state.noteDetails?.id) const darkModeEnabled = useDarkModeState() - const { value, error, loading } = useAsync(async () => { + const { + value: revision, + error, + loading + } = useAsync(async () => { if (noteId === undefined || selectedRevisionId === undefined) { throw new Error('No revision selected') } else { @@ -37,24 +40,24 @@ export const RevisionViewer: React.FC = ({ selectedRevision }, [selectedRevisionId, noteId]) const previousRevisionContent = useMemo(() => { - return Optional.ofNullable(value) - .flatMap((revision) => - Optional.ofNullable(parsePatch(revision.patch)[0]) - .map((patch) => invertUnifiedPatch(patch)) - .map((patch) => applyPatch(revision.content, patch)) - ) - .orElse('') - }, [value]) + if (revision === undefined) { + return '' + } + const patch = parsePatch(revision.patch)[0] + const inversePatch = invertUnifiedPatch(patch) + const reverseContent = applyPatch(revision.content, inversePatch) + return reverseContent === false ? '' : reverseContent + }, [revision]) if (selectedRevisionId === undefined) { - return null + return } return ( - +