From 265b712fe3e34dd30864c6b63a821de0fcc2e665 Mon Sep 17 00:00:00 2001 From: Sean Hagstrom Date: Fri, 23 Feb 2024 14:01:14 +0000 Subject: [PATCH] [#18912] resolve schema issues for context-tag (#18927) (#18927) chore: create profile-picture schema with profile-picture-fn field fix: update context-tag schema to allow for profile-picture-fn tidy: move profile-picture schema into the common schema namespaces tidy: revise docs for user-avatar-internal component to mainly warn about `profile-picture-fn` usage tidy: rename `profile-picture` schema to `profile-picture-source` tidy: use profile-picture-source schema in user-avatar schema --- .../avatars/user_avatar/schema.cljs | 5 +--- .../components/avatars/user_avatar/view.cljs | 29 +++---------------- .../components/tags/context_tag/schema.cljs | 5 ++-- src/schema/quo.cljs | 28 ++++++++++++++++++ src/status_im/setup/schema.cljs | 4 ++- 5 files changed, 39 insertions(+), 32 deletions(-) create mode 100644 src/schema/quo.cljs diff --git a/src/quo/components/avatars/user_avatar/schema.cljs b/src/quo/components/avatars/user_avatar/schema.cljs index bbfdfde7ed..a75299762c 100644 --- a/src/quo/components/avatars/user_avatar/schema.cljs +++ b/src/quo/components/avatars/user_avatar/schema.cljs @@ -17,8 +17,5 @@ [:theme :schema.common/theme] [:profile-picture {:optional true} - [:maybe - [:or - :schema.common/image-source - [:map [:fn fn?]]]]]]]] + [:maybe :schema.quo/profile-picture-source]]]]] :any]) diff --git a/src/quo/components/avatars/user_avatar/view.cljs b/src/quo/components/avatars/user_avatar/view.cljs index 880357655b..877e6177a5 100644 --- a/src/quo/components/avatars/user_avatar/view.cljs +++ b/src/quo/components/avatars/user_avatar/view.cljs @@ -25,32 +25,11 @@ (defn user-avatar-internal "Render user avatar with `profile-picture` - `profile-picture` should be one of {:uri profile-picture-uri} or {:fn profile-picture-fn} - `profile-picture-fn` should return an image URI, there's helper fn to generate - it in `utils.image-server` - - params for `profile-picture-fn` - {:length initials' length - :full-name used to generate initials - :font-size initials font size - :indicator-size status indicator outer radius, set to nil or 0 when no indicator - :indicator-border `indicator-size`-`indicator-border` is the inner radius - :indicator-color color for status indicator - :theme :light or :dark - :background-color intials avatar background color - :color intials avatar text color - :size intials avatar radius - :ring? render ident ring around avatar? NOTE: this option may not work if override-ring? is not nil} - - supported color formats: - #RRGGBB - #RRGGBBAA - rgb(255,255,255) - rgba(255,255,255,0.1) note alpha is 0-1 - - the reason we use the `profile-picture-fn` here is to separate - logic (pubkey, key-uid... in subs) and style (color, size... in this component)" + WARNING: + When calling the `profile-picture-fn` and passing the `:ring?` key, be aware that the `profile-picture-fn` + may have an `:override-ring?` value. If it does then the `:ring?` value will not be used. + For reference, refer to the `utils.image-server` namespace for these `profile-picture-fn` are generated." [{:keys [full-name size profile-picture customization-color static? status-indicator? online? ring? theme] :or {size :big diff --git a/src/quo/components/tags/context_tag/schema.cljs b/src/quo/components/tags/context_tag/schema.cljs index 419cc16903..7310059388 100644 --- a/src/quo/components/tags/context_tag/schema.cljs +++ b/src/quo/components/tags/context_tag/schema.cljs @@ -18,7 +18,7 @@ (def ^:private ?default [:map - [:profile-picture {:optional true} [:maybe :schema.common/image-source]] + [:profile-picture {:optional true} [:maybe :schema.quo/profile-picture-source]] [:full-name {:optional true} [:maybe :string]]]) (def ^:private ?multiuser @@ -26,7 +26,8 @@ [:users {:optional true} [:maybe [:sequential - [:map [:profile-picture {:optional true} [:maybe :schema.common/image-source]] + [:map + [:profile-picture {:optional true} [:maybe :schema.quo/profile-picture-source]] [:full-name {:optional true} [:maybe :string]] [:customization-color {:optional true} [:maybe :schema.common/customization-color]]]]]]]) diff --git a/src/schema/quo.cljs b/src/schema/quo.cljs new file mode 100644 index 0000000000..d72993e61f --- /dev/null +++ b/src/schema/quo.cljs @@ -0,0 +1,28 @@ +(ns schema.quo + (:require + [schema.registry :as registry])) + +(def ^:private ?profile-picture-fn-params + [:map + [:length :int] + [:full-name :string] + [:font-size :int] + [:indicator-size {:optional true} [:maybe :int]] + [:indicator-color {:optional true} [:maybe :string]] + [:indicator-center-to-edge {:optional true} [:maybe :int]] + [:override-theme :schema.common/theme] + [:background-color :string] + [:color :string] + [:size :int] + [:ring? :boolean] + [:ring-width :int]]) + +(def ^:private ?profile-picture-source + [:or + :schema.common/image-source + [:map + [:fn [:=> [:cat ?profile-picture-fn-params] :string]]]]) + +(defn register-schemas + [] + (registry/register ::profile-picture-source ?profile-picture-source)) diff --git a/src/status_im/setup/schema.cljs b/src/status_im/setup/schema.cljs index 0fe5ceb297..41bfe5da6c 100644 --- a/src/status_im/setup/schema.cljs +++ b/src/status_im/setup/schema.cljs @@ -9,6 +9,7 @@ malli.util schema.common [schema.core :as schema] + schema.quo schema.re-frame schema.registry [taoensso.timbre :as log])) @@ -78,7 +79,8 @@ [] (schema.registry/merge (malli.util/schemas)) (schema.common/register-schemas) - (schema.re-frame/register-schemas)) + (schema.re-frame/register-schemas) + (schema.quo/register-schemas)) (defn setup! "Configure Malli and initializes instrumentation.