diff --git a/backend/src/app/rpc/mutations/profile.clj b/backend/src/app/rpc/mutations/profile.clj index 07f3866b6..85acbe863 100644 --- a/backend/src/app/rpc/mutations/profile.clj +++ b/backend/src/app/rpc/mutations/profile.clj @@ -601,7 +601,8 @@ (db/update! conn :profile {:props (db/tjson props)} {:id profile-id}) - nil))) + + (profile/filter-profile-props props)))) ;; --- MUTATION: Delete Profile diff --git a/backend/src/app/rpc/queries/profile.clj b/backend/src/app/rpc/queries/profile.clj index c1ed70244..26b6276d2 100644 --- a/backend/src/app/rpc/queries/profile.clj +++ b/backend/src/app/rpc/queries/profile.clj @@ -75,7 +75,7 @@ [conn profile] (merge profile (retrieve-additional-data conn (:id profile)))) -(defn- filter-profile-props +(defn filter-profile-props [props] (into {} (filter (fn [[k _]] (simple-ident? k))) props)) diff --git a/frontend/src/app/main/data/users.cljs b/frontend/src/app/main/data/users.cljs index f66c0af21..1c44bf4a8 100644 --- a/frontend/src/app/main/data/users.cljs +++ b/frontend/src/app/main/data/users.cljs @@ -385,6 +385,20 @@ (rx/empty))) (rx/ignore)))))) +(defn update-profile-props + [props] + (ptk/reify ::update-profile-props + ptk/UpdateEvent + (update [_ state] + (update-in state [:profile :props] merge props)) + + ;; TODO: for the release 1.13 we should skip fetching profile and just use + ;; the response value of update-profile-props RPC call + ptk/WatchEvent + (watch [_ state _] + (->> (rp/mutation :update-profile-props {:props props}) + (rx/map (constantly (fetch-profile))))))) + (defn mark-onboarding-as-viewed ([] (mark-onboarding-as-viewed nil)) ([{:keys [version]}] @@ -459,6 +473,7 @@ ptk/UpdateEvent (update [_ state] (update-in state [:profile :props] assoc :nudge value)) + ptk/WatchEvent (watch [_ _ _] (let [props {:nudge value}] diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 15c46bfdb..b7889b470 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -24,6 +24,7 @@ [app.config :as cfg] [app.main.data.events :as ev] [app.main.data.messages :as dm] + [app.main.data.users :as du] [app.main.data.workspace.bool :as dwb] [app.main.data.workspace.changes :as dch] [app.main.data.workspace.common :as dwc] @@ -438,8 +439,29 @@ ptk/UpdateEvent (update [_ state] (update state :workspace-layout - (fn [stored] - (reduce disj stored (d/concat-set flags))))))) + (fn [flags] + (disj flags flag)))))) + +;; --- Nudge + +(defn update-nudge + [{:keys [big small] :as params}] + (ptk/reify ::update-nudge + IDeref + (-deref [_] (d/without-nils params)) + + ptk/UpdateEvent + (update [_ state] + (update-in state [:profile :props :nudge] + (fn [nudge] + (cond-> nudge + (number? big) (assoc :big big) + (number? small) (assoc :small small))))) + + ptk/WatchEvent + (watch [_ state _] + (let [nudge (get-in state [:profile :props :nudge])] + (rx/of (du/update-profile-props {:nudge nudge})))))) ;; --- Set element options mode diff --git a/frontend/src/app/main/ui/workspace/nudge.cljs b/frontend/src/app/main/ui/workspace/nudge.cljs index c479a00ba..0909a7b84 100644 --- a/frontend/src/app/main/ui/workspace/nudge.cljs +++ b/frontend/src/app/main/ui/workspace/nudge.cljs @@ -7,7 +7,7 @@ (ns app.main.ui.workspace.nudge (:require [app.main.data.modal :as modal] - [app.main.data.users :as du] + [app.main.data.workspace :as dw] [app.main.refs :as refs] [app.main.store :as st] [app.main.ui.components.numeric-input :refer [numeric-input]] @@ -19,34 +19,33 @@ [rumext.alpha :as mf]) (:import goog.events.EventType)) +(defn- on-keydown + [event] + (when (k/enter? event) + (dom/prevent-default event) + (dom/stop-propagation event) + (modal/hide!))) (mf/defc nudge-modal {::mf/register modal/components ::mf/register-as :nudge-option} [] - (let [profile (mf/deref refs/profile) - nudge (get-in profile [:props :nudge] {:big 10 :small 1}) - update-nudge (fn [value size] (let [update-nudge (if (= :big size) - {:big value :small (:small nudge)} - {:small value :big (:big nudge)})] - (st/emit! (du/update-nudge update-nudge)))) - update-big (fn [value] (update-nudge value :big)) - update-small (fn [value] (update-nudge value :small)) - close #(modal/hide!)] + (let [profile (mf/deref refs/profile) + nudge (or (get-in profile [:props :nudge]) {:big 10 :small 1}) + update-big (mf/use-fn #(st/emit! (dw/update-nudge {:big %}))) + update-small (mf/use-fn #(st/emit! (dw/update-nudge {:small %}))) + on-close (mf/use-fn #(modal/hide!))] + (mf/with-effect - (letfn [(on-keydown [event] - (when (k/enter? event) - (dom/prevent-default event) - (dom/stop-propagation event) - (close)))] - (->> (events/listen js/document EventType.KEYDOWN on-keydown) - (partial events/unlistenByKey)))) + ;; (st/emit! (ptk/event ::ev/event {::ev/name "show-release-notes" :version version})) + (->> (events/listen js/document EventType.KEYDOWN on-keydown) + (partial events/unlistenByKey))) [:div.nudge-modal-overlay [:div.nudge-modal-container [:div.nudge-modal-header [:p.nudge-modal-title (tr "modals.nudge-title")] - [:button.modal-close-button {:on-click close} i/close]] + [:button.modal-close-button {:on-click on-close} i/close]] [:div.nudge-modal-body [:div.input-wrapper [:span @@ -59,4 +58,4 @@ [:p.nudge-subtitle (tr "modals.big-nudge")] [:> numeric-input {:min 1 :value (:big nudge) - :on-change update-big}]]]]]])) \ No newline at end of file + :on-change update-big}]]]]]]))