0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-24 15:39:50 -05:00

Integreate new history version dialog in workspace.

This commit is contained in:
Andrey Antukh 2016-04-16 20:42:41 +03:00
parent 8d2767999b
commit 39df77e6ed
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
3 changed files with 49 additions and 31 deletions

View file

@ -159,19 +159,24 @@
[id]
(ApplySelectedHistory. id))
;; --- Discard Selected History
;; --- Deselect Page History
(defrecord DiscardSelectedHistory [id]
(defrecord DeselectPageHistory [id]
rs/UpdateEvent
(-apply-update [_ state]
(let [packed (get-in state [:pagedata-by-id id])]
(-> state
(stpr/unpack-page packed)
(assoc-in [:workspace :history :selected] nil)))))
(-> (stpr/unpack-page state packed)
(assoc-in [:workspace :history :deselecting] true)
(assoc-in [:workspace :history :selected] nil))))
(defn discard-selected-history
rs/WatchEvent
(-apply-watch [_ state s]
(->> (rx/of #(assoc-in % [:workspace :history :deselecting] false))
(rx/delay 500))))
(defn deselect-page-history
[id]
(DiscardSelectedHistory. id))
(DeselectPageHistory. id))
;; --- History Item Updated
@ -238,7 +243,7 @@
(rx/of (select-page-history (inc version)))
(> (inc version) (:max-version history))
(rx/of (discard-selected-history (:page workspace)))
(rx/of (deselect-page-history (:page workspace)))
:else
(rx/empty)))))

View file

@ -26,6 +26,7 @@
[uxbox.ui.workspace.shortcuts :refer (shortcuts-mixin)]
[uxbox.ui.workspace.header :refer (header)]
[uxbox.ui.workspace.rules :refer (horizontal-rule vertical-rule)]
[uxbox.ui.workspace.sidebar.history :refer (history-dialog)]
[uxbox.ui.workspace.sidebar :refer (left-sidebar right-sidebar)]
[uxbox.ui.workspace.colorpalette :refer (colorpalette)]
[uxbox.ui.workspace.canvas :refer (viewport)]))
@ -99,7 +100,7 @@
(defn- workspace-render
[own projectid]
(let [{:keys [flags zoom] :as workspace} (rum/react wb/workspace-l)
(let [{:keys [flags zoom page] :as workspace} (rum/react wb/workspace-l)
left-sidebar? (not (empty? (keep flags [:layers :sitemap
:document-history])))
right-sidebar? (not (empty? (keep flags [:icons :drawtools
@ -122,13 +123,8 @@
:on-scroll on-scroll
:on-wheel (partial on-wheel own)}
;; WIP message version
#_[:div.message-version
[:span "Continue working with version 22?"]
[:div.message-action
[:a.btn-transparent "Accept"]
[:a.btn-transparent "Cancel"]
]]
(history-dialog page)
;; Rules
(horizontal-rule zoom)

View file

@ -32,7 +32,7 @@
(as-> (l/in [:workspace :history]) $
(l/focus-atom $ st/state)))
;; --- Components
;; --- History Item (Component)
(defn history-item-render
[own item selected]
@ -61,11 +61,13 @@
:name "history-item"
:mixins [mx/static]}))
;; --- History List (Component)
(defn history-list-render
[own page history]
(letfn [(on-select [event]
(dom/prevent-default event)
(rs/emit! (udh/discard-selected-history (:id page))))
(rs/emit! (udh/deselect-page-history (:id page))))
(on-load-more [event]
(dom/prevent-default event)
@ -90,25 +92,14 @@
[:a.btn-primary.btn-small
"view more"]])]))))
(defn history-list-will-update
[own]
(let [[page history] (:rum/props own)]
(if-let [version (:selected history)]
(let [selected (get-in history [:by-version version])]
(udm/dialog!
(tr "history.alert-message" version)
:on-accept #(rs/emit! (udh/apply-selected-history (:id page)))
:on-cancel #(rs/emit! (udh/discard-selected-history (:id page)))))
(udm/close!))
own))
(def history-list
(mx/component
{:render history-list-render
:will-update history-list-will-update
:name "history-list"
:mixins [mx/static]}))
;; --- History Pinned List (Component)
(defn history-pinned-list-render
[own history]
(html
@ -124,6 +115,8 @@
:name "history-pinned-list"
:mixins [mx/static]}))
;; --- History Toolbox (Component)
(defn history-toolbox-render
[own]
(let [local (:rum/local own)
@ -158,3 +151,27 @@
{:render history-toolbox-render
:name "document-history-toolbox"
:mixins [mx/static rum/reactive (mx/local)]}))
;; --- History Dialog
(defn history-dialog-render
[own page]
(let [history (rum/react history-l)
version (:selected history)
on-accept #(rs/emit! (udh/apply-selected-history page))
on-cancel #(rs/emit! (udh/deselect-page-history page))]
(when (or version (:deselecting history))
(html
[:div.message-version
{:class (when (:deselecting history) "hide-message")}
[:span (tr "history.alert-message" (or version "00"))
[:div.message-action
[:a.btn-transparent {:on-click on-accept} "Accept"]
[:a.btn-transparent {:on-click on-cancel} "Cancel"]]]]))))
(def history-dialog
(mx/component
{:render history-dialog-render
:name "history-dialog"
:mixins [mx/static rum/reactive]}))