Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarBasem committed Dec 9, 2022
1 parent 0658974 commit 78518d2
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 67 deletions.
11 changes: 7 additions & 4 deletions src/status_im/group_chats/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
:js-response true
: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]}
Expand Down Expand Up @@ -189,7 +188,6 @@
(fx/defn deselect-member
{:events [:deselect-member]}
[{:keys [db]} id]
(println "DESELECTING MEMBER " id)
{:db (update db :deselected-members conj id)})

(fx/defn undo-deselect-member
Expand Down Expand Up @@ -217,11 +215,16 @@
[{:keys [db]} id]
{:db (update db :selected-participants conj id)})

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

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

(fx/defn show-group-chat-profile
{:events [:show-group-chat-profile]}
[{:keys [db] :as cofx} chat-id]
Expand Down
77 changes: 33 additions & 44 deletions src/status_im/ui2/screens/chat/group_details/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
[status-im2.common.contact-list-item.view :as contact-list-item]
[status-im.ui2.screens.chat.messages.message :as message]
[quo.components.safe-area :as safe-area]
[reagent.core :as reagent]
[status-im2.common.home.actions.view :as actions]
[status-im.ui2.screens.common.contact-list.view :as contact-list]))

Expand Down Expand Up @@ -51,46 +50,33 @@
:weight :medium
:style {:color (colors/theme-colors colors/neutral-50 colors/neutral-40)}} title]])

(def added (reagent/atom ()))

(def removed (reagent/atom ()))

(defn remove-members [chat-id]
(doseq [member-key @removed]
(rf/dispatch [:group-chats.ui/remove-member-pressed chat-id member-key true])))

(defn add-members-sheet [{:keys [chat-id] :as group} admin?]
(let [added (reagent/atom ())]
(fn []
[:f>
(fn []
(let [{window-height :height} (rn/use-window-dimensions)
safe-area (safe-area/use-safe-area)]
[rn/view {:style {:height (- window-height (:top safe-area))}}
[rn/touchable-opacity
{:on-press #(rf/dispatch [:bottom-sheet/hide])
:style (style/close-icon)}
[quo2/icon :i/close {:color (colors/theme-colors colors/neutral-100 colors/white)}]]
[quo2/text {:size :heading-1
:weight :semi-bold
:style {:margin-left 20}}
(i18n/label (if admin? :t/manage-members :t/add-members))]
[contact-list/contact-list {:icon :check
:group group
:added added
:removed removed
:search? true}]
[rn/view {:style style/bottom-container}
[quo2/button {:style {:flex 1}
:on-press (fn []
(rf/dispatch [:group-chats.ui/add-members-pressed])
(rf/dispatch [:group-chats.ui/remove-members-pressed])
;(remove-members chat-id)
(reset! removed ())
(reset! added ())
(rf/dispatch [:bottom-sheet/hide]))
:disabled (and (zero? (count @added)) (zero? (count @removed)))}
(i18n/label :t/save)]]]))])))
(defn add-members-sheet [group admin?]
[:f>
(fn []
(let [{window-height :height} (rn/use-window-dimensions)
safe-area (safe-area/use-safe-area)
selected-participants (rf/sub [:selected-participants])
deselected-members (rf/sub [:deselected-members])]
[rn/view {:style {:height (- window-height (:top safe-area))}}
[rn/touchable-opacity
{:on-press #(rf/dispatch [:bottom-sheet/hide])
:style (style/close-icon)}
[quo2/icon :i/close {:color (colors/theme-colors colors/neutral-100 colors/white)}]]
[quo2/text {:size :heading-1
:weight :semi-bold
:style {:margin-left 20}}
(i18n/label (if admin? :t/manage-members :t/add-members))]
[contact-list/contact-list {:icon :check
:group group
:search? true}]
[rn/view {:style style/bottom-container}
[quo2/button {:style {:flex 1}
:on-press (fn []
(rf/dispatch [:group-chats.ui/add-members-pressed])
(rf/dispatch [:group-chats.ui/remove-members-pressed])
(rf/dispatch [:bottom-sheet/hide]))
:disabled (and (zero? (count selected-participants)) (zero? (count deselected-members)))}
(i18n/label :t/save)]]]))])

(defn group-details []
(let [{:keys [admins chat-id chat-name color public? muted contacts] :as group} (rf/sub [:chats/current-chat])
Expand Down Expand Up @@ -128,9 +114,12 @@
[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)
:on-press #(rf/dispatch
[:bottom-sheet/show-sheet
{:content (fn [] [add-members-sheet group admin?])} :add-participants-toggle-list])}
:on-press (fn []
(rf/dispatch [:group/reset-add-participants])
(rf/dispatch [:group/reset-remove-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)}]
Expand Down
23 changes: 7 additions & 16 deletions src/status_im2/common/contact_list_item/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
(rf/dispatch [:search/home-filter-changed nil])
(rf/dispatch [:accept-all-activity-center-notifications-from-chat chat-id]))))

(defn action-icon [{:keys [public-key] :as item} {:keys [icon group added removed] :as extra-data}]
(defn action-icon [{:keys [public-key] :as item} {:keys [icon group] :as extra-data}]
(let [{:keys [contacts admins]} group
member? (contains? contacts public-key)
current-pk (rf/sub [:multiaccount/public-key])
admin? (get admins current-pk)
contact-selected? (rf/sub [:is-participant-selected? public-key])]
admin? (get admins current-pk)]
[rn/touchable-opacity {:on-press #(rf/dispatch [:bottom-sheet/show-sheet
{:content (fn [] [actions/actions item extra-data])}])
:style {:position :absolute
Expand All @@ -34,20 +33,12 @@
:disabled? (and member? (not admin?))
:on-change (fn [selected]
(if-not member?
(if contact-selected?
(do
(reset! added (remove #(= % public-key) @added))
(rf/dispatch [:deselect-participant public-key true]))
(do
(swap! added conj public-key)
(rf/dispatch [:select-participant public-key true])))
(if selected
(do
(rf/dispatch [:undo-deselect-member public-key true])
(reset! removed (remove #(= % public-key) @removed)))
(do
(rf/dispatch [:deselect-member public-key true])
(swap! removed conj public-key)))))}])]))
(rf/dispatch [:select-participant public-key true])
(rf/dispatch [:deselect-participant public-key true]))
(if selected
(rf/dispatch [:undo-deselect-member public-key true])
(rf/dispatch [:deselect-member public-key true]))))}])]))

(defn contact-list-item [item _ _ extra-data]
(let [{:keys [public-key ens-verified added? images]} item
Expand Down
6 changes: 3 additions & 3 deletions status-go-version.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
"owner": "status-im",
"repo": "status-go",
"version": "3745ec03efdf16c231e3df74da0c51af2480107e",
"commit-sha1": "3745ec03efdf16c231e3df74da0c51af2480107e",
"src-sha256": "1hikww0y1p70pr5ga3jnz72zc27k0zqjp9vk79ww9fw0165yi1h0"
"version": "v0.115.5",
"commit-sha1": "684e9654de4800df619ce593b5d331ebea9ed1a8",
"src-sha256": "0ci1s3w5jnf6sz2b6hn30gy14hp142gic006r6c3g5ln8y19wdbi"
}

0 comments on commit 78518d2

Please sign in to comment.