2016-03-25 14:29:38 +03:00
|
|
|
(ns syng-im.components.chat
|
2016-03-25 13:36:16 +03:00
|
|
|
(:require [re-frame.core :refer [subscribe dispatch dispatch-sync]]
|
2016-03-25 17:22:13 +03:00
|
|
|
[syng-im.components.react :refer [android?
|
|
|
|
view
|
|
|
|
text
|
|
|
|
image
|
|
|
|
touchable-highlight
|
|
|
|
navigator
|
2016-03-28 19:00:07 +03:00
|
|
|
toolbar-android]]
|
|
|
|
[syng-im.components.realm :refer [list-view]]
|
2016-03-25 17:22:13 +03:00
|
|
|
[syng-im.utils.logging :as log]
|
|
|
|
[syng-im.navigation :refer [nav-pop]]
|
|
|
|
[syng-im.resources :as res]
|
2016-03-28 19:00:07 +03:00
|
|
|
[syng-im.utils.listview :refer [to-realm-datasource]]
|
2016-03-25 17:22:13 +03:00
|
|
|
[syng-im.components.invertible-scroll-view :refer [invertible-scroll-view]]
|
|
|
|
[reagent.core :as r]
|
|
|
|
[syng-im.components.chat-message :refer [chat-message]]
|
|
|
|
[syng-im.components.chat-message-new :refer [chat-message-new]]))
|
2016-03-25 13:36:16 +03:00
|
|
|
|
2016-03-25 14:29:38 +03:00
|
|
|
|
|
|
|
(defn chat [{:keys [navigator]}]
|
2016-03-25 17:22:13 +03:00
|
|
|
(let [messages (subscribe [:get-chat-messages])]
|
2016-03-25 13:36:16 +03:00
|
|
|
(fn []
|
2016-03-25 17:22:13 +03:00
|
|
|
(let [msgs @messages
|
|
|
|
_ (log/debug "messages=" msgs)
|
2016-03-28 19:00:07 +03:00
|
|
|
datasource (to-realm-datasource msgs)]
|
2016-03-25 17:22:13 +03:00
|
|
|
[view {:style {:flex 1
|
|
|
|
:backgroundColor "white"}}
|
|
|
|
(when android?
|
|
|
|
;; TODO add IOS version
|
|
|
|
[toolbar-android {:logo res/logo-icon
|
|
|
|
:title "Chat name"
|
|
|
|
:titleColor "#4A5258"
|
|
|
|
:subtitle "Last seen just now"
|
|
|
|
:subtitleColor "#AAB2B2"
|
|
|
|
:navIcon res/nav-back-icon
|
|
|
|
:style {:backgroundColor "white"
|
|
|
|
:height 56
|
|
|
|
:elevation 2}
|
|
|
|
:onIconClicked (fn []
|
|
|
|
(nav-pop navigator))}])
|
|
|
|
[list-view {:dataSource datasource
|
|
|
|
:renderScrollComponent (fn [props]
|
|
|
|
(invertible-scroll-view nil))
|
|
|
|
:renderRow (fn [row section-id row-id]
|
|
|
|
(r/as-element [chat-message (js->clj row :keywordize-keys true)]))
|
2016-03-29 23:45:31 +03:00
|
|
|
:style {:backgroundColor "white"}}]
|
2016-03-25 17:22:13 +03:00
|
|
|
[chat-message-new]]))))
|