From 904664319a6097ae16c3b6463a81a729fb0aaee5 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 8 Jan 2020 19:18:43 +0100 Subject: [PATCH] :sparkles: Adapt zoom widget to new state layout. --- frontend/src/uxbox/main/data/workspace.cljs | 51 ++++++++----------- .../src/uxbox/main/ui/workspace/header.cljs | 13 ++--- 2 files changed, 28 insertions(+), 36 deletions(-) diff --git a/frontend/src/uxbox/main/data/workspace.cljs b/frontend/src/uxbox/main/data/workspace.cljs index 3b38cc8d7..9d4b75fdd 100644 --- a/frontend/src/uxbox/main/data/workspace.cljs +++ b/frontend/src/uxbox/main/data/workspace.cljs @@ -527,38 +527,29 @@ ;; --- Zoom Management -(defrecord IncreaseZoom [] - ptk/UpdateEvent - (update [_ state] - (let [increase #(nth c/zoom-levels - (+ (index-of c/zoom-levels %) 1) - (last c/zoom-levels))] - (update-in state [:workspace :zoom] (fnil increase 1))))) +(def increase-zoom + (ptk/reify ::increase-zoom + ptk/UpdateEvent + (update [_ state] + (let [increase #(nth c/zoom-levels + (+ (index-of c/zoom-levels %) 1) + (last c/zoom-levels))] + (update-in state [:workspace-local :zoom] (fnil increase 1)))))) -(defn increase-zoom - [] - (IncreaseZoom.)) +(def decrease-zoom + (ptk/reify ::decrease-zoom + ptk/UpdateEvent + (update [_ state] + (let [decrease #(nth c/zoom-levels + (- (index-of c/zoom-levels %) 1) + (first c/zoom-levels))] + (update-in state [:workspace-local :zoom] (fnil decrease 1)))))) -(defrecord DecreaseZoom [] - ptk/UpdateEvent - (update [_ state] - (let [decrease #(nth c/zoom-levels - (- (index-of c/zoom-levels %) 1) - (first c/zoom-levels))] - (update-in state [:workspace :zoom] (fnil decrease 1))))) - -(defn decrease-zoom - [] - (DecreaseZoom.)) - -(defrecord ResetZoom [] - ptk/UpdateEvent - (update [_ state] - (assoc-in state [:workspace :zoom] 1))) - -(defn reset-zoom - [] - (ResetZoom.)) +(def reset-zoom + (ptk/reify ::reset-zoom + ptk/UpdateEvent + (update [_ state] + (assoc-in state [:workspace-local :zoom] 1)))) ;; --- Grid Alignment diff --git a/frontend/src/uxbox/main/ui/workspace/header.cljs b/frontend/src/uxbox/main/ui/workspace/header.cljs index 579a7e997..80355e048 100644 --- a/frontend/src/uxbox/main/ui/workspace/header.cljs +++ b/frontend/src/uxbox/main/ui/workspace/header.cljs @@ -26,10 +26,11 @@ ;; --- Zoom Widget (mf/defc zoom-widget + {:wrap [mf/wrap-memo]} [props] (let [zoom (mf/deref refs/selected-zoom) - increase #(st/emit! (dw/increase-zoom)) - decrease #(st/emit! (dw/decrease-zoom))] + increase #(st/emit! dw/increase-zoom) + decrease #(st/emit! dw/decrease-zoom)] [:ul.options-view [:li.zoom-input [:span.add-zoom {:on-click decrease} "-"] @@ -180,10 +181,10 @@ ;; i/alignment]] ;; [:& user] [:div.secondary-options - [:& zoom-widget] - [:a.tooltip.tooltip-bottom.view-mode + [:& zoom-widget] + [:a.tooltip.tooltip-bottom.view-mode {:alt (tr "workspace.header.view-mode") - ;; :on-click #(st/emit! (dw/->OpenView (:id page))) - } + ;; :on-click #(st/emit! (dw/->OpenView (:id page))) + } i/play]] ]))