add/remove participants

This commit is contained in:
Roman Volosovskyi 2016-05-20 19:58:07 +03:00
parent ae1918a2ae
commit cd45d3420e
10 changed files with 55 additions and 39 deletions

View File

@ -67,8 +67,8 @@
(defn on-action-selected [position] (defn on-action-selected [position]
(case position (case position
0 (dispatch [:show-add-participants]) 0 (dispatch [:navigate-to :add-participants])
1 (dispatch [:show-remove-participants]) 1 (dispatch [:navigate-to :remove-participants])
2 (dispatch [:leave-group-chat]))) 2 (dispatch [:leave-group-chat])))
(defn overlay [{:keys [on-click-outside]} items] (defn overlay [{:keys [on-click-outside]} items]
@ -119,13 +119,13 @@
:icon :menu_group :icon :menu_group
:icon-style {:width 25 :icon-style {:width 25
:height 19} :height 19}
:handler #(dispatch [:show-add-participants])} :handler #(dispatch [:navigate-to :add-participants])}
{:title "Remove Contact from chat" {:title "Remove Contact from chat"
:subtitle "Alex, John" :subtitle "Alex, John"
:icon :search_gray_copy :icon :search_gray_copy
:icon-style {:width 17 :icon-style {:width 17
:height 17} :height 17}
:handler #(dispatch [:show-remove-participants])} :handler #(dispatch [:navigate-to :remove-participants])}
{:title "Leave Chat" {:title "Leave Chat"
:icon :muted :icon :muted
:icon-style {:width 18 :icon-style {:width 18

View File

@ -1,8 +1,7 @@
(ns syng-im.group-settings.handlers (ns syng-im.group-settings.handlers
(:require [re-frame.core :refer [register-handler debug dispatch after]] (:require [re-frame.core :refer [register-handler debug dispatch after]]
[syng-im.persistence.realm :as r] [syng-im.persistence.realm :as r]
[syng-im.models.messages :refer [clear-history]] [syng-im.models.messages :refer [clear-history]]))
[clojure.string :as s]))
(defn save-chat-property! (defn save-chat-property!
[db-name property-name] [db-name property-name]

View File

@ -168,7 +168,7 @@
[scroll-view st/body [scroll-view st/body
[chat-name] [chat-name]
[text {:style st/members-text} "Members"] [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 [view st/add-members-container
[icon :add-gray st/add-members-icon] [icon :add-gray st/add-members-icon]
[text {:style st/add-members-text} [text {:style st/add-members-text}

View File

@ -38,9 +38,10 @@
syng-im.chat.handlers syng-im.chat.handlers
[syng-im.group-settings.handlers :refer [delete-chat]] [syng-im.group-settings.handlers :refer [delete-chat]]
syng-im.navigation.handlers syng-im.navigation.handlers
syng-im.discovery.handlers
syng-im.contacts.handlers syng-im.contacts.handlers
syng-im.new-group.handlers)) syng-im.discovery.handlers
syng-im.new-group.handlers
syng-im.participants.handlers))
;; -- Middleware ------------------------------------------------------------ ;; -- Middleware ------------------------------------------------------------
;; ;;

View File

@ -51,21 +51,6 @@
(fn [db _] (fn [db _]
(push-view db :contact-list))) (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 (defn show-profile
[db [_ identity]] [db [_ identity]]
(-> db (-> db

View File

@ -8,7 +8,6 @@
(defn on-toggle [whisper-identity] (defn on-toggle [whisper-identity]
(fn [checked?] (fn [checked?]
(println checked?)
(let [action (if checked? :select-contact :deselect-contact)] (let [action (if checked? :select-contact :deselect-contact)]
(dispatch [action whisper-identity])))) (dispatch [action whisper-identity]))))

View File

@ -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))

View File

@ -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))

View File

@ -1,4 +1,5 @@
(ns syng-im.participants.views.contact (ns syng-im.participants.views.contact
(:require-macros [syng-im.utils.views :refer [defview]])
(:require [re-frame.core :refer [subscribe dispatch dispatch-sync]] (:require [re-frame.core :refer [subscribe dispatch dispatch-sync]]
[syng-im.components.react :refer [view]] [syng-im.components.react :refer [view]]
[syng-im.contacts.views.contact-inner :refer [contact-inner-view]] [syng-im.contacts.views.contact-inner :refer [contact-inner-view]]
@ -6,14 +7,17 @@
[reagent.core :as r] [reagent.core :as r]
[syng-im.participants.styles :as st])) [syng-im.participants.styles :as st]))
(defn participant-contact [{:keys [whisper-identity] :as contact}] ;; todo duplication
;; todo must be moved to handlers (defn on-toggle [whisper-identity]
(let [checked (r/atom false)] (fn [checked?]
(fn [{:keys [whisper-identity] :as contact}] (let [action (if checked? :select-participant :deselect-participant)]
[view st/participant-container (dispatch [action whisper-identity]))))
[item-checkbox {:onToggle (fn [checked?]
(reset! checked checked?) (defview participant-contact
(dispatch [:select-new-participant whisper-identity checked?])) [{:keys [whisper-identity] :as contact}]
:checked @checked [checked [:is-participant-selected? whisper-identity]]
:size 30}] [view st/participant-container
[contact-inner-view contact]]))) [item-checkbox {:onToggle (on-toggle whisper-identity)
:checked checked
:size 30}]
[contact-inner-view contact]])

View File

@ -5,7 +5,8 @@
syng-im.group-settings.subs syng-im.group-settings.subs
syng-im.discovery.subs syng-im.discovery.subs
syng-im.contacts.subs syng-im.contacts.subs
syng-im.new-group.subs)) syng-im.new-group.subs
syng-im.participants.subs))
(register-sub :get (register-sub :get
(fn [db [_ k]] (fn [db [_ k]]