import { WebApplication } from '@/UIModels/Application' import { AppState } from '@/UIModels/AppState' import { HistoryEntry, SNComponent, SNNote } from '@standardnotes/snjs' import { observer } from 'mobx-react-lite' import { FunctionComponent } from 'preact' import { useEffect, useMemo } from 'preact/hooks' import { ComponentView } from '@/Components/ComponentView' import { LegacyHistoryEntry } from './utils' const ABSOLUTE_CENTER_CLASSNAME = 'absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2' type SelectedRevisionContentProps = { application: WebApplication appState: AppState selectedRevision: HistoryEntry | LegacyHistoryEntry editorForCurrentNote: SNComponent | undefined templateNoteForRevision: SNNote } export const SelectedRevisionContent: FunctionComponent = observer( ({ application, appState, selectedRevision, editorForCurrentNote, templateNoteForRevision }) => { const componentViewer = useMemo(() => { if (!editorForCurrentNote) { return undefined } const componentViewer = application.componentManager.createComponentViewer(editorForCurrentNote) componentViewer.setReadonly(true) componentViewer.lockReadonly = true componentViewer.overrideContextItem = templateNoteForRevision return componentViewer }, [application.componentManager, editorForCurrentNote, templateNoteForRevision]) useEffect(() => { return () => { if (componentViewer) { application.componentManager.destroyComponentViewer(componentViewer) } } }, [application.componentManager, componentViewer]) return (
{selectedRevision.payload.content.title}
{!componentViewer && (
{selectedRevision.payload.content.text.length ? ( ) : (
Empty note.
)}
)} {componentViewer && (
)}
) }, )