From b69ddbe6515f31de0c2cd5fe6f5645e19d6d8b4e Mon Sep 17 00:00:00 2001 From: virvar Date: Mon, 21 Mar 2016 16:01:20 +0300 Subject: [PATCH] Move contact list to components Former-commit-id: 7c9e8f6105ead0c3ca70079075142af9b085eae3 --- src/messenger/android/core.cljs | 3 +- src/messenger/android/sign_up_confirm.cljs | 8 ++-- .../contact_list/contact.cljs} | 46 ++----------------- .../components/contact_list/contact_list.cljs | 42 +++++++++++++++++ 4 files changed, 51 insertions(+), 48 deletions(-) rename src/messenger/{android/contacts_list.cljs => components/contact_list/contact.cljs} (80%) create mode 100644 src/messenger/components/contact_list/contact_list.cljs diff --git a/src/messenger/android/core.cljs b/src/messenger/android/core.cljs index 66f0b23d95..50a23c60bb 100644 --- a/src/messenger/android/core.cljs +++ b/src/messenger/android/core.cljs @@ -11,7 +11,7 @@ [messenger.state :as state] [messenger.utils.utils :refer [log toast]] [messenger.android.login :refer [login]] - [messenger.android.contacts-list :refer [contacts-list]] + [messenger.components.contact-list.contact-list :refer [contact-list]] [messenger.comm.pubsub :as pubsub] [messenger.comm.intercom :as intercom :refer [load-user-phone-number]] [messenger.protocol.protocol-handler :refer [make-handler]] @@ -55,7 +55,6 @@ (swap! state/app-state assoc :contacts-ds (data-source {:rowHasChanged (fn [row1 row2] (not= row1 row2))})) -(swap! state/app-state assoc :component contacts-list) (defonce RootNode (sup/root-node! 1)) (defonce app-root (om/factory RootNode)) diff --git a/src/messenger/android/sign_up_confirm.cljs b/src/messenger/android/sign_up_confirm.cljs index fdbbeaeb76..13f2d7b296 100644 --- a/src/messenger/android/sign_up_confirm.cljs +++ b/src/messenger/android/sign_up_confirm.cljs @@ -11,16 +11,16 @@ [messenger.utils.utils :refer [log toast]] [messenger.utils.resources :as res] [messenger.components.spinner :refer [spinner]] - [messenger.comm.intercom :as intercom :refer [set-confirmation-code]] - [messenger.android.contacts-list :refer [contacts-list]])) + [messenger.components.contact-list.contact-list :refer [contact-list]] + [messenger.comm.intercom :as intercom :refer [set-confirmation-code]])) (def nav-atom (atom nil)) (defn show-home-view [] (swap! state/app-state assoc :loading false) (binding [state/*nav-render* false] - (.replace @nav-atom (clj->js {:component contacts-list - :name "contacts-list"})))) + (.replace @nav-atom (clj->js {:component contact-list + :name "contact-list"})))) (defn sync-contacts [] (intercom/sync-contacts show-home-view)) diff --git a/src/messenger/android/contacts_list.cljs b/src/messenger/components/contact_list/contact.cljs similarity index 80% rename from src/messenger/android/contacts_list.cljs rename to src/messenger/components/contact_list/contact.cljs index a715a4eb0a..74388a4320 100644 --- a/src/messenger/android/contacts_list.cljs +++ b/src/messenger/components/contact_list/contact.cljs @@ -1,20 +1,12 @@ -(ns messenger.android.contacts-list +(ns messenger.components.contact-list.contact (:require-macros - [natal-shell.components :refer [view text image touchable-highlight list-view - toolbar-android]] - [natal-shell.core :refer [with-error-view]]) + [natal-shell.components :refer [view text image touchable-highlight]]) (:require [om.next :as om :refer-macros [defui]] - [re-natal.support :as sup] [messenger.state :as state] [messenger.utils.utils :refer [log toast http-post]] [messenger.utils.resources :as res] - [messenger.comm.intercom :as intercom] [messenger.components.chat.chat :refer [chat]])) -(def fake-contacts? true) - -(def react-native-contacts (js/require "react-native-contacts")) - (defn nav-push [nav route] (binding [state/*nav-render* false] (.push nav (clj->js route)))) @@ -32,7 +24,8 @@ '[:name :photo-path :delivery-status :datetime :new-messages-count :online]) Object (render [this] - (let [{:keys [name photo-path delivery-status datetime new-messages-count online]} + (let [{:keys [name photo-path delivery-status datetime new-messages-count + online]} (dissoc (om/props this) :om.next/computed) {:keys [nav]} (om/get-computed this)] (touchable-highlight @@ -129,34 +122,3 @@ new-messages-count))))))))) (def contact (om/factory Contact {:keyfn :name})) - -(defn render-row [nav row section-id row-id] - (contact (om/computed (js->clj row :keywordize-keys true) - {:nav nav}))) - -(defn load-contacts [] - (intercom/load-syng-contacts)) - -(defui ContactsList - static om/IQuery - (query [this] - '[:contacts-ds]) - Object - (componentDidMount [this] - (load-contacts)) - (render [this] - (let [{:keys [contacts-ds]} (om/props this) - {:keys [nav]} (om/get-computed this)] - (view {:style {:flex 1 - :backgroundColor "white"}} - (toolbar-android {:logo res/logo-icon - :title "Chats" - :titleColor "#4A5258" - :style {:backgroundColor "white" - :height 56 - :elevation 2}}) - (list-view {:dataSource contacts-ds - :renderRow (partial render-row nav) - :style {:backgroundColor "white"}}))))) - -(def contacts-list (om/factory ContactsList)) diff --git a/src/messenger/components/contact_list/contact_list.cljs b/src/messenger/components/contact_list/contact_list.cljs new file mode 100644 index 0000000000..d939338917 --- /dev/null +++ b/src/messenger/components/contact_list/contact_list.cljs @@ -0,0 +1,42 @@ +(ns messenger.components.contact-list.contact-list + (:require-macros + [natal-shell.components :refer [view text image touchable-highlight list-view + toolbar-android]] + [natal-shell.core :refer [with-error-view]]) + (:require [om.next :as om :refer-macros [defui]] + [messenger.state :as state] + [messenger.utils.utils :refer [log toast http-post]] + [messenger.utils.resources :as res] + [messenger.comm.intercom :as intercom] + [messenger.components.contact-list.contact :refer [contact]])) + +(defn render-row [nav row section-id row-id] + (contact (om/computed (js->clj row :keywordize-keys true) + {:nav nav}))) + +(defn load-contacts [] + (intercom/load-syng-contacts)) + +(defui ContactList + static om/IQuery + (query [this] + '[:contacts-ds]) + Object + (componentDidMount [this] + (load-contacts)) + (render [this] + (let [{:keys [contacts-ds]} (om/props this) + {:keys [nav]} (om/get-computed this)] + (view {:style {:flex 1 + :backgroundColor "white"}} + (toolbar-android {:logo res/logo-icon + :title "Chats" + :titleColor "#4A5258" + :style {:backgroundColor "white" + :height 56 + :elevation 2}}) + (list-view {:dataSource contacts-ds + :renderRow (partial render-row nav) + :style {:backgroundColor "white"}}))))) + +(def contact-list (om/factory ContactList))