diff --git a/frontend/src/uxbox/main/data/pages.cljs b/frontend/src/uxbox/main/data/pages.cljs index 878c6ca76..c0ca3c82c 100644 --- a/frontend/src/uxbox/main/data/pages.cljs +++ b/frontend/src/uxbox/main/data/pages.cljs @@ -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)))))))))) diff --git a/frontend/src/uxbox/main/data/workspace.cljs b/frontend/src/uxbox/main/data/workspace.cljs index 6e54390c5..df399a21f 100644 --- a/frontend/src/uxbox/main/data/workspace.cljs +++ b/frontend/src/uxbox/main/data/workspace.cljs @@ -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 diff --git a/frontend/src/uxbox/main/ui/workspace/sidebar/sitemap_forms.cljs b/frontend/src/uxbox/main/ui/workspace/sidebar/sitemap_forms.cljs index ab0987553..2d24b8806 100644 --- a/frontend/src/uxbox/main/ui/workspace/sidebar/sitemap_forms.cljs +++ b/frontend/src/uxbox/main/ui/workspace/sidebar/sitemap_forms.cljs @@ -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}]