From 3983cb161e592cb297a2a0f0e6411e2d45e7f7d1 Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Wed, 22 Nov 2023 16:18:04 +0100 Subject: [PATCH] :bug: Fix swap panel keeps open after undo --- .../app/main/data/workspace/selection.cljs | 37 +++++++++++-------- .../data/workspace/specialized_panel.cljs | 31 +++++++--------- .../app/main/data/workspace/transforms.cljs | 2 +- .../sidebar/options/menus/component.cljs | 4 +- .../main/ui/workspace/viewport/actions.cljs | 4 +- 5 files changed, 41 insertions(+), 37 deletions(-) diff --git a/frontend/src/app/main/data/workspace/selection.cljs b/frontend/src/app/main/data/workspace/selection.cljs index ee774bbd8..132b9377f 100644 --- a/frontend/src/app/main/data/workspace/selection.cljs +++ b/frontend/src/app/main/data/workspace/selection.cljs @@ -27,6 +27,7 @@ [app.main.data.workspace.changes :as dch] [app.main.data.workspace.collapse :as dwc] [app.main.data.workspace.libraries-helpers :as dwlh] + [app.main.data.workspace.specialized-panel :as-alias dwsp] [app.main.data.workspace.state-helpers :as wsh] [app.main.data.workspace.undo :as dwu] [app.main.data.workspace.zoom :as dwz] @@ -124,14 +125,15 @@ (update [_ state] (-> state (update-in [:workspace-local :selected] d/toggle-selection id toggle?) - (assoc-in [:workspace-local :last-selected] id) - (dissoc :specialized-panel))) + (assoc-in [:workspace-local :last-selected] id))) ptk/WatchEvent (watch [_ state _] (let [page-id (:current-page-id state) objects (wsh/lookup-page-objects state page-id)] - (rx/of (dwc/expand-all-parents [id] objects))))))) + (rx/of + (dwc/expand-all-parents [id] objects) + ::dwsp/interrupt)))))) (defn select-prev-shape ([] @@ -186,12 +188,14 @@ [id] (dm/assert! (uuid? id)) (ptk/reify ::deselect-shape + ptk/WatchEvent + (watch [_ _ _] + (rx/of ::dwsp/interrupt)) ptk/UpdateEvent (update [_ state] (-> state (update-in [:workspace-local :selected] disj id) - (update :workspace-local dissoc :last-selected) - (dissoc :specialized-panel))))) + (update :workspace-local dissoc :last-selected))))) (defn shift-select-shapes ([id] @@ -199,6 +203,9 @@ ([id objects] (ptk/reify ::shift-select-shapes + ptk/WatchEvent + (watch [_ _ _] + (rx/of ::dwsp/interrupt)) ptk/UpdateEvent (update [_ state] (let [objects (or objects (wsh/lookup-page-objects state)) @@ -208,9 +215,8 @@ (conj id))] (-> state (assoc-in [:workspace-local :selected] - (set/union selection append-to-selection)) - (update :workspace-local assoc :last-selected id) - (dissoc :specialized-panel))))))) + (set/union selection append-to-selection)) + (update :workspace-local assoc :last-selected id))))))) (defn select-shapes [ids] @@ -227,14 +233,14 @@ ids (if (d/not-empty? focus) (cpf/filter-not-focus objects focus ids) ids)] - (-> state - (assoc-in [:workspace-local :selected] ids) - (dissoc :specialized-panel)))) + (assoc-in state [:workspace-local :selected] ids))) ptk/WatchEvent (watch [_ state _] (let [objects (wsh/lookup-page-objects state)] - (rx/of (dwc/expand-all-parents ids objects)))))) + (rx/of + (dwc/expand-all-parents ids objects) + ::dwsp/interrupt))))) (defn select-all [] @@ -273,6 +279,9 @@ ([check-modal] (ptk/reify ::deselect-all + ptk/WatchEvent + (watch [_ _ _] + (rx/of ::dwsp/interrupt)) ptk/UpdateEvent (update [_ state] @@ -283,9 +292,7 @@ (update :workspace-local #(-> % (assoc :selected (d/ordered-set)) - (dissoc :selected-frame))) - :allways - (dissoc :specialized-panel)))))) + (dissoc :selected-frame)))))))) ;; --- Select Shapes (By selrect) diff --git a/frontend/src/app/main/data/workspace/specialized_panel.cljs b/frontend/src/app/main/data/workspace/specialized_panel.cljs index 880aa659b..467c67077 100644 --- a/frontend/src/app/main/data/workspace/specialized_panel.cljs +++ b/frontend/src/app/main/data/workspace/specialized_panel.cljs @@ -7,38 +7,35 @@ (ns app.main.data.workspace.specialized-panel (:require [app.common.data :as d] + [app.main.data.workspace.common :as-alias dwc] [app.main.data.workspace.state-helpers :as wsh] [beicon.core :as rx] [potok.core :as ptk])) -(defn interrupt? [e] (= e :interrupt)) +(defn interrupt? [e] (or (= e :interrupt) (= e ::interrupt))) -(def clear-specialized-panel +(defn clear-specialized-panel + [] (ptk/reify ::clear-specialized-panel ptk/UpdateEvent (update [_ state] (dissoc state :specialized-panel)))) + (defn open-specialized-panel - ([type] - (ptk/reify ::open-specialized-panel-1 - ptk/WatchEvent - (watch [_ state _] + [type] + (ptk/reify ::open-specialized-panel + ptk/UpdateEvent + (update [_ state] (let [page-id (:current-page-id state) objects (wsh/lookup-page-objects state page-id) selected-ids (wsh/lookup-selected state) selected-shapes (map (d/getf objects) selected-ids)] - - (rx/of (open-specialized-panel type selected-shapes)))))) - - ([type shapes] - (ptk/reify ::open-specialized-panel-2 - ptk/UpdateEvent - (update [_ state] - (assoc state :specialized-panel {:type type :shapes shapes})) + (assoc state :specialized-panel {:type type :shapes selected-shapes}))) ptk/WatchEvent (watch [_ _ stream] - (->> stream - (rx/filter interrupt?) + (->> (rx/merge + (rx/filter interrupt? stream) + (rx/filter (ptk/type? ::dwc/undo) stream)) (rx/take 1) - (rx/map (constantly clear-specialized-panel))))))) + (rx/map clear-specialized-panel))))) diff --git a/frontend/src/app/main/data/workspace/transforms.cljs b/frontend/src/app/main/data/workspace/transforms.cljs index 0e286a7e6..57a971c4d 100644 --- a/frontend/src/app/main/data/workspace/transforms.cljs +++ b/frontend/src/app/main/data/workspace/transforms.cljs @@ -840,7 +840,7 @@ ;; Remove layout-item properties when moving a shape outside a layout (cond-> (not (ctl/any-layout? objects frame-id)) (pcb/update-shapes moving-shapes-ids ctl/remove-layout-item-data)) - ;; Remove componnet-root property when moving a shape inside a component + ;; Remove component-root property when moving a shape inside a component (cond-> (ctn/get-instance-root objects frame) (pcb/update-shapes moving-shapes-ids #(dissoc % :component-root))) (pcb/update-shapes moving-shapes-ids #(cond-> % (cfh/frame-shape? %) (assoc :hide-in-viewer true))) diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs index 567423888..01dcbc9a4 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs @@ -442,12 +442,12 @@ on-component-back (mf/use-fn - #(st/emit! :interrupt)) + #(st/emit! ::dwsp/interrupt)) open-component-panel (mf/use-fn (mf/deps can-swap? shapes) - #(when can-swap? (st/emit! (dwsp/open-specialized-panel :component-swap shapes)))) + #(when can-swap? (st/emit! (dwsp/open-specialized-panel :component-swap)))) menu-entries (cmm/generate-components-menu-entries shapes components-v2) show-menu? (seq menu-entries)] diff --git a/frontend/src/app/main/ui/workspace/viewport/actions.cljs b/frontend/src/app/main/ui/workspace/viewport/actions.cljs index da80a402b..2be3f84e8 100644 --- a/frontend/src/app/main/ui/workspace/viewport/actions.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/actions.cljs @@ -18,7 +18,7 @@ [app.main.data.workspace.libraries :as dwl] [app.main.data.workspace.media :as dwm] [app.main.data.workspace.path :as dwdp] - [app.main.data.workspace.specialized-panel :as dwsp] + [app.main.data.workspace.specialized-panel :as-alias dwsp] [app.main.refs :as refs] [app.main.store :as st] [app.main.streams :as ms] @@ -86,7 +86,7 @@ left-click? (do (st/emit! (ms/->MouseEvent :down ctrl? shift? alt? meta?) - dwsp/clear-specialized-panel) + ::dwsp/interrupt) (when (and (not= edition id) (or text-editing? grid-editing?)) (st/emit! dw/clear-edition-mode))