Move contact list to components

Former-commit-id: 7c9e8f6105
This commit is contained in:
virvar 2016-03-21 16:01:20 +03:00
parent ff91912a7a
commit b69ddbe651
4 changed files with 51 additions and 48 deletions

View File

@ -11,7 +11,7 @@
[messenger.state :as state] [messenger.state :as state]
[messenger.utils.utils :refer [log toast]] [messenger.utils.utils :refer [log toast]]
[messenger.android.login :refer [login]] [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.pubsub :as pubsub]
[messenger.comm.intercom :as intercom :refer [load-user-phone-number]] [messenger.comm.intercom :as intercom :refer [load-user-phone-number]]
[messenger.protocol.protocol-handler :refer [make-handler]] [messenger.protocol.protocol-handler :refer [make-handler]]
@ -55,7 +55,6 @@
(swap! state/app-state assoc :contacts-ds (swap! state/app-state assoc :contacts-ds
(data-source {:rowHasChanged (fn [row1 row2] (data-source {:rowHasChanged (fn [row1 row2]
(not= row1 row2))})) (not= row1 row2))}))
(swap! state/app-state assoc :component contacts-list)
(defonce RootNode (sup/root-node! 1)) (defonce RootNode (sup/root-node! 1))
(defonce app-root (om/factory RootNode)) (defonce app-root (om/factory RootNode))

View File

@ -11,16 +11,16 @@
[messenger.utils.utils :refer [log toast]] [messenger.utils.utils :refer [log toast]]
[messenger.utils.resources :as res] [messenger.utils.resources :as res]
[messenger.components.spinner :refer [spinner]] [messenger.components.spinner :refer [spinner]]
[messenger.comm.intercom :as intercom :refer [set-confirmation-code]] [messenger.components.contact-list.contact-list :refer [contact-list]]
[messenger.android.contacts-list :refer [contacts-list]])) [messenger.comm.intercom :as intercom :refer [set-confirmation-code]]))
(def nav-atom (atom nil)) (def nav-atom (atom nil))
(defn show-home-view [] (defn show-home-view []
(swap! state/app-state assoc :loading false) (swap! state/app-state assoc :loading false)
(binding [state/*nav-render* false] (binding [state/*nav-render* false]
(.replace @nav-atom (clj->js {:component contacts-list (.replace @nav-atom (clj->js {:component contact-list
:name "contacts-list"})))) :name "contact-list"}))))
(defn sync-contacts [] (defn sync-contacts []
(intercom/sync-contacts show-home-view)) (intercom/sync-contacts show-home-view))

View File

@ -1,20 +1,12 @@
(ns messenger.android.contacts-list (ns messenger.components.contact-list.contact
(:require-macros (:require-macros
[natal-shell.components :refer [view text image touchable-highlight list-view [natal-shell.components :refer [view text image touchable-highlight]])
toolbar-android]]
[natal-shell.core :refer [with-error-view]])
(:require [om.next :as om :refer-macros [defui]] (:require [om.next :as om :refer-macros [defui]]
[re-natal.support :as sup]
[messenger.state :as state] [messenger.state :as state]
[messenger.utils.utils :refer [log toast http-post]] [messenger.utils.utils :refer [log toast http-post]]
[messenger.utils.resources :as res] [messenger.utils.resources :as res]
[messenger.comm.intercom :as intercom]
[messenger.components.chat.chat :refer [chat]])) [messenger.components.chat.chat :refer [chat]]))
(def fake-contacts? true)
(def react-native-contacts (js/require "react-native-contacts"))
(defn nav-push [nav route] (defn nav-push [nav route]
(binding [state/*nav-render* false] (binding [state/*nav-render* false]
(.push nav (clj->js route)))) (.push nav (clj->js route))))
@ -32,7 +24,8 @@
'[:name :photo-path :delivery-status :datetime :new-messages-count :online]) '[:name :photo-path :delivery-status :datetime :new-messages-count :online])
Object Object
(render [this] (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) (dissoc (om/props this) :om.next/computed)
{:keys [nav]} (om/get-computed this)] {:keys [nav]} (om/get-computed this)]
(touchable-highlight (touchable-highlight
@ -129,34 +122,3 @@
new-messages-count))))))))) new-messages-count)))))))))
(def contact (om/factory Contact {:keyfn :name})) (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))

View File

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