mirror of
https://github.com/penpot/penpot.git
synced 2025-03-13 00:01:51 -05:00
✨ Add audit events for theme activation
This commit is contained in:
parent
8eaf93f08a
commit
ef2160dbb6
5 changed files with 54 additions and 42 deletions
|
@ -7,6 +7,7 @@
|
||||||
(ns app.main.data.dashboard.shortcuts
|
(ns app.main.data.dashboard.shortcuts
|
||||||
(:require
|
(:require
|
||||||
[app.main.data.dashboard :as dd]
|
[app.main.data.dashboard :as dd]
|
||||||
|
[app.main.data.events :as ev]
|
||||||
[app.main.data.shortcuts :as ds]
|
[app.main.data.shortcuts :as ds]
|
||||||
[app.main.data.users :as du]
|
[app.main.data.users :as du]
|
||||||
[app.main.store :as st]))
|
[app.main.store :as st]))
|
||||||
|
@ -35,7 +36,10 @@
|
||||||
:toggle-theme {:tooltip (ds/alt "M")
|
:toggle-theme {:tooltip (ds/alt "M")
|
||||||
:command (ds/a-mod "m")
|
:command (ds/a-mod "m")
|
||||||
:subsections [:general-dashboard]
|
:subsections [:general-dashboard]
|
||||||
:fn #(st/emit! (du/toggle-theme))}})
|
:fn #(st/emit! (with-meta (du/toggle-theme)
|
||||||
|
{::ev/origin "dashboard:shortcuts"}))}})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(defn get-tooltip [shortcut]
|
(defn get-tooltip [shortcut]
|
||||||
(assert (contains? shortcuts shortcut) (str shortcut))
|
(assert (contains? shortcuts shortcut) (str shortcut))
|
||||||
|
|
|
@ -53,7 +53,9 @@
|
||||||
|
|
||||||
(defn set-current-team!
|
(defn set-current-team!
|
||||||
[team-id]
|
[team-id]
|
||||||
(swap! storage assoc ::current-team-id team-id))
|
(if (nil? team-id)
|
||||||
|
(swap! storage dissoc ::current-team-id)
|
||||||
|
(swap! storage assoc ::current-team-id team-id)))
|
||||||
|
|
||||||
;; --- EVENT: fetch-teams
|
;; --- EVENT: fetch-teams
|
||||||
|
|
||||||
|
@ -132,7 +134,7 @@
|
||||||
(swap! storage assoc :profile profile)
|
(swap! storage assoc :profile profile)
|
||||||
(i18n/set-locale! (:lang profile))
|
(i18n/set-locale! (:lang profile))
|
||||||
(when (not= previous-email email)
|
(when (not= previous-email email)
|
||||||
(swap! storage dissoc ::current-team-id)))))))
|
(set-current-team! nil)))))))
|
||||||
|
|
||||||
(defn fetch-profile
|
(defn fetch-profile
|
||||||
[]
|
[]
|
||||||
|
@ -295,6 +297,19 @@
|
||||||
|
|
||||||
;; --- Update Profile
|
;; --- Update Profile
|
||||||
|
|
||||||
|
(defn persist-profile
|
||||||
|
[& {:as opts}]
|
||||||
|
(ptk/reify ::persist-profile
|
||||||
|
ptk/WatchEvent
|
||||||
|
(watch [_ state _]
|
||||||
|
(let [on-success (:on-success opts identity)
|
||||||
|
on-error (:on-error opts rx/throw)
|
||||||
|
profile (:profile state)]
|
||||||
|
|
||||||
|
(->> (rp/cmd! :update-profile (dissoc profile :props))
|
||||||
|
(rx/tap on-success)
|
||||||
|
(rx/catch on-error))))))
|
||||||
|
|
||||||
(defn update-profile
|
(defn update-profile
|
||||||
[data]
|
[data]
|
||||||
(dm/assert!
|
(dm/assert!
|
||||||
|
@ -303,21 +318,19 @@
|
||||||
|
|
||||||
(ptk/reify ::update-profile
|
(ptk/reify ::update-profile
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ _ stream]
|
(watch [_ state _]
|
||||||
(let [mdata (meta data)
|
(let [data (dissoc data :props)
|
||||||
on-success (:on-success mdata identity)
|
profile (:profile state)
|
||||||
on-error (:on-error mdata rx/throw)]
|
profile' (d/deep-merge profile data)]
|
||||||
(->> (rp/cmd! :update-profile (dissoc data :props))
|
|
||||||
(rx/mapcat
|
(rx/concat
|
||||||
(fn [_]
|
(rx/of #(assoc % :profile profile'))
|
||||||
(rx/merge
|
|
||||||
(->> stream
|
(when (not= (:theme profile) (:theme profile'))
|
||||||
(rx/filter (ptk/type? ::profile-fetched))
|
(rx/of (ptk/data-event ::ev/event
|
||||||
(rx/take 1)
|
{::ev/name "activate-theme"
|
||||||
(rx/tap on-success)
|
::ev/origin "settings"
|
||||||
(rx/ignore))
|
:theme (:theme profile')}))))))))
|
||||||
(rx/of (profile-fetched data)))))
|
|
||||||
(rx/catch on-error))))))
|
|
||||||
|
|
||||||
;; --- Toggle Theme
|
;; --- Toggle Theme
|
||||||
|
|
||||||
|
@ -327,18 +340,19 @@
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(update-in state [:profile :theme]
|
(update-in state [:profile :theme]
|
||||||
(fn [theme]
|
(fn [current]
|
||||||
(cond
|
(if (= current "default")
|
||||||
(= theme "default")
|
|
||||||
"light"
|
"light"
|
||||||
|
|
||||||
:else
|
|
||||||
"default"))))
|
"default"))))
|
||||||
|
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(watch [it state _]
|
||||||
(rx/of (update-profile (:profile state))))))
|
(let [profile (get state :profile)
|
||||||
|
origin (::ev/origin (meta it))]
|
||||||
|
(rx/of (ptk/data-event ::ev/event {:theme (:theme profile)
|
||||||
|
::ev/name "activate-theme"
|
||||||
|
::ev/origin origin})
|
||||||
|
(persist-profile))))))
|
||||||
|
|
||||||
;; --- Request Email Change
|
;; --- Request Email Change
|
||||||
|
|
||||||
|
|
|
@ -552,12 +552,12 @@
|
||||||
:command (ds/c-mod "alt+enter")
|
:command (ds/c-mod "alt+enter")
|
||||||
:fn #(emit-when-no-readonly (dp/open-preview-selected))}
|
:fn #(emit-when-no-readonly (dp/open-preview-selected))}
|
||||||
|
|
||||||
|
|
||||||
;; THEME
|
;; THEME
|
||||||
:toggle-theme {:tooltip (ds/alt "M")
|
:toggle-theme {:tooltip (ds/alt "M")
|
||||||
:command (ds/a-mod "m")
|
:command (ds/a-mod "m")
|
||||||
:subsections [:basics]
|
:subsections [:basics]
|
||||||
:fn #(st/emit! (du/toggle-theme))}})
|
:fn #(st/emit! (with-meta (du/toggle-theme)
|
||||||
|
{::ev/origin "workspace:shortcut"}))}})
|
||||||
|
|
||||||
(def opacity-shortcuts
|
(def opacity-shortcuts
|
||||||
(into {} (->>
|
(into {} (->>
|
||||||
|
|
|
@ -24,15 +24,12 @@
|
||||||
(s/def ::options-form
|
(s/def ::options-form
|
||||||
(s/keys :opt-un [::lang ::theme]))
|
(s/keys :opt-un [::lang ::theme]))
|
||||||
|
|
||||||
(defn- on-success
|
|
||||||
[_]
|
|
||||||
(st/emit! (msg/success (tr "notifications.profile-saved"))))
|
|
||||||
|
|
||||||
(defn- on-submit
|
(defn- on-submit
|
||||||
[form _event]
|
[form _event]
|
||||||
(let [data (:clean-data @form)
|
(let [data (:clean-data @form)]
|
||||||
mdata {:on-success (partial on-success form)}]
|
(st/emit! (du/update-profile data)
|
||||||
(st/emit! (du/update-profile (with-meta data mdata)))))
|
(du/persist-profile)
|
||||||
|
(msg/success (tr "notifications.profile-saved")))))
|
||||||
|
|
||||||
(mf/defc options-form
|
(mf/defc options-form
|
||||||
{::mf/wrap-props false}
|
{::mf/wrap-props false}
|
||||||
|
|
|
@ -27,15 +27,12 @@
|
||||||
(s/def ::profile-form
|
(s/def ::profile-form
|
||||||
(s/keys :req-un [::fullname ::email]))
|
(s/keys :req-un [::fullname ::email]))
|
||||||
|
|
||||||
(defn- on-success
|
|
||||||
[_]
|
|
||||||
(st/emit! (msg/success (tr "notifications.profile-saved"))))
|
|
||||||
|
|
||||||
(defn- on-submit
|
(defn- on-submit
|
||||||
[form _event]
|
[form _event]
|
||||||
(let [data (:clean-data @form)
|
(let [data (:clean-data @form)]
|
||||||
mdata {:on-success (partial on-success form)}]
|
(st/emit! (du/update-profile data)
|
||||||
(st/emit! (du/update-profile (with-meta data mdata)))))
|
(du/persist-profile)
|
||||||
|
(msg/success (tr "notifications.profile-saved")))))
|
||||||
|
|
||||||
;; --- Profile Form
|
;; --- Profile Form
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue