diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 519669971..69203edeb 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -65,6 +65,7 @@ [beicon.core :as rx] [cljs.spec.alpha :as s] [cuerdas.core :as str] + [linked.core :as lks] [potok.core :as ptk])) (s/def ::shape-attrs ::cts/shape-attrs) @@ -961,7 +962,6 @@ :graphics #{} :colors #{} :typographies #{}})))) - (defn go-to-component [component-id] (ptk/reify ::go-to-component @@ -984,6 +984,31 @@ (let [wrapper-id (str "component-shape-id-" component-id)] (tm/schedule-on-idle #(dom/scroll-into-view-if-needed! (dom/get-element wrapper-id))))))) +(defn go-to-main-instance + [page-id shape-id on-page-selected] + (us/verify ::us/uuid page-id) + (us/verify ::us/uuid shape-id) + (ptk/reify ::go-to-main-instance + ptk/WatchEvent + (watch [_ state stream] + (let [current-page-id (:current-page-id state)] + (if (= page-id current-page-id) + (do + (on-page-selected) + (rx/of (dws/select-shapes (lks/set shape-id)))) + (let [project-id (:current-project-id state) + file-id (:current-file-id state) + pparams {:file-id file-id :project-id project-id} + qparams {:page-id page-id :layout :assets}] + (rx/merge + (rx/of (rt/nav :workspace pparams qparams)) + (->> stream + (rx/filter (ptk/type? ::dwv/initialize-viewport)) + (rx/take 1) + (rx/mapcat #(do + (on-page-selected) + (rx/of (dws/select-shapes (lks/set shape-id))))))))))))) + (def go-to-file (ptk/reify ::go-to-file ptk/WatchEvent diff --git a/frontend/src/app/main/ui/workspace/sidebar/assets.cljs b/frontend/src/app/main/ui/workspace/sidebar/assets.cljs index e80065095..cbb4b3674 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/assets.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/assets.cljs @@ -370,6 +370,24 @@ dragging? (mf/use-state false) + unselect-all + (mf/use-callback + (fn [] + (st/emit! (dw/unselect-all-assets)))) + + on-component-click + (mf/use-callback + (mf/deps component selected-components) + (fn [event] + (dom/stop-propagation event) + (let [main-instance-id (:main-instance-id component) + main-instance-page (:main-instance-page component)] + (if (and main-instance-id main-instance-page) + (st/emit! (dw/go-to-main-instance main-instance-page main-instance-id + #(on-asset-click event (:id component) unselect-all))) + ;; This may occur when :components-v2 is disabled + (on-asset-click event (:id component) unselect-all))))) + on-drop (mf/use-callback (mf/deps component dragging? selected-components selected-components-full selected-components-paths) @@ -405,7 +423,7 @@ :enum-item (not @listing-thumbs?)) :id (str "component-shape-id-" (:id component)) :draggable true - :on-click #(on-asset-click % (:id component) nil) + :on-click on-component-click :on-context-menu (on-context-menu (:id component)) :on-drag-start on-component-drag-start :on-drag-enter on-drag-enter @@ -1973,7 +1991,7 @@ on-asset-click (mf/use-callback - (mf/deps extend-selected-assets selected-assets) + (mf/deps selected-assets) (fn [asset-type asset-groups event asset-id default-click] (cond (kbd/mod? event)