Skip to content

Commit

Permalink
tidy: expose image-uri helper schemas for annotating functions
Browse files Browse the repository at this point in the history
  • Loading branch information
seanstrom committed Mar 22, 2024
1 parent 267228a commit 64fb6cc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
20 changes: 12 additions & 8 deletions src/schema/quo.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
[:ring? :boolean]
[:ring-width :int]])

(def ^:private ?account-image-uri-opts
(def ^:private ?account-image-uri-options
[:map
[:port :int]
[:ratio :double]
Expand All @@ -26,7 +26,7 @@
[:theme :schema.common/theme]
[:override-ring? [:maybe :boolean]]])

(def ^:private ?initials-image-uri-opts
(def ^:private ?initials-image-uri-options
[:map
[:port :int]
[:ratio :double]
Expand All @@ -37,7 +37,7 @@
[:public-key {:optional true} [:maybe :string]]
[:override-ring? {:optional true} [:maybe :boolean]]])

(def ^:private ?contact-image-uri-opts
(def ^:private ?contact-image-uri-options
[:map
[:port :int]
[:clock :int]
Expand All @@ -47,17 +47,17 @@
[:theme :schema.common/theme]
[:override-ring? [:maybe :boolean]]])

(def ?image-uri-config
(def ^:private ?image-uri-config
[:or
[:map
[:kind [:enum :contact]]
[:options ?contact-image-uri-opts]]
[:options ?contact-image-uri-options]]
[:map
[:kind [:enum :account]]
[:options ?account-image-uri-opts]]
[:options ?account-image-uri-options]]
[:map
[:kind [:enum :initials]]
[:options ?initials-image-uri-opts]]])
[:options ?initials-image-uri-options]]])

(def ^:private ?profile-picture-source
[:or
Expand All @@ -69,4 +69,8 @@
[]
(registry/register ::profile-picture-options ?profile-picture-options)
(registry/register ::image-uri-config ?image-uri-config)
(registry/register ::profile-picture-source ?profile-picture-source))
(registry/register ::profile-picture-source ?profile-picture-source)
(registry/register ::profile-picture-options ?profile-picture-options)
(registry/register ::account-image-uri-options ?account-image-uri-options)
(registry/register ::contact-image-uri-options ?contact-image-uri-options)
(registry/register ::initials-image-uri-options ?initials-image-uri-options))
27 changes: 19 additions & 8 deletions src/utils/image_server.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@
"&ringWidth="
(* ring-width ratio)))

(schema/=> get-account-image-uri
[:=>
[:cat
[:union
:schema.quo/account-image-uri-options
:schema.quo/profile-picture-options]]
[:string]])

(defn get-initials-avatar-uri
"fn to get the avatar uri when account/contact/placeholder has no custom pic set
Expand Down Expand Up @@ -158,14 +166,9 @@
(schema/=> get-initials-avatar-uri
[:=>
[:cat
[:map
[:color string?]
[:background-color string?]
[:size number?]
[:ratio float?]
[:uppercase-ratio number?]
[:font-size number?]
[:font-file string?]]]
[:union
:schema.quo/initials-image-uri-options
:schema.quo/profile-picture-options]]
[:string]])

(defn get-contact-image-uri
Expand Down Expand Up @@ -204,6 +207,14 @@
"&ringWidth="
(* ring-width ratio)))

(schema/=> get-contact-image-uri
[:=>
[:cat
[:union
:schema.quo/contact-image-uri-options
:schema.quo/profile-picture-options]]
[:string]])

(defn get-qr-image-uri-for-any-url
[{:keys [url port qr-size error-level]}]
(let [qr-url-base64 (js/btoa url)
Expand Down

0 comments on commit 64fb6cc

Please sign in to comment.