Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarBasem committed Dec 16, 2022
1 parent 492349f commit 9d1e5f3
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 25 deletions.
1 change: 0 additions & 1 deletion shadow-cljs.edn
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
:optimizations :simple
:target :node-test
:main status-im.test-runner/main
:ns-regexp "status-im2.subs.contact-test"
;; set :ui-driven to true to let shadow-cljs inject node-repl
:ui-driven true
:closure-defines
Expand Down
2 changes: 1 addition & 1 deletion src/quo2/components/avatars/group_avatar.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
:align-items :center
:justify-content :center
:border-radius (/ container-size 2)
:background-color (colors/custom-hex-color color 50 60)}
:background-color color}
[icon/icon :i/group {:size icon-size
:color colors/white-opa-70}]])))
3 changes: 0 additions & 3 deletions src/quo2/foundations/colors.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,7 @@
90 "E6"
"FF"))

(defn custom-hex-color [color light-opacity dark-opacity]
(str color (opacity->hex (if (theme/dark?) dark-opacity light-opacity))))

;; TODO (OmarBasem): custom-color-by-theme supports only string colors, so maybe we can get rid of it.
(defn custom-color-by-theme
"(custom-color-by-theme color suffix-light suffix-dark opacity-light opacity-dark)
color :primary/:purple/...
Expand Down
16 changes: 9 additions & 7 deletions src/status_im/group_chats/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
:on-success #(re-frame/dispatch [:chat-updated % do-not-navigate?])}]})

(fx/defn remove-members
"remove members from a group chat"
{:events [:group-chats.ui/remove-members-pressed]}
[{{:keys [current-chat-id deselected-members]} :db :as cofx}]
{::json-rpc/call [{:method "wakuext_removeMembersFromGroupChat"
:params [nil current-chat-id deselected-members]
:js-response true
:on-success #(re-frame/dispatch [:chat-updated % true])}]})
:on-success #(re-frame/dispatch [:chat-updated % true])
:on-error #()}]})

(fx/defn join-chat
{:events [:group-chats.ui/join-pressed]}
Expand Down Expand Up @@ -92,7 +92,9 @@
{::json-rpc/call [{:method "wakuext_addMembersToGroupChat"
:params [nil current-chat-id selected-participants]
:js-response true
:on-success #(re-frame/dispatch [:chat-updated % true])}]})
:on-success #(do
(println "SUCCESSADDMEMBERS" selected-participants)
(re-frame/dispatch [:chat-updated % true]))}]})

(fx/defn add-members-from-invitation
"Add members to a group chat"
Expand Down Expand Up @@ -214,13 +216,13 @@
[{:keys [db]} id]
{:db (update db :selected-participants conj id)})

(fx/defn reset-add-participants
{:events [:group/reset-add-participants]}
(fx/defn clear-added-participants
{:events [:group/clear-added-participants]}
[{db :db}]
{:db (assoc db :selected-participants #{})})

(fx/defn reset-remove-members
{:events [:group/reset-remove-members]}
(fx/defn clear-removed-members
{:events [:group/clear-removed-members]}
[{db :db}]
{:db (assoc db :deselected-members #{})})

Expand Down
18 changes: 12 additions & 6 deletions src/status_im/ui2/screens/chat/group_details/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
:justify-content :space-between}}
[back-button] [options-button]])

(defn count-container [count]
[rn/view {:style (style/count-container)}
(defn count-container [count accessibility-label]
[rn/view {:style (style/count-container)
:accessibility-label accessibility-label}
[quo2/text {:size :label
:weight :medium
:style {:text-align :center}} count]])
Expand All @@ -59,6 +60,7 @@
[rn/view {:style {:height (- window-height (:top safe-area))}}
[rn/touchable-opacity
{:on-press #(rf/dispatch [:bottom-sheet/hide])
:accessibility-label :close-manage-members
:style (style/close-icon)}
[quo2/icon :i/close {:color (colors/theme-colors colors/neutral-100 colors/white)}]]
[quo2/text {:size :heading-1
Expand All @@ -70,6 +72,7 @@
:search? true}]
[rn/view {:style style/bottom-container}
[quo2/button {:style {:flex 1}
:accessibility-label :save
:on-press (fn []
(rf/dispatch [:group-chats.ui/add-members-pressed])
(rf/dispatch [:group-chats.ui/remove-members-pressed])
Expand Down Expand Up @@ -100,28 +103,31 @@
[quo2/icon (if public? :i/world :i/privacy) {:size 20 :color (colors/theme-colors colors/neutral-50 colors/neutral-40)}]]]
[rn/view {:style (style/actions-view)}
[rn/touchable-opacity {:style (style/action-container color)
:accessibility-label :pinned-messages
:on-press (fn []
(rf/dispatch [:bottom-sheet/show-sheet :pinned-messages-list chat-id]))}
[rn/view {:style {:flex-direction :row
:justify-content :space-between}}
[quo2/icon :i/pin {:size 20 :color (colors/theme-colors colors/neutral-100 colors/white)}]
[count-container (count pinned-messages)]]
[count-container (count pinned-messages) :pinned-count]]
[quo2/text {:style {:margin-top 16} :size :paragraph-1 :weight :medium} (i18n/label :t/pinned-messages)]]
[rn/touchable-opacity {:style (style/action-container color)
:accessibility-label :toggle-mute
:on-press #(rf/dispatch [::chat.models/mute-chat-toggled chat-id (not muted)])}
[quo2/icon (if muted :i/muted :i/activity-center) {:size 20 :color (colors/theme-colors colors/neutral-100 colors/white)}]
[quo2/text {:style {:margin-top 16} :size :paragraph-1 :weight :medium} (i18n/label (if muted :unmute-group :mute-group))]]
[rn/touchable-opacity {:style (style/action-container color)
:accessibility-label :manage-members
:on-press (fn []
(rf/dispatch [:group/reset-add-participants])
(rf/dispatch [:group/reset-remove-members])
(rf/dispatch [:group/clear-added-participants])
(rf/dispatch [:group/clear-removed-members])
(rf/dispatch
[:bottom-sheet/show-sheet
{:content (fn [] [add-members-sheet group admin?])}]))}
[rn/view {:style {:flex-direction :row
:justify-content :space-between}}
[quo2/icon :i/add-user {:size 20 :color (colors/theme-colors colors/neutral-100 colors/white)}]
[count-container (count contacts)]]
[count-container (count contacts) :members-count]]
[quo2/text {:style {:margin-top 16} :size :paragraph-1 :weight :medium} (i18n/label (if admin? :t/manage-members :t/add-members))]]]
[rn/section-list {:key-fn :title
:sticky-section-headers-enabled false
Expand Down
2 changes: 2 additions & 0 deletions src/status_im2/common/contact_list_item/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
(if (= icon :options)
[quo/icon :i/options {:size 20 :color (colors/theme-colors colors/neutral-50 colors/neutral-40)}]
[quo/checkbox {:default-checked? member?
:accessibility-label :contact-toggle-check
:disabled? (and member? (not admin?))
:on-change (fn [selected]
(if-not member?
Expand All @@ -45,6 +46,7 @@
photo-path (when (seq images) (rf/sub [:chats/photo-path public-key]))
current-pk (rf/sub [:multiaccount/public-key])]
[rn/touchable-opacity (merge {:style (style/container)
:accessibility-label :contact
:active-opacity 1
:on-press #(open-chat public-key)
:on-long-press #(rf/dispatch [:bottom-sheet/show-sheet
Expand Down
6 changes: 4 additions & 2 deletions src/status_im2/common/home/actions/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[status-im2.common.constants :as constants]
[status-im.chat.models :as chat.models]))

(defn- entry [{:keys [icon label on-press danger? sub-label chevron? add-divider?]}]
(defn- entry [{:keys [icon label on-press danger? sub-label chevron? add-divider? accessibility-label]}]
{:pre [(keyword? icon)
(string? label)
(fn? on-press)
Expand All @@ -20,7 +20,8 @@
:danger? danger?
:sub-label sub-label
:right-icon (when chevron? :i/chevron-right)
:add-divider? add-divider?})
:add-divider? add-divider?
:accessibility-label accessibility-label})

(defn hide-sheet-and-dispatch [event]
(rf/dispatch [:bottom-sheet/hide])
Expand Down Expand Up @@ -256,6 +257,7 @@
(defn group-details-entry [chat-id]
(entry {:icon :i/members
:label (i18n/label :t/group-details)
:accessibility-label :group-details
:on-press #(hide-sheet-and-dispatch [:show-group-chat-profile chat-id])
:danger? false
:sub-label nil
Expand Down
7 changes: 2 additions & 5 deletions src/status_im2/subs/contact.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[status-im.utils.gfycat.core :as gfycat]
[status-im.ethereum.core :as ethereum]
[clojure.string :as string]
[utils.collection]
[i18n.i18n :as i18n]))

(re-frame/reg-sub
Expand Down Expand Up @@ -84,10 +85,6 @@
sort
vals)))

(defn distinct-by [f coll]
(let [groups (group-by f coll)]
(map #(first (groups %)) (distinct (map f coll)))))

(re-frame/reg-sub
:contacts/add-members-sections
:<- [:contacts/current-chat-contacts]
Expand All @@ -100,7 +97,7 @@
(update-in acc [first-char :data] #(conj % contact))
(assoc acc first-char {:title first-char :data [contact]}))))
{}
(distinct-by :public-key (concat members contacts)))
(utils.collection/distinct-by :public-key (concat members contacts)))
sort
vals)))

Expand Down
6 changes: 6 additions & 0 deletions src/utils/collection.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@
Similar to group-by except that the map values are single objects (depends on key uniqueness)."
[key coll]
(into {} (map #(vector (key %) %) coll)))


(defn distinct-by [key coll]
"Given a key and a collection returns a unique collection by that key"
(let [groups (group-by key coll)]
(map #(first (groups %)) (distinct (map key coll)))))
6 changes: 6 additions & 0 deletions status-go-version.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
"version": "v0.117.1",
"commit-sha1": "8593866862175eeab6f30765e5f0b813f3b1b4db",
Expand Down Expand Up @@ -41,4 +42,9 @@
"commit-sha1": "53ccf5344c088242474fb1ad429013be5788e8e1",
"src-sha256": "1qr5r30h347k950z38ifg2mc4mqz3dj6rj2b15150x0cfb2lvbjq"
>>>>>>> 3d0f52ba2... update status-go version
=======
"version": "d1a4b53d5c36c955c09302777d4a3c5aa24f87de",
"commit-sha1": "d1a4b53d5c36c955c09302777d4a3c5aa24f87de",
"src-sha256": "10ig1l4im6fkd7kn90ylichzpcf29m7k59w91d7p47j18icdmwv7"
>>>>>>> be4f63a29... refactor
}

0 comments on commit 9d1e5f3

Please sign in to comment.