diff --git a/common/src/app/common/pages/changes.cljc b/common/src/app/common/pages/changes.cljc index e3a5274f2..1172de76e 100644 --- a/common/src/app/common/pages/changes.cljc +++ b/common/src/app/common/pages/changes.cljc @@ -293,23 +293,24 @@ (defmethod process-change :add-page [data {:keys [id name page]}] - (cond - (and (string? name) (uuid? id)) - (let [page (assoc init/empty-page-data - :id id - :name name)] - (-> data - (update :pages conj id) - (update :pages-index assoc id page))) - - (map? page) - (-> data - (update :pages conj (:id page)) - (update :pages-index assoc (:id page) page)) - - :else + (when (and id name page) (ex/raise :type :conflict - :hint "name or page should be provided, never both"))) + :hint "name or page should be provided, never both")) + (letfn [(conj-if-not-exists [pages id] + (cond-> pages + (not (d/seek #(= % id) pages)) + (conj id)))] + (if (and (string? name) (uuid? id)) + (let [page (assoc init/empty-page-data + :id id + :name name)] + (-> data + (update :pages conj-if-not-exists id) + (update :pages-index assoc id page))) + + (-> data + (update :pages conj-if-not-exists (:id page)) + (update :pages-index assoc (:id page) page))))) (defmethod process-change :mod-page [data {:keys [id name]}] diff --git a/frontend/src/app/main/data/workspace/changes.cljs b/frontend/src/app/main/data/workspace/changes.cljs index 4ca6c4f0b..4edfa71fd 100644 --- a/frontend/src/app/main/data/workspace/changes.cljs +++ b/frontend/src/app/main/data/workspace/changes.cljs @@ -141,6 +141,11 @@ (try (us/assert ::spec/changes redo-changes) (us/assert ::spec/changes undo-changes) + + ;; (prn "====== commit-changes ======" path) + ;; (cljs.pprint/pprint redo-changes) + ;; (cljs.pprint/pprint undo-changes) + (update-in state path cp/process-changes redo-changes false) (catch :default e