From c7f87d0f2687fd2c5065bf81332b9daf21d7f427 Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Fri, 27 Jan 2023 14:19:55 +0100 Subject: [PATCH] :bug: Fix incorrect state after undo page creation --- CHANGES.md | 1 + .../src/app/main/data/workspace/common.cljs | 23 ++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index a2cb4c73e..b8e7d1d8d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -66,6 +66,7 @@ - Fix multiuser - "Shadow" element is not updating immediately [Taiga #4709](https://tree.taiga.io/project/penpot/issue/4709) - Fix paths not flagged as modified when resized [Taiga #4742](https://tree.taiga.io/project/penpot/issue/4742) - Fix resend invitation doesn't reset the expiration date [Taiga #4741](https://tree.taiga.io/project/penpot/issue/4741) +- Fix incorrect state after undo page creation [Taiga #4690](https://tree.taiga.io/project/penpot/issue/4690) ### :heart: Community contributions by (Thank you!) diff --git a/frontend/src/app/main/data/workspace/common.cljs b/frontend/src/app/main/data/workspace/common.cljs index a9df53834..0cbd9877b 100644 --- a/frontend/src/app/main/data/workspace/common.cljs +++ b/frontend/src/app/main/data/workspace/common.cljs @@ -9,6 +9,7 @@ [app.common.logging :as log] [app.main.data.workspace.changes :as dch] [app.main.data.workspace.undo :as dwu] + [app.util.router :as rt] [beicon.core :as rx] [potok.core :as ptk])) @@ -26,6 +27,25 @@ (defn interrupt? [e] (= e :interrupt)) + +(defn- assure-valid-current-page + [] + (ptk/reify ::assure-valid-current-page + ptk/WatchEvent + (watch [_ state _] + (let [current_page (:current-page-id state) + pages (get-in state [:workspace-data :pages]) + exists? (some #(= current_page %) pages) + + project-id (:current-project-id state) + file-id (:current-file-id state) + pparams {:file-id file-id :project-id project-id} + qparams {:page-id (first pages)}] + (if exists? + (rx/empty) + (rx/of (rt/nav :workspace pparams qparams))))))) + + ;; These functions should've been in `src/app/main/data/workspace/undo.cljs` but doing that causes ;; a circular dependency with `src/app/main/data/workspace/changes.cljs` (def undo @@ -45,7 +65,8 @@ (dch/commit-changes {:redo-changes changes :undo-changes [] :save-undo? false - :origin it})))))))))) + :origin it}) + (assure-valid-current-page)))))))))) (def redo (ptk/reify ::redo