From 4eba7c0cd9164fbdefae9fc0ff9f80dfd4eae12b Mon Sep 17 00:00:00 2001 From: virvar Date: Tue, 17 May 2016 13:26:20 +0300 Subject: [PATCH] Fix group chat Former-commit-id: 69b0dbdb8d7a813c3811054e918bdc6621552d65 --- src/syng_im/chat/screen.cljs | 5 +- .../group_settings/group_settings.cljs | 87 +++++++++---------- src/syng_im/navigation/handlers.cljs | 2 +- 3 files changed, 45 insertions(+), 49 deletions(-) diff --git a/src/syng_im/chat/screen.cljs b/src/syng_im/chat/screen.cljs index 1121e99dab..dd355b4223 100644 --- a/src/syng_im/chat/screen.cljs +++ b/src/syng_im/chat/screen.cljs @@ -224,12 +224,11 @@ :dataSource (to-datasource messages)}])) (defview chat [] - [is-active [:chat :is-active] - group-chat [:chat :group-chat] + [group-chat [:chat :group-chat] show-actions-atom [:show-actions]] [view st/chat-view [chat-toolbar] [messages-view group-chat] (when group-chat [typing-all]) - (when is-active [chat-message-new]) + [chat-message-new] (when show-actions-atom [actions-view])]) diff --git a/src/syng_im/group_settings/group_settings.cljs b/src/syng_im/group_settings/group_settings.cljs index 5d23a3ea40..b8f3886788 100644 --- a/src/syng_im/group_settings/group_settings.cljs +++ b/src/syng_im/group_settings/group_settings.cljs @@ -1,4 +1,5 @@ (ns syng-im.group-settings.group-settings + (:require-macros [syng-im.utils.views :refer [defview]]) (:require [re-frame.core :refer [subscribe dispatch dispatch-sync]] [syng-im.resources :as res] [syng-im.components.react :refer [view @@ -38,7 +39,8 @@ [text {:style st/modal-remove-text} "Remove"]]]]]) -(defn chat-members [members] +(defview chat-members [] + [members [:current-chat-contacts]] [view st/chat-members-container (for [member members] ^{:key member} [member-view member])]) @@ -87,10 +89,9 @@ [text {:style st/modal-color-picker-save-btn-text} "Save"]]]]]))) -(defn chat-color-icon [] - (let [chat-color (subscribe [:get-current-chat-color])] - (fn [] - [view {:style (st/chat-color-icon @chat-color)}]))) +(defview chat-color-icon [] + [chat-color [:get-current-chat-color]] + [view {:style (st/chat-color-icon chat-color)}]) (defn settings-view [] ;; TODO implement settings handlers @@ -121,48 +122,44 @@ (for [setting settings] ^{:key setting} [setting-view setting])])) -(defn chat-icon [] - (let [chat-name (subscribe [:get-current-chat-name]) - chat-color (subscribe [:get-current-chat-color])] - (fn [] - [view (st/chat-icon @chat-color) - [text {:style st/chat-icon-text} (nth @chat-name 0)]]))) +(defview chat-icon [] + [chat-name [:get-current-chat-name] + chat-color [:get-current-chat-color]] + [view (st/chat-icon chat-color) + [text {:style st/chat-icon-text} (nth chat-name 0)]]) (defn new-group-toolbar [] [toolbar {:title "Chat settings" :custom-action [chat-icon]}]) -(defn group-settings [] - (let [chat-name (subscribe [:get-current-chat-name]) - members (subscribe [:current-chat-contacts]) - selected-member (subscribe [:selected-group-chat-member]) - show-color-picker (subscribe [:group-settings-show-color-picker])] - (fn [] - [view st/group-settings - [new-group-toolbar] - [scroll-view st/body - [text {:style st/chat-name-text} - "Chat name"] - [view st/chat-name-value-container - [text {:style st/chat-name-value} - @chat-name] - [touchable-highlight {:style st/chat-name-btn-edit-container - :on-press show-chat-name-edit} - [text {:style st/chat-name-btn-edit-text} - "Edit"]]] - [text {:style st/members-text} - "Members"] - [touchable-highlight {:on-press (fn [] - (dispatch [:show-add-participants]))} - [view st/add-members-container - [icon :add-gray st/add-members-icon] - [text {:style st/add-members-text} - "Add members"]]] - [chat-members (vals (js->clj @members :keywordize-keys true))] - [text {:style st/settings-text} - "Settings"] - [settings-view]] - (when @show-color-picker - [chat-color-picker]) - (when @selected-member - [member-menu @selected-member])]))) +(defview group-settings [] + [chat-name [:get-current-chat-name] + selected-member [:selected-group-chat-member] + show-color-picker [:group-settings-show-color-picker]] + [view st/group-settings + [new-group-toolbar] + [scroll-view st/body + [text {:style st/chat-name-text} + "Chat name"] + [view st/chat-name-value-container + [text {:style st/chat-name-value} + chat-name] + [touchable-highlight {:style st/chat-name-btn-edit-container + :on-press show-chat-name-edit} + [text {:style st/chat-name-btn-edit-text} + "Edit"]]] + [text {:style st/members-text} + "Members"] + [touchable-highlight {:on-press #(dispatch [:show-add-participants])} + [view st/add-members-container + [icon :add-gray st/add-members-icon] + [text {:style st/add-members-text} + "Add members"]]] + [chat-members] + [text {:style st/settings-text} + "Settings"] + [settings-view]] + (when show-color-picker + [chat-color-picker]) + (when selected-member + [member-menu selected-member])]) diff --git a/src/syng_im/navigation/handlers.cljs b/src/syng_im/navigation/handlers.cljs index 217bd88136..35c4750bf5 100644 --- a/src/syng_im/navigation/handlers.cljs +++ b/src/syng_im/navigation/handlers.cljs @@ -57,7 +57,7 @@ (push-view db :contact-list))) (defn clear-new-participants [db] - (assoc-in db :new-participants #{})) + (assoc db :new-participants #{})) (register-handler :show-remove-participants (fn [db _]