mirror of
https://github.com/penpot/penpot.git
synced 2025-02-24 07:46:13 -05:00
🐛 Fix delete page with components
This commit is contained in:
parent
a1c09057c1
commit
65c695e830
3 changed files with 30 additions and 6 deletions
|
@ -478,18 +478,40 @@
|
|||
(declare purge-page)
|
||||
(declare go-to-file)
|
||||
|
||||
(defn- delete-page-components
|
||||
[changes page]
|
||||
(let [components-to-delete (->> page
|
||||
:objects
|
||||
vals
|
||||
(filter #(true? (:main-instance? %)))
|
||||
(map :component-id))
|
||||
|
||||
changes (reduce (fn [changes component-id]
|
||||
(pcb/delete-component changes component-id))
|
||||
changes
|
||||
components-to-delete)]
|
||||
changes))
|
||||
|
||||
(defn delete-page
|
||||
[id]
|
||||
(ptk/reify ::delete-page
|
||||
ptk/WatchEvent
|
||||
(watch [it state _]
|
||||
(let [pages (get-in state [:workspace-data :pages])
|
||||
(let [components-v2 (features/active-feature? state :components-v2)
|
||||
file-id (:current-file-id state)
|
||||
file (wsh/get-file state file-id)
|
||||
pages (get-in state [:workspace-data :pages])
|
||||
index (d/index-of pages id)
|
||||
page (get-in state [:workspace-data :pages-index id])
|
||||
page (assoc page :index index)
|
||||
|
||||
changes (-> (pcb/empty-changes it)
|
||||
(pcb/del-page page))]
|
||||
changes (cond-> (pcb/empty-changes it)
|
||||
components-v2
|
||||
(pcb/with-library-data file)
|
||||
components-v2
|
||||
(delete-page-components page)
|
||||
:always
|
||||
(pcb/del-page page))]
|
||||
|
||||
(rx/of (dch/commit-changes changes)
|
||||
(when (= id (:current-page-id state))
|
||||
|
|
|
@ -435,9 +435,10 @@
|
|||
ptk/WatchEvent
|
||||
(watch [it state _]
|
||||
(let [page-id (:current-page-id state)
|
||||
current-page (dm/get-in state [:workspace-data :pages-index page-id])
|
||||
objects (wsh/lookup-page-objects state page-id)
|
||||
library-data (wsh/get-file state library-id)
|
||||
{:keys [changes shape]} (dwlh/prepare-restore-component library-data component-id it)
|
||||
{:keys [changes shape]} (dwlh/prepare-restore-component library-data component-id current-page it)
|
||||
parent-id (:parent-id shape)
|
||||
objects (cond-> (assoc objects (:id shape) shape)
|
||||
(not (nil? parent-id))
|
||||
|
|
|
@ -213,9 +213,10 @@
|
|||
children-ids)))))
|
||||
|
||||
(defn prepare-restore-component
|
||||
([library-data component-id it]
|
||||
([library-data component-id current-page it]
|
||||
(let [component (ctkl/get-deleted-component library-data component-id)
|
||||
page (ctf/get-component-page library-data component)]
|
||||
page (or (ctf/get-component-page library-data component)
|
||||
current-page)]
|
||||
(prepare-restore-component nil library-data component-id it page (gpt/point 0 0) nil nil)))
|
||||
|
||||
([changes library-data component-id it page delta old-id parent-id]
|
||||
|
|
Loading…
Add table
Reference in a new issue