0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-14 11:09:04 -05:00

Adapt page creation to model changes.

This commit is contained in:
Andrey Antukh 2019-12-10 22:04:31 +01:00
parent 9bb5be306f
commit 433d8cee9a
3 changed files with 19 additions and 18 deletions

View file

@ -172,30 +172,32 @@
;; --- Create Page
(declare page-created)
(s/def ::create-page
(s/keys :req-un [::name ::file-id]))
(defn create-page
[{:keys [project-id name] :as data}]
[{:keys [file-id name] :as data}]
(s/assert ::create-page data)
(ptk/reify ::create-page
ptk/WatchEvent
(watch [this state s]
#_(let [ordering (count (get-in state [:projects project-id :pages]))
(let [ordering (count (get-in state [:files file-id :pages]))
params {:name name
:project-id project-id
:file-id file-id
:ordering ordering
:data {:shapes []
:canvas []
:shapes-by-id {}}
:metadata {}}]
(->> (rp/mutation :create-page params)
(->> (rp/mutation :create-project-page params)
(rx/map page-created))))))
;; --- Page Created
(defn page-created
[{:keys [id project-id] :as page}]
[{:keys [id file-id] :as page}]
(s/assert ::page page)
(ptk/reify ::page-created
cljs.core/IDeref
@ -206,8 +208,13 @@
(let [data (:data page)
page (dissoc page :data)]
(-> state
(update-in [:workspace-file :pages] (fnil conj []) id)
(update :pages assoc id page)
(update :pages-data assoc id data))))))
(update :pages-data assoc id data))))
ptk/WatchEvent
(watch [_ state stream]
(rx/of (uxbox.main.data.projects/fetch-file file-id)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Workspace-Aware Page Events
@ -249,7 +256,7 @@
(if (:history local)
(rx/empty)
(let [page (assoc page :data data)]
(->> (rp/mutation :update-page page)
(->> (rp/mutation :update-project-page-data page)
(rx/map (fn [res] (merge page res)))
(rx/map page-persisted)
(rx/catch (fn [err] (rx/of ::page-persist-error))))))))))

View file

@ -152,7 +152,6 @@
ptk/WatchEvent
(watch [_ state stream]
(prn "initialize" file-id page-id)
#_(when-not (get-in state [:pages page-id])
(reset! st/loader true))
@ -172,7 +171,6 @@
(rx/mapcat #(rx/of (initialized file-id page-id)
#_(initialize-alignment page-id))))
;; When workspace is initialized, run the event watchers.
(->> (rx/filter (ptk/type? ::initialized) stream)
(rx/take 1)
@ -193,7 +191,6 @@
(let [file (get-in state [:files file-id])
page (get-in state [:pages page-id])
data (get-in state [:pages-data page-id])]
(prn "initialized" file)
(assoc state
:workspace-file file
:workspace-data data
@ -1206,11 +1203,8 @@
(->> stream
(rx/filter udp/page-update?)
(rx/debounce 500)
(rx/mapcat #(rx/merge (rx/of rehash-shapes-relationships udp/persist-current-page)
(->> (rx/filter (ptk/type? ::udp/page-persisted) stream)
(rx/timeout 1000 (rx/empty))
(rx/take 1)
(rx/ignore))))
(rx/mapcat #(rx/of rehash-shapes-relationships
udp/persist-current-page))
(rx/take-until stopper))))))
;; (def watch-shapes-changes

View file

@ -21,11 +21,11 @@
[uxbox.util.i18n :refer [tr]]))
(s/def ::id ::us/uuid)
(s/def ::project-id ::us/uuid)
(s/def ::file-id ::us/uuid)
(s/def ::name ::us/not-empty-string)
(s/def ::page-form
(s/keys :req-un [::project-id ::name]
(s/keys :req-un [::file-id ::name]
:opt-un [::id]))
(defn- on-submit
@ -40,7 +40,7 @@
(defn- initial-data
[page]
(merge {:name ""}
(select-keys page [:name :id :project-id])))
(select-keys page [:name :id :file-id])))
(mf/defc page-form
[{:keys [page] :as props}]