diff --git a/.gitignore b/.gitignore index ba5f1314d6..91db22af1e 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ data/* *.pem *.key *.cert +.history # Yarn Berry .yarn/* diff --git a/app/actions/definitions/revisions.tsx b/app/actions/definitions/revisions.tsx index be90ec8633..fee7d43e9e 100644 --- a/app/actions/definitions/revisions.tsx +++ b/app/actions/definitions/revisions.tsx @@ -3,6 +3,7 @@ import { LinkIcon, RestoreIcon, TrashIcon, DownloadIcon } from "outline-icons"; import { matchPath } from "react-router-dom"; import { toast } from "sonner"; import { ExportContentType } from "@shared/types"; +import Revision from "~/models/Revision"; import stores from "~/stores"; import { createAction, createActionWithChildren } from "~/actions"; import { RevisionSection } from "~/actions/sections"; @@ -21,7 +22,7 @@ export const restoreRevision = createAction({ section: RevisionSection, visible: ({ activeDocumentId }) => !!activeDocumentId && stores.policies.abilities(activeDocumentId).update, - perform: async ({ event, location, activeDocumentId }) => { + perform: async ({ event, location, activeDocumentId, getActiveModel }) => { event?.preventDefault(); if (!activeDocumentId) { return; @@ -30,7 +31,10 @@ export const restoreRevision = createAction({ const match = matchPath<{ revisionId: string }>(location.pathname, { path: matchDocumentHistory, }); - const revisionId = match?.params.revisionId; + const revisionId = getActiveModel(Revision)?.id ?? match?.params.revisionId; + if (!revisionId) { + return; + } const document = stores.documents.get(activeDocumentId); if (!document) { diff --git a/app/scenes/Document/components/Document.tsx b/app/scenes/Document/components/Document.tsx index f2273cbe69..5d0c7823a9 100644 --- a/app/scenes/Document/components/Document.tsx +++ b/app/scenes/Document/components/Document.tsx @@ -125,6 +125,16 @@ function DocumentScene({ return; } + history.replace(document.url, { + ...location.state, + restore: undefined, + revisionId: undefined, + }); + + if (!revisionId) { + return; + } + const response = await client.post("/revisions.info", { id: revisionId, }); @@ -135,7 +145,6 @@ function DocumentScene({ new AllSelection(editor.view.state.doc) ); toast.success(t("Document restored")); - history.replace(document.url, history.location.state); } }, [location, replaceSelection, t, history, document.url]); diff --git a/app/scenes/Document/components/History/RevisionListItem.tsx b/app/scenes/Document/components/History/RevisionListItem.tsx index d14a0c767c..cb7b2cc942 100644 --- a/app/scenes/Document/components/History/RevisionListItem.tsx +++ b/app/scenes/Document/components/History/RevisionListItem.tsx @@ -112,7 +112,7 @@ const RevisionListItem = ({ item, document, ...rest }: Props) => { } return ( - +