Fix crash when selecting avatar in context tags (#13923)
This commit is contained in:
parent
da62e0c533
commit
d4b7e5c8b6
|
@ -1,7 +1,6 @@
|
|||
(ns quo2.components.context-tags
|
||||
(:require [quo2.foundations.colors :as colors]
|
||||
[quo.theme :as quo.theme]
|
||||
[re-frame.core :as re-frame]
|
||||
[quo2.components.text :as text]
|
||||
[quo2.components.group-avatar :as group-avatar]
|
||||
[quo.react-native :as rn]))
|
||||
|
@ -46,9 +45,8 @@
|
|||
:size :paragraph-2}
|
||||
(trim-public-key public-key)]]))
|
||||
|
||||
(defn user-avatar-tag [_ _]
|
||||
(fn [params public-key]
|
||||
(let [{:keys [name photo]} @(re-frame/subscribe [:contacts/name-and-photo public-key])]
|
||||
(defn user-avatar-tag []
|
||||
(fn [params username photo]
|
||||
[base-tag (assoc-in params [:style :padding-left] 3)
|
||||
[rn/image {:style {:width 20
|
||||
:border-radius 10
|
||||
|
@ -58,4 +56,4 @@
|
|||
[text/text {:weight :medium
|
||||
:size :paragraph-2}
|
||||
|
||||
(str " " name)]])))
|
||||
(str " " username)]]))
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
(ns quo2.screens.context-tags
|
||||
(:require [reagent.core :as reagent]
|
||||
[re-frame.core :as re-frame]
|
||||
[status-im.multiaccounts.core :as multiaccounts]
|
||||
[quo.react-native :as rn]
|
||||
[quo.previews.preview :as preview]
|
||||
|
@ -12,8 +11,11 @@
|
|||
:color :purple})
|
||||
|
||||
(def example-pk "0x04fcf40c526b09ff9fb22f4a5dbd08490ef9b64af700870f8a0ba2133f4251d5607ed83cd9047b8c2796576bc83fa0de23a13a4dced07654b8ff137fe744047917")
|
||||
(def example-pk2 "0x04c178513eb741e8c4e50326b22baefa7d60a2f4eb81e328c4bbe0b441f87b2a014a5907a419f5897fc3c0493a0ff9db689a1999d6ca7fdc63119dd1981d0c7ccf")
|
||||
(def example-photo "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAIAQMAAAD+wSzIAAAABlBMVE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y1OXd6pJsQ+gqjk8VWFYmHrwBzW/n+uMPFiRwHB2I7ih8ciHFxIkd/3Omk5tCDV1t+2nNu5sxxpDFNx+huNhVT3/zMDz8usXC3ddaHBj1GHj/As08fwTS7Kt1HBTmyN29vdwAw+/wbwLVOJ3uAD1wi/dUH7Qei66PfyuRj4Ik9is+hglfbkbfR3cnZm7chlUWLdwmprtCohX4HUtlOcQjLYCu+fzGJH2QRKvP3UNz8bWk1qMxjGTOMThZ3kvgLI5AzFfo379UAAAAASUVORK5CYII=")
|
||||
|
||||
(def descriptor [{:label "Type"
|
||||
(def main-descriptor [{:label "Type"
|
||||
:key :type
|
||||
:type :select
|
||||
:options [{:key :public-key
|
||||
|
@ -27,23 +29,35 @@
|
|||
(let [state (reagent/atom {:label "Name"
|
||||
:type :group-avatar})]
|
||||
(fn []
|
||||
(let [contacts @(re-frame/subscribe [:contacts/contacts])
|
||||
descriptor
|
||||
(cond-> descriptor
|
||||
(= (:type @state) :group-avatar)
|
||||
(conj {:label "Label"
|
||||
:key :label
|
||||
:type :text})
|
||||
(= (:type @state) :avatar)
|
||||
(conj {:label "Contacts"
|
||||
:key :contact
|
||||
:type :select
|
||||
:options
|
||||
(map (fn [{:keys [public-key]}]
|
||||
(let [contacts {example-pk {:public-key example-pk
|
||||
:names {:three-words-name "Automatic incompatible Coati"}
|
||||
:photo example-photo}
|
||||
example-pk2 {:public-key example-pk2
|
||||
:names {:three-words-name "Clearcut Flickering Rattlesnake"}
|
||||
:photo example-photo2}}
|
||||
contacts-public-keys (map (fn [{:keys [public-key]}]
|
||||
{:key public-key
|
||||
:value (multiaccounts/displayed-name
|
||||
(get contacts public-key))})
|
||||
(vals contacts))}))]
|
||||
(vals contacts))
|
||||
current-username (if (seq (:contact @state))
|
||||
(->> @state :contact contacts multiaccounts/displayed-name)
|
||||
"Please select a user")
|
||||
descriptor
|
||||
(cond
|
||||
(= (:type @state) :group-avatar) (conj main-descriptor {:label "Label"
|
||||
:key :label
|
||||
:type :text})
|
||||
(= (:type @state) :avatar) (let [photo (-> @state :contact contacts :photo)]
|
||||
(when-not (contains? @state :contacts)
|
||||
(swap! state assoc :contacts contacts-public-keys))
|
||||
(when-not (= (:photo @state)
|
||||
photo)
|
||||
(swap! state assoc :photo photo))
|
||||
(conj main-descriptor {:label "Contacts"
|
||||
:key :contact
|
||||
:type :select
|
||||
:options contacts-public-keys})))]
|
||||
[rn/view {:margin-bottom 50
|
||||
:padding 16}
|
||||
[rn/view {:flex 1}
|
||||
|
@ -56,9 +70,8 @@
|
|||
[quo2/group-avatar-tag (:label @state) group-avatar-default-params]
|
||||
:public-key
|
||||
[quo2/public-key-tag {} example-pk]
|
||||
|
||||
:avatar
|
||||
[quo2/user-avatar-tag {} (:contact @state)])]]))))
|
||||
[quo2/user-avatar-tag {} current-username (:photo @state)])]]))))
|
||||
|
||||
(defn preview-context-tags []
|
||||
[rn/view {:background-color (colors/theme-colors colors/white
|
||||
|
|
Loading…
Reference in New Issue