0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-09 16:48:16 -05:00

Add proper event tracing on nudge modal

And ♻️ refactor data event handling, moving
some logic from component to the event.
This commit is contained in:
Andrey Antukh 2022-03-07 14:58:50 +01:00
parent 8114b165d9
commit 5f49656e30
5 changed files with 60 additions and 23 deletions

View file

@ -601,7 +601,8 @@
(db/update! conn :profile
{:props (db/tjson props)}
{:id profile-id})
nil)))
(profile/filter-profile-props props))))
;; --- MUTATION: Delete Profile

View file

@ -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))

View file

@ -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}]

View file

@ -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

View file

@ -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}]]]]]]))
:on-change update-big}]]]]]]))