From d8cb4669e5b06799edd1366c1fdf73d90967cb8d Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Sun, 27 Mar 2016 18:45:58 +0300 Subject: [PATCH] Improved history deselection. --- src/uxbox/data/pages.cljs | 36 +++++++++++++-------- src/uxbox/ui/workspace/sidebar/history.cljs | 3 +- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/uxbox/data/pages.cljs b/src/uxbox/data/pages.cljs index b5d5c08ef9..7fbe6b68c9 100644 --- a/src/uxbox/data/pages.cljs +++ b/src/uxbox/data/pages.cljs @@ -213,22 +213,30 @@ ;; --- Select Page History -(defrecord SelectPageHistory [page history] +;; TODO: seems like it is inefficient packing the current +;; page every time, but a this moment it works. Maybe in +;; future it will need some refactor. + +(defrecord SelectPageHistory [id history] rs/UpdateEvent (-apply-update [_ state] - (let [page (get-in state [:pages-by-id page]) - page' (assoc page - :history true - :data (:data history) - :version (:version history))] - (-> state - (stpr/unpack-page page') - (assoc-in [:workspace :history :selected] (:id history)) - (update-in [:workspace :history] - (fn [v] - (if (:current-version v) - v - (assoc v :current-version (:version page))))))))) + (if (nil? history) + (let [packed (get-in state [:workspace :history :current])] + (-> state + (stpr/unpack-page packed) + (assoc-in [:workspace :history :selected] nil) + (assoc-in [:workspace :history :current] nil))) + + (let [packed (stpr/pack-page state id) + page (get-in state [:pages-by-id id]) + page' (assoc page + :history true + :data (:data history) + :version (:version history))] + (-> state + (stpr/unpack-page page') + (assoc-in [:workspace :history :selected] (:id history)) + (update-in [:workspace :history :current] (fnil identity packed))))))) (defn select-page-history [id history] diff --git a/src/uxbox/ui/workspace/sidebar/history.cljs b/src/uxbox/ui/workspace/sidebar/history.cljs index b4c0ae764a..7d8dba8102 100644 --- a/src/uxbox/ui/workspace/sidebar/history.cljs +++ b/src/uxbox/ui/workspace/sidebar/history.cljs @@ -57,7 +57,8 @@ (let [select #(rs/emit! (dpg/select-page-history (:id page) %))] (html [:ul.history-content - [:li {:class (when-not (:selected history) "current")} + [:li {:class (when-not (:selected history) "current") + :on-click (partial select nil)} [:div.pin-icon i/pin] [:span (str "Version " (:version page) " (current)")]] (for [item (:items history)]