From fe6623b34272b254428f1a09a5a3d528de02fb10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Fri, 10 Sep 2021 11:13:48 +0200 Subject: [PATCH] :bug: Fix interactions in viewer --- frontend/src/app/main/data/viewer.cljs | 26 ++++++++++++------- frontend/src/app/main/ui/viewer/handoff.cljs | 3 +-- .../ui/viewer/handoff/attributes/common.cljs | 2 +- .../ui/viewer/handoff/attributes/text.cljs | 2 +- .../src/app/main/ui/viewer/interactions.cljs | 23 ++++++++-------- 5 files changed, 31 insertions(+), 25 deletions(-) diff --git a/frontend/src/app/main/data/viewer.cljs b/frontend/src/app/main/data/viewer.cljs index fde18c31d..c30ed5bf2 100644 --- a/frontend/src/app/main/data/viewer.cljs +++ b/frontend/src/app/main/data/viewer.cljs @@ -305,7 +305,11 @@ (ptk/reify ::go-to-frame ptk/WatchEvent (watch [_ state _] - (let [frames (get-in state [:viewer-data :frames]) + (let [route (:route state) + qparams (:query-params route) + page-id (:page-id qparams) + + frames (get-in state [:viewer :pages page-id :frames]) index (d/index-of-pred frames #(= (:id %) frame-id))] (when index (rx/of (go-to-frame-by-index index))))))) @@ -320,12 +324,6 @@ qparams (:query-params route)] (rx/of (rt/nav :viewer pparams (assoc qparams :section section))))))) -(defn set-current-frame [frame-id] - (ptk/reify ::set-current-frame - ptk/UpdateEvent - (update [_ state] - (assoc-in state [:viewer-data :current-frame-id] frame-id)))) - (defn deselect-all [] (ptk/reify ::deselect-all ptk/UpdateEvent @@ -355,7 +353,10 @@ (ptk/reify ::shift-select-to ptk/UpdateEvent (update [_ state] - (let [objects (get-in state [:viewer-data :objects]) + (let [route (:route state) + qparams (:query-params route) + page-id (:page-id qparams) + objects (get-in state [:viewer :pages page-id :objects]) selection (-> state (get-in [:viewer-local :selected] #{}) (conj id))] @@ -368,8 +369,13 @@ (ptk/reify ::select-all ptk/UpdateEvent (update [_ state] - (let [objects (get-in state [:viewer-data :objects]) - frame-id (get-in state [:viewer-data :current-frame-id]) + (let [route (:route state) + qparams (:query-params route) + page-id (:page-id qparams) + index (:index qparams) + objects (get-in state [:viewer :pages page-id :objects]) + frame-id (get-in state [:viewer :pages page-id :frames index :id]) + selection (->> objects (filter #(= (:frame-id (second %)) frame-id)) (map first) diff --git a/frontend/src/app/main/ui/viewer/handoff.cljs b/frontend/src/app/main/ui/viewer/handoff.cljs index 1fa925678..f3cbeaa7b 100644 --- a/frontend/src/app/main/ui/viewer/handoff.cljs +++ b/frontend/src/app/main/ui/viewer/handoff.cljs @@ -51,8 +51,7 @@ (mf/use-effect (mf/deps (:id frame)) (fn [] - (st/emit! (dv/set-current-frame (:id frame)) - (dv/select-shape (:id frame))))) + (st/emit! (dv/select-shape (:id frame))))) [:* [:& left-sidebar {:frame frame diff --git a/frontend/src/app/main/ui/viewer/handoff/attributes/common.cljs b/frontend/src/app/main/ui/viewer/handoff/attributes/common.cljs index c13617692..c7fa443ed 100644 --- a/frontend/src/app/main/ui/viewer/handoff/attributes/common.cljs +++ b/frontend/src/app/main/ui/viewer/handoff/attributes/common.cljs @@ -19,7 +19,7 @@ (def file-colors-ref - (l/derived (l/in [:viewer-data :file :colors]) st/state)) + (l/derived (l/in [:viewer :file :data :colors]) st/state)) (defn make-colors-library-ref [file-id] (let [get-library diff --git a/frontend/src/app/main/ui/viewer/handoff/attributes/text.cljs b/frontend/src/app/main/ui/viewer/handoff/attributes/text.cljs index 9ed9c189d..e760b668f 100644 --- a/frontend/src/app/main/ui/viewer/handoff/attributes/text.cljs +++ b/frontend/src/app/main/ui/viewer/handoff/attributes/text.cljs @@ -22,7 +22,7 @@ (:content shape)) (def file-typographies-ref - (l/derived (l/in [:viewer-data :file :typographies]) st/state)) + (l/derived (l/in [:viewer :file :data :typographies]) st/state)) (defn make-typographies-library-ref [file-id] (let [get-library diff --git a/frontend/src/app/main/ui/viewer/interactions.cljs b/frontend/src/app/main/ui/viewer/interactions.cljs index d5eeb6379..15846eca9 100644 --- a/frontend/src/app/main/ui/viewer/interactions.cljs +++ b/frontend/src/app/main/ui/viewer/interactions.cljs @@ -49,7 +49,7 @@ (prepare-objects page frame)) wrapper (mf/use-memo - (mf/deps objects) + (mf/deps objects interactions?) #(shapes/frame-container-factory objects interactions?)) ;; Retrieve frame again with correct modifier @@ -77,16 +77,17 @@ (st/emit! (dcm/close-thread))))] (mf/use-effect - (fn [] - ;; bind with passive=false to allow the event to be cancelled - ;; https://stackoverflow.com/a/57582286/3219895 - (let [key1 (events/listen goog/global "wheel" on-mouse-wheel #js {"passive" false}) - key2 (events/listen js/window "keydown" on-key-down) - key3 (events/listen js/window "click" on-click)] - (fn [] - (events/unlistenByKey key1) - (events/unlistenByKey key2) - (events/unlistenByKey key3))))) + (mf/deps local) ;; on-click event depends on local + (fn [] + ;; bind with passive=false to allow the event to be cancelled + ;; https://stackoverflow.com/a/57582286/3219895 + (let [key1 (events/listen goog/global "wheel" on-mouse-wheel #js {"passive" false}) + key2 (events/listen js/window "keydown" on-key-down) + key3 (events/listen js/window "click" on-click)] + (fn [] + (events/unlistenByKey key1) + (events/unlistenByKey key2) + (events/unlistenByKey key3))))) [:svg {:view-box (:vbox size) :width (:width size)