diff --git a/backend/src/uxbox/services/mutations/pages.clj b/backend/src/uxbox/services/mutations/pages.clj index 54cd6fa91..382c731c7 100644 --- a/backend/src/uxbox/services/mutations/pages.clj +++ b/backend/src/uxbox/services/mutations/pages.clj @@ -21,8 +21,10 @@ [uxbox.services.queries.files :as files] [uxbox.services.queries.pages :refer [decode-row]] [uxbox.tasks :as tasks] + [uxbox.redis :as redis] [uxbox.util.blob :as blob] - [uxbox.util.time :as dt])) + [uxbox.util.time :as dt] + [uxbox.util.transit :as t])) ;; --- Helpers & Specs @@ -148,9 +150,10 @@ (s/def ::changes (s/coll-of map? :kind vector?)) +(s/def ::session-id ::us/uuid) (s/def ::revn ::us/integer) (s/def ::update-page - (s/keys :req-un [::id ::profile-id ::revn ::changes])) + (s/keys :req-un [::id ::session-id ::profile-id ::revn ::changes])) (declare update-page) (declare retrieve-lagged-changes) @@ -172,7 +175,9 @@ :hint "The incoming revision number is greater that stored version." :context {:incoming-revn (:revn params) :stored-revn (:revn page)})) - (let [changes (:changes params) + (let [sid (:session-id params) + changes (->> (:changes params) + (mapv #(assoc % :session-id sid))) data (-> (:data page) (blob/decode) (cp/process-changes changes) @@ -183,7 +188,16 @@ :revn (inc (:revn page)) :changes (blob/encode changes)) - chng (insert-page-change! conn page)] + chng (insert-page-change! conn page) + msg {:type :page-change + :profile-id (:profile-id params) + :page-id (:id page) + :session-id sid + :revn (:revn page) + :changes changes}] + + @(redis/run! :publish {:channel (str (:file-id page)) + :message (t/encode-str msg)}) (db/update! conn :page {:revn (:revn page) @@ -192,13 +206,6 @@ (retrieve-lagged-changes conn chng params))) -;; (p/do! (ve/publish! uxbox.core/system topic -;; {:type :page-change -;; :profile-id (:profile-id params) -;; :page-id (:page-id s) -;; :revn (:revn s) -;; :changes changes}) - (defn- insert-page-change! [conn {:keys [revn data changes] :as page}] (let [id (uuid/next) diff --git a/frontend/src/uxbox/main/data/workspace/notifications.cljs b/frontend/src/uxbox/main/data/workspace/notifications.cljs index c30aea24f..74e4b77b4 100644 --- a/frontend/src/uxbox/main/data/workspace/notifications.cljs +++ b/frontend/src/uxbox/main/data/workspace/notifications.cljs @@ -18,6 +18,7 @@ [uxbox.main.repo :as rp] [uxbox.main.store :as st] [uxbox.main.streams :as ms] + [uxbox.main.data.workspace.persistence :as dwp] [uxbox.util.avatars :as avatars] [uxbox.util.geom.point :as gpt] [uxbox.util.time :as dt] @@ -75,7 +76,6 @@ (ptk/reify ::send-keepalive ptk/EffectEvent (effect [_ state stream] - (prn "send-keepalive" file-id) (when-let [ws (get-in state [:ws file-id])] (ws/-send ws (t/encode {:type :keepalive})))))) @@ -165,13 +165,10 @@ (ws/-send ws (t/encode msg)))))) (defn handle-page-change - [{:keys [profile-id page-id revn operations] :as msg}] + [msg] (ptk/reify ::handle-page-change ptk/WatchEvent (watch [_ state stream] - #_(let [page-id' (get-in state [:workspace-page :id])] - (when (= page-id page-id') - (rx/of (shapes-changes-commited msg))))))) - + (rx/of (dwp/shapes-changes-persisted msg))))) diff --git a/frontend/src/uxbox/main/data/workspace/persistence.cljs b/frontend/src/uxbox/main/data/workspace/persistence.cljs index 0c957bb71..29afd2700 100644 --- a/frontend/src/uxbox/main/data/workspace/persistence.cljs +++ b/frontend/src/uxbox/main/data/workspace/persistence.cljs @@ -42,7 +42,7 @@ (let [stoper (rx/filter #(= ::finalize %) stream) notifier (->> stream (rx/filter (ptk/type? ::dwc/commit-changes)) - (rx/debounce 2000) + (rx/debounce 200) (rx/merge stoper))] (rx/merge (->> stream @@ -64,15 +64,13 @@ (ptk/reify ::persist-changes ptk/WatchEvent (watch [_ state stream] - (let [session-id (:session-id state) - page (get-in state [:workspace-pages page-id]) - changes (->> changes - (mapcat identity) - (map #(assoc % :session-id session-id)) - (vec)) - params {:id (:id page) - :revn (:revn page) - :changes changes}] + (let [sid (:session-id state) + page (get-in state [:workspace-pages page-id]) + changes (into [] (mapcat identity) changes) + params {:id (:id page) + :revn (:revn page) + :session-id sid + :changes changes}] (->> (rp/mutation :update-page params) (rx/map shapes-changes-persisted)))))) diff --git a/frontend/src/uxbox/main/ui/workspace/shapes/text.cljs b/frontend/src/uxbox/main/ui/workspace/shapes/text.cljs index fdb04b344..3a41a73cf 100644 --- a/frontend/src/uxbox/main/ui/workspace/shapes/text.cljs +++ b/frontend/src/uxbox/main/ui/workspace/shapes/text.cljs @@ -260,15 +260,16 @@ (fn [event] (mf/set-ref-val! selecting-ref false)) - on-keyup + on-key-up (fn [event] + (dom/stop-propagation event) (when (= (.-keyCode event) 27) ; ESC (on-close))) on-mount (fn [] (let [lkey1 (events/listen js/document EventType.CLICK on-click) - lkey2 (events/listen js/document EventType.KEYUP on-keyup)] + lkey2 (events/listen js/document EventType.KEYUP on-key-up)] (st/emit! (dwt/assign-editor id editor)) #(do (st/emit! (dwt/assign-editor id nil)) diff --git a/frontend/src/uxbox/main/ui/workspace/viewport.cljs b/frontend/src/uxbox/main/ui/workspace/viewport.cljs index 9632ec599..4baa5c6fc 100644 --- a/frontend/src/uxbox/main/ui/workspace/viewport.cljs +++ b/frontend/src/uxbox/main/ui/workspace/viewport.cljs @@ -33,6 +33,7 @@ [uxbox.main.ui.workspace.snap-feedback :refer [snap-feedback]] [uxbox.util.math :as mth] [uxbox.util.dom :as dom] + [uxbox.util.object :as obj] [uxbox.util.geom.point :as gpt] [uxbox.util.perf :as perf] [uxbox.common.uuid :as uuid]) @@ -162,10 +163,7 @@ (and (not edition) (= 2 (.-which event))) - (handle-viewport-positioning viewport-ref) - - :else - (js/console.log "on-mouse-down" event))))) + (handle-viewport-positioning viewport-ref))))) on-context-menu (mf/use-callback @@ -234,10 +232,13 @@ shift? (kbd/shift? event) opts {:key key :shift? shift? - :ctrl? ctrl?}] + :ctrl? ctrl?} + target (dom/get-target event)] + (when-not (.-repeat bevent) (st/emit! (ms/->KeyboardEvent :down key ctrl? shift?)) - (when (kbd/space? event) + (when (and (kbd/space? event) + (not= "rich-text" (obj/get target "className"))) (handle-viewport-positioning viewport-ref)))))) on-key-up