mirror of
https://github.com/penpot/penpot.git
synced 2025-02-14 11:09:04 -05:00
Improved history usability.
This commit is contained in:
parent
e32188f593
commit
71fb8f0a42
4 changed files with 80 additions and 21 deletions
|
@ -135,20 +135,21 @@
|
|||
|
||||
;; --- Select Page History
|
||||
|
||||
(defrecord SelectPageHistory [item]
|
||||
(defrecord SelectPageHistory [version]
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(let [page (get-in state [:pages-by-id (:page item)])
|
||||
page' (assoc page
|
||||
(let [item (get-in state [:workspace :history :by-version version])
|
||||
page (get-in state [:pages-by-id (:page item)])
|
||||
page (assoc page
|
||||
:history true
|
||||
:data (:data item))]
|
||||
(-> state
|
||||
(stpr/unpack-page page')
|
||||
(assoc-in [:workspace :history :selected] (:id item))))))
|
||||
(stpr/unpack-page page)
|
||||
(assoc-in [:workspace :history :selected] version)))))
|
||||
|
||||
(defn select-page-history
|
||||
[item]
|
||||
(SelectPageHistory. item))
|
||||
[version]
|
||||
(SelectPageHistory. version))
|
||||
|
||||
;; --- Apply selected history
|
||||
|
||||
|
@ -234,6 +235,60 @@
|
|||
[item]
|
||||
(UpdateHistoryItem. item))
|
||||
|
||||
;; --- Forward to Next Version
|
||||
|
||||
(defrecord ForwardToNextVersion []
|
||||
rs/WatchEvent
|
||||
(-apply-watch [_ state s]
|
||||
(let [workspace (:workspace state)
|
||||
history (:history workspace)
|
||||
version (:selected history)]
|
||||
(cond
|
||||
(nil? version)
|
||||
(rx/empty)
|
||||
|
||||
(>= (:max-version history) (inc version))
|
||||
(rx/of (select-page-history (inc version)))
|
||||
|
||||
(> (inc version) (:max-version history))
|
||||
(rx/of (discard-selected-history (:page workspace)))
|
||||
|
||||
:else
|
||||
(rx/empty)))))
|
||||
|
||||
(defn forward-to-next-version
|
||||
[]
|
||||
(ForwardToNextVersion.))
|
||||
|
||||
;; --- Backwards to Previous Version
|
||||
|
||||
(defrecord BackwardsToPreviousVersion []
|
||||
rs/WatchEvent
|
||||
(-apply-watch [_ state s]
|
||||
(let [workspace (:workspace state)
|
||||
history (:history workspace)
|
||||
version (:selected history)]
|
||||
(cond
|
||||
(nil? version)
|
||||
(let [maxv (:max-version history)]
|
||||
(rx/of (select-page-history maxv)))
|
||||
|
||||
(pos? (dec version))
|
||||
(if (contains? (:by-version history) (dec version))
|
||||
(rx/of (select-page-history (dec version)))
|
||||
(let [since (:min-version history)
|
||||
page (:page workspace)
|
||||
params {:since since}]
|
||||
(rx/of (fetch-page-history page params)
|
||||
(select-page-history (dec version)))))
|
||||
|
||||
:else
|
||||
(rx/empty)))))
|
||||
|
||||
(defn backwards-to-previous-version
|
||||
[]
|
||||
(BackwardsToPreviousVersion.))
|
||||
|
||||
;; --- Helpers
|
||||
|
||||
(defn- update-history-index
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
[uxbox.router :as r]
|
||||
[uxbox.rstore :as rs]
|
||||
[uxbox.data.workspace :as dw]
|
||||
[uxbox.data.history :as udh]
|
||||
[uxbox.ui.workspace.clipboard]
|
||||
[uxbox.ui.workspace.settings]
|
||||
[uxbox.ui.workspace.base :as wb]
|
||||
|
@ -59,8 +60,9 @@
|
|||
(let [page (rum/react wb/page-l)
|
||||
flags (rum/react wb/flags-l)
|
||||
toggle #(rs/emit! (dw/toggle-flag %))
|
||||
on-undo #(rs/emit! (udh/backwards-to-previous-version))
|
||||
on-redo #(rs/emit! (udh/forward-to-next-version))
|
||||
;; TODO: temporary
|
||||
open-clipboard-dialog #(lightbox/open! :clipboard)
|
||||
open-confirm-dialog #(lightbox/open! :confirm)]
|
||||
(html
|
||||
[:header#workspace-bar.workspace-bar
|
||||
|
@ -100,11 +102,11 @@
|
|||
[:ul.options-btn
|
||||
[:li.tooltip.tooltip-bottom
|
||||
{:alt "Undo (Ctrl + Z)"
|
||||
:on-click open-clipboard-dialog}
|
||||
:on-click on-undo}
|
||||
i/undo]
|
||||
[:li.tooltip.tooltip-bottom
|
||||
{:alt "Redo (Ctrl + Shift + Z)"
|
||||
:on-click open-confirm-dialog}
|
||||
:on-click on-redo}
|
||||
i/redo]]
|
||||
[:ul.options-btn
|
||||
;; TODO: refactor
|
||||
|
@ -115,7 +117,8 @@
|
|||
:href "#" :on-click on-download-clicked}
|
||||
i/export]]
|
||||
[:li.tooltip.tooltip-bottom
|
||||
{:alt "Image (Ctrl + I)"}
|
||||
{:alt "Image (Ctrl + I)"
|
||||
:on-click open-confirm-dialog}
|
||||
i/image]]
|
||||
[:ul.options-btn
|
||||
[:li.tooltip.tooltip-bottom
|
||||
|
|
|
@ -11,7 +11,8 @@
|
|||
[beicon.core :as rx]
|
||||
[uxbox.rstore :as rs]
|
||||
[uxbox.ui.lightbox :as lightbox]
|
||||
[uxbox.data.workspace :as dw])
|
||||
[uxbox.data.workspace :as dw]
|
||||
[uxbox.data.history :as udh])
|
||||
(:import goog.events.EventType
|
||||
goog.events.KeyCodes
|
||||
goog.ui.KeyboardShortcutHandler
|
||||
|
@ -36,6 +37,8 @@
|
|||
:ctrl+d #(rs/emit! (dw/duplicate-selected))
|
||||
:ctrl+c #(rs/emit! (dw/copy-to-clipboard))
|
||||
:ctrl+v #(rs/emit! (dw/paste-from-clipboard))
|
||||
:ctrl+z #(rs/emit! (udh/backwards-to-previous-version))
|
||||
:ctrl+shift+z #(rs/emit! (udh/forward-to-next-version))
|
||||
:ctrl+shift+v #(lightbox/open! :clipboard)
|
||||
:esc #(rs/emit! (dw/deselect-all))
|
||||
:backspace #(rs/emit! (dw/delete-selected))
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
[own item selected]
|
||||
(letfn [(on-select [event]
|
||||
(dom/prevent-default event)
|
||||
(rs/emit! (udh/select-page-history item)))
|
||||
(rs/emit! (udh/select-page-history (:version item))))
|
||||
(on-pinned [event]
|
||||
(dom/prevent-default event)
|
||||
(dom/stop-propagation event)
|
||||
|
@ -46,7 +46,7 @@
|
|||
:label "no label"
|
||||
:pinned (not (:pinned item)))]
|
||||
(rs/emit! (udh/update-history-item item))))]
|
||||
(let [selected? (= (:id item) selected)]
|
||||
(let [selected? (= (:version item) selected)]
|
||||
(html
|
||||
[:li {:class (when selected? "current") :on-click on-select}
|
||||
[:div.pin-icon {:on-click on-pinned
|
||||
|
@ -92,12 +92,10 @@
|
|||
(defn history-list-will-update
|
||||
[own]
|
||||
(let [[page history] (:rum/props own)]
|
||||
(if (:selected history)
|
||||
(let [selected (->> (:items history)
|
||||
(filter #(= (:selected history) (:id %)))
|
||||
(first))]
|
||||
(if-let [version (:selected history)]
|
||||
(let [selected (get-in history [:by-version version])]
|
||||
(msg/dialog
|
||||
:message (tr "history.alert-message" (:version selected))
|
||||
:message (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)))))
|
||||
(msg/close))
|
||||
|
|
Loading…
Add table
Reference in a new issue