mirror of
https://github.com/penpot/penpot.git
synced 2025-07-23 22:27:16 +02:00
🔧 Refactor page actions to use changes-builder
This commit is contained in:
parent
e139cba621
commit
96870c3fee
2 changed files with 74 additions and 44 deletions
|
@ -320,14 +320,10 @@
|
|||
unames (dwc/retrieve-used-names pages)
|
||||
name (dwc/generate-unique-name unames "Page-1")
|
||||
|
||||
rchange {:type :add-page
|
||||
:id id
|
||||
:name name}
|
||||
uchange {:type :del-page
|
||||
:id id}]
|
||||
(rx/of (dch/commit-changes {:redo-changes [rchange]
|
||||
:undo-changes [uchange]
|
||||
:origin it})))))))
|
||||
changes (-> (pcb/empty-changes it)
|
||||
(pcb/add-empty-page id name))]
|
||||
|
||||
(rx/of (dch/commit-changes changes)))))))
|
||||
|
||||
(defn duplicate-page
|
||||
[page-id]
|
||||
|
@ -342,13 +338,10 @@
|
|||
|
||||
page (-> page (assoc :name name :id id))
|
||||
|
||||
rchange {:type :add-page
|
||||
:page page}
|
||||
uchange {:type :del-page
|
||||
:id id}]
|
||||
(rx/of (dch/commit-changes {:redo-changes [rchange]
|
||||
:undo-changes [uchange]
|
||||
:origin it}))))))
|
||||
changes (-> (pcb/empty-changes it)
|
||||
(pcb/add-page id page))]
|
||||
|
||||
(rx/of (dch/commit-changes changes))))))
|
||||
|
||||
(s/def ::rename-page
|
||||
(s/keys :req-un [::id ::name]))
|
||||
|
@ -360,33 +353,26 @@
|
|||
(ptk/reify ::rename-page
|
||||
ptk/WatchEvent
|
||||
(watch [it state _]
|
||||
(let [page (get-in state [:workspace-data :pages-index id])
|
||||
rchg {:type :mod-page
|
||||
:id id
|
||||
:name name}
|
||||
uchg {:type :mod-page
|
||||
:id id
|
||||
:name (:name page)}]
|
||||
(rx/of (dch/commit-changes {:redo-changes [rchg]
|
||||
:undo-changes [uchg]
|
||||
:origin it}))))))
|
||||
(let [page (get-in state [:workspace-data :pages-index id])
|
||||
changes (-> (pcb/empty-changes it)
|
||||
(pcb/mod-page page name))]
|
||||
|
||||
(rx/of (dch/commit-changes changes))))))
|
||||
|
||||
(declare purge-page)
|
||||
(declare go-to-file)
|
||||
|
||||
;; TODO: for some reason, the page-id here in some circumstances is `nil`
|
||||
(defn delete-page
|
||||
[id]
|
||||
(ptk/reify ::delete-page
|
||||
ptk/WatchEvent
|
||||
(watch [it state _]
|
||||
(let [page (get-in state [:workspace-data :pages-index id])
|
||||
rchg {:type :del-page :id id}
|
||||
uchg {:type :add-page :page page}]
|
||||
|
||||
(rx/of (dch/commit-changes {:redo-changes [rchg]
|
||||
:undo-changes [uchg]
|
||||
:origin it})
|
||||
changes (-> (pcb/empty-changes it)
|
||||
(pcb/del-page page))]
|
||||
|
||||
(rx/of (dch/commit-changes changes)
|
||||
(when (= id (:current-page-id state))
|
||||
go-to-file))))))
|
||||
|
||||
|
@ -1962,19 +1948,12 @@
|
|||
(ptk/reify ::change-canvas-color
|
||||
ptk/WatchEvent
|
||||
(watch [it state _]
|
||||
(let [page-id (get state :current-page-id)
|
||||
options (wsh/lookup-page-options state page-id)
|
||||
previous-color (:background options)]
|
||||
(rx/of (dch/commit-changes
|
||||
{:redo-changes [{:type :set-option
|
||||
:page-id page-id
|
||||
:option :background
|
||||
:value (:color color)}]
|
||||
:undo-changes [{:type :set-option
|
||||
:page-id page-id
|
||||
:option :background
|
||||
:value previous-color}]
|
||||
:origin it}))))))
|
||||
(let [page (wsh/lookup-page state)
|
||||
changes (-> (pcb/empty-changes it)
|
||||
(pcb/with-page page)
|
||||
(pcb/set-page-option :background (:color color)))]
|
||||
|
||||
(rx/of (dch/commit-changes changes))))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Artboard
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue