From cd45d3420e74a49312468eb0c7822487492c257f Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Fri, 20 May 2016 19:58:07 +0300 Subject: [PATCH] add/remove participants --- src/syng_im/chat/screen.cljs | 8 +++---- src/syng_im/group_settings/handlers.cljs | 3 +-- src/syng_im/group_settings/screen.cljs | 2 +- src/syng_im/handlers.cljs | 5 ++-- src/syng_im/navigation/handlers.cljs | 15 ------------ src/syng_im/new_group/views/contact.cljs | 1 - src/syng_im/participants/handlers.cljs | 23 ++++++++++++++++++ src/syng_im/participants/subs.cljs | 8 +++++-- src/syng_im/participants/views/contact.cljs | 26 ++++++++++++--------- src/syng_im/subs.cljs | 3 ++- 10 files changed, 55 insertions(+), 39 deletions(-) create mode 100644 src/syng_im/participants/handlers.cljs diff --git a/src/syng_im/chat/screen.cljs b/src/syng_im/chat/screen.cljs index dd355b4223..1541c7b5f7 100644 --- a/src/syng_im/chat/screen.cljs +++ b/src/syng_im/chat/screen.cljs @@ -67,8 +67,8 @@ (defn on-action-selected [position] (case position - 0 (dispatch [:show-add-participants]) - 1 (dispatch [:show-remove-participants]) + 0 (dispatch [:navigate-to :add-participants]) + 1 (dispatch [:navigate-to :remove-participants]) 2 (dispatch [:leave-group-chat]))) (defn overlay [{:keys [on-click-outside]} items] @@ -119,13 +119,13 @@ :icon :menu_group :icon-style {:width 25 :height 19} - :handler #(dispatch [:show-add-participants])} + :handler #(dispatch [:navigate-to :add-participants])} {:title "Remove Contact from chat" :subtitle "Alex, John" :icon :search_gray_copy :icon-style {:width 17 :height 17} - :handler #(dispatch [:show-remove-participants])} + :handler #(dispatch [:navigate-to :remove-participants])} {:title "Leave Chat" :icon :muted :icon-style {:width 18 diff --git a/src/syng_im/group_settings/handlers.cljs b/src/syng_im/group_settings/handlers.cljs index 58dbda4067..71247222ec 100644 --- a/src/syng_im/group_settings/handlers.cljs +++ b/src/syng_im/group_settings/handlers.cljs @@ -1,8 +1,7 @@ (ns syng-im.group-settings.handlers (:require [re-frame.core :refer [register-handler debug dispatch after]] [syng-im.persistence.realm :as r] - [syng-im.models.messages :refer [clear-history]] - [clojure.string :as s])) + [syng-im.models.messages :refer [clear-history]])) (defn save-chat-property! [db-name property-name] diff --git a/src/syng_im/group_settings/screen.cljs b/src/syng_im/group_settings/screen.cljs index c74c74c020..3debc05c29 100644 --- a/src/syng_im/group_settings/screen.cljs +++ b/src/syng_im/group_settings/screen.cljs @@ -168,7 +168,7 @@ [scroll-view st/body [chat-name] [text {:style st/members-text} "Members"] - [touchable-highlight {:on-press #(dispatch [:show-add-participants])} + [touchable-highlight {:on-press #(dispatch [:navigate-to :add-participants])} [view st/add-members-container [icon :add-gray st/add-members-icon] [text {:style st/add-members-text} diff --git a/src/syng_im/handlers.cljs b/src/syng_im/handlers.cljs index 3123cf44b6..327e336144 100644 --- a/src/syng_im/handlers.cljs +++ b/src/syng_im/handlers.cljs @@ -38,9 +38,10 @@ syng-im.chat.handlers [syng-im.group-settings.handlers :refer [delete-chat]] syng-im.navigation.handlers - syng-im.discovery.handlers syng-im.contacts.handlers - syng-im.new-group.handlers)) + syng-im.discovery.handlers + syng-im.new-group.handlers + syng-im.participants.handlers)) ;; -- Middleware ------------------------------------------------------------ ;; diff --git a/src/syng_im/navigation/handlers.cljs b/src/syng_im/navigation/handlers.cljs index 6166d13ec6..f385485298 100644 --- a/src/syng_im/navigation/handlers.cljs +++ b/src/syng_im/navigation/handlers.cljs @@ -51,21 +51,6 @@ (fn [db _] (push-view db :contact-list))) -(defn clear-new-participants [db] - (assoc db :new-participants #{})) - -(register-handler :show-remove-participants - (fn [db _] - (-> db - (push-view :remove-participants) - clear-new-participants))) - -(register-handler :show-add-participants - (fn [db _] - (-> db - (push-view :add-participants) - clear-new-participants))) - (defn show-profile [db [_ identity]] (-> db diff --git a/src/syng_im/new_group/views/contact.cljs b/src/syng_im/new_group/views/contact.cljs index 6701e9fafc..e861bf02ba 100644 --- a/src/syng_im/new_group/views/contact.cljs +++ b/src/syng_im/new_group/views/contact.cljs @@ -8,7 +8,6 @@ (defn on-toggle [whisper-identity] (fn [checked?] - (println checked?) (let [action (if checked? :select-contact :deselect-contact)] (dispatch [action whisper-identity])))) diff --git a/src/syng_im/participants/handlers.cljs b/src/syng_im/participants/handlers.cljs new file mode 100644 index 0000000000..a2b71cf64d --- /dev/null +++ b/src/syng_im/participants/handlers.cljs @@ -0,0 +1,23 @@ +(ns syng-im.participants.handlers + (:require [syng-im.navigation.handlers :as nav] + [re-frame.core :refer [register-handler debug]])) + +(defmethod nav/preload-data! :add-participants + [db _] + (assoc db :new-participants #{})) + +(defmethod nav/preload-data! :remove-participants + [db _] + (assoc db :new-participants #{})) + +(defn deselect-participant + [db [_ id]] + (update db :new-participants disj id)) + +(register-handler :deselect-participant deselect-participant) + +(defn select-participant + [db [_ id]] + (update db :new-participants conj id)) + +(register-handler :select-participant (debug select-participant)) diff --git a/src/syng_im/participants/subs.cljs b/src/syng_im/participants/subs.cljs index 810a9ff3f6..c6e53a8af1 100644 --- a/src/syng_im/participants/subs.cljs +++ b/src/syng_im/participants/subs.cljs @@ -1,3 +1,7 @@ -(ns syng-im.participants.subs) +(ns syng-im.participants.subs + (:require-macros [reagent.ratom :refer [reaction]]) + (:require [re-frame.core :refer [register-sub]] + [syng-im.utils.subs :as u])) -() +(register-sub :is-participant-selected? + (u/contains-sub :new-participants)) diff --git a/src/syng_im/participants/views/contact.cljs b/src/syng_im/participants/views/contact.cljs index f193f24deb..4adbf51ba3 100644 --- a/src/syng_im/participants/views/contact.cljs +++ b/src/syng_im/participants/views/contact.cljs @@ -1,4 +1,5 @@ (ns syng-im.participants.views.contact + (:require-macros [syng-im.utils.views :refer [defview]]) (:require [re-frame.core :refer [subscribe dispatch dispatch-sync]] [syng-im.components.react :refer [view]] [syng-im.contacts.views.contact-inner :refer [contact-inner-view]] @@ -6,14 +7,17 @@ [reagent.core :as r] [syng-im.participants.styles :as st])) -(defn participant-contact [{:keys [whisper-identity] :as contact}] - ;; todo must be moved to handlers - (let [checked (r/atom false)] - (fn [{:keys [whisper-identity] :as contact}] - [view st/participant-container - [item-checkbox {:onToggle (fn [checked?] - (reset! checked checked?) - (dispatch [:select-new-participant whisper-identity checked?])) - :checked @checked - :size 30}] - [contact-inner-view contact]]))) +;; todo duplication +(defn on-toggle [whisper-identity] + (fn [checked?] + (let [action (if checked? :select-participant :deselect-participant)] + (dispatch [action whisper-identity])))) + +(defview participant-contact + [{:keys [whisper-identity] :as contact}] + [checked [:is-participant-selected? whisper-identity]] + [view st/participant-container + [item-checkbox {:onToggle (on-toggle whisper-identity) + :checked checked + :size 30}] + [contact-inner-view contact]]) diff --git a/src/syng_im/subs.cljs b/src/syng_im/subs.cljs index 6964ed715a..b2cf4af3bc 100644 --- a/src/syng_im/subs.cljs +++ b/src/syng_im/subs.cljs @@ -5,7 +5,8 @@ syng-im.group-settings.subs syng-im.discovery.subs syng-im.contacts.subs - syng-im.new-group.subs)) + syng-im.new-group.subs + syng-im.participants.subs)) (register-sub :get (fn [db [_ k]]