import type { RevisionPojo, RevisionItem } from "@triliumnext/commons"; import appContext from "../../components/app_context"; import FNote from "../../entities/fnote"; import dialog from "../../services/dialog"; import froca from "../../services/froca"; import { t } from "../../services/i18n"; import server from "../../services/server"; import toast from "../../services/toast"; import Button from "../react/Button"; import FormToggle from "../react/FormToggle"; import Modal from "../react/Modal"; import FormList, { FormListItem } from "../react/FormList"; import utils from "../../services/utils"; import { Dispatch, StateUpdater, useEffect, useRef, useState } from "preact/hooks"; import protected_session_holder from "../../services/protected_session_holder"; import { renderMathInElement } from "../../services/math"; import type { CSSProperties } from "preact/compat"; import open from "../../services/open"; import ActionButton from "../react/ActionButton"; import options from "../../services/options"; import { useTriliumEvent } from "../react/hooks"; import { diffWords } from "diff"; export default function RevisionsDialog() { const [ note, setNote ] = useState(); const [ noteContent, setNoteContent ] = useState(); const [ revisions, setRevisions ] = useState(); const [ currentRevision, setCurrentRevision ] = useState(); const [ shown, setShown ] = useState(false); const [ showDiff, setShowDiff ] = useState(false); const [ refreshCounter, setRefreshCounter ] = useState(0); useTriliumEvent("showRevisions", async ({ noteId }) => { const note = await getNote(noteId); if (note) { setNote(note); setShown(true); } }); useEffect(() => { if (note?.noteId) { server.get(`notes/${note.noteId}/revisions`).then(setRevisions); note.getContent().then(setNoteContent); } else { setRevisions(undefined); setNoteContent(undefined); } }, [ note?.noteId, refreshCounter ]); if (revisions?.length && !currentRevision) { setCurrentRevision(revisions[0]); } return ( {["text", "code", "mermaid"].includes(currentRevision?.type ?? "") && ( setShowDiff(newValue)} switchOnName={t("revisions.diff_on")} switchOffName={t("revisions.diff_off")} switchOnTooltip={t("revisions.diff_on_hint")} switchOffTooltip={t("revisions.diff_off_hint")} /> )}