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

View file

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

View file

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