remove to-realm-datasource

This commit is contained in:
Roman Volosovskyi 2016-05-13 18:56:52 +03:00
parent c27fddfe18
commit f484b190fd
12 changed files with 91 additions and 151 deletions

View File

@ -1,11 +1,12 @@
(ns syng-im.chats-list.screen
(:require [re-frame.core :refer [subscribe dispatch]]
[syng-im.components.react :refer [view
[syng-im.components.react :refer [list-view
list-item
view
text
image
touchable-highlight]]
[syng-im.components.realm :refer [list-view]]
[syng-im.utils.listview :refer [to-realm-datasource]]
[syng-im.utils.listview :refer [to-datasource2]]
[reagent.core :as r]
[syng-im.chats-list.views.chat-list-item :refer [chat-list-item]]
[syng-im.components.action-button :refer [action-button
@ -28,24 +29,22 @@
(defn chats-list []
(let [chats (subscribe [:get :chats])]
(fn []
(let [chats @chats
datasource (to-realm-datasource chats)]
[view st/chats-container
[chats-list-toolbar]
[list-view {:dataSource datasource
:renderRow (fn [row _ _]
(r/as-element [chat-list-item row]))
:style st/list-container}]
[action-button {:buttonColor color-blue}
[action-button-item
{:title "New Chat"
:buttonColor :#9b59b6
:onPress #(dispatch [:navigate-to :contact-list])}
[icon {:name :android-create
:style st/create-icon}]]
[action-button-item
{:title "New Group Chat"
:buttonColor :#1abc9c
:onPress #(dispatch [:show-group-new])}
[icon {:name :person-stalker
:style st/person-stalker-icon}]]]]))))
[view st/chats-container
[chats-list-toolbar]
[list-view {:dataSource (to-datasource2 (vals @chats))
:renderRow (fn [row _ _]
(list-item [chat-list-item row]))
:style st/list-container}]
[action-button {:buttonColor color-blue}
[action-button-item
{:title "New Chat"
:buttonColor :#9b59b6
:onPress #(dispatch [:navigate-to :contact-list])}
[icon {:name :android-create
:style st/create-icon}]]
[action-button-item
{:title "New Group Chat"
:buttonColor :#1abc9c
:onPress #(dispatch [:show-group-new])}
[icon {:name :person-stalker
:style st/person-stalker-icon}]]]])))

View File

@ -8,12 +8,11 @@
[syng-im.chats-list.views.inner-item :refer
[chat-list-item-inner-view]]))
(defn chat-list-item [chat-obj]
(defn chat-list-item [{:keys [chat-id] :as chat}]
[touchable-highlight
{:on-press #(dispatch [:show-chat (aget chat-obj "chat-id") :push])}
{:on-press #(dispatch [:show-chat chat-id :push])}
;; TODO add [photo-path delivery-status new-messages-count online] values to chat-obj
;; TODO should chat-obj be clj-map?
[view [chat-list-item-inner-view (merge (js->clj chat-obj :keywordize-keys true)
[view [chat-list-item-inner-view (merge chat
{:photo-path nil
:delivery-status :seen
:new-messages-count 3

View File

@ -40,42 +40,3 @@
(r/as-element component))
(def dismiss-keyboard! (js/require "dismissKeyboard"))
(comment
(.-width (.get (.. js/React -Dimensions) "window"))
)
;; (do
;; (def activity-indicator-ios (r/adapt-react-class (.-ActivityIndicatorIOS js/React)))
;; (def animated-image (r/adapt-react-class (.-Animated.Image js/React)))
;; (def animated-text (r/adapt-react-class (.-Animated.Text js/React)))
;; (def animated-view (r/adapt-react-class (.-Animated.View js/React)))
;; (def date-picker-ios (r/adapt-react-class (.-DatePickerIOS js/React)))
;; (def drawer-layout-android (r/adapt-react-class (.-DrawerLayoutAndroid js/React)))
;; (def image (r/adapt-react-class (.-Image js/React)))
;; (def list-view (r/adapt-react-class (.-ListView js/React)))
;; (def map-view (r/adapt-react-class (.-MapView js/React)))
;; (def modal (r/adapt-react-class (.-Modal js/React)))
;; (def navigator (r/adapt-react-class (.-Navigator js/React)))
;; (def navigator-ios (r/adapt-react-class (.-NavigatorIOS js/React)))
;; (def picker-ios (r/adapt-react-class (.-PickerIOS js/React)))
;; (def progress-bar-android (r/adapt-react-class (.-ProgressBarAndroid js/React)))
;; (def progress-view-ios (r/adapt-react-class (.-ProgressViewIOS js/React)))
;; (def pull-to-refresh-view-android (r/adapt-react-class (.-PullToRefreshViewAndroid js/React)))
;; (def scroll-view (r/adapt-react-class (.-ScrollView js/React)))
;; (def segmented-control-ios (r/adapt-react-class (.-SegmentedControlIOS js/React)))
;; (def slider-ios (r/adapt-react-class (.-SliderIOS js/React)))
;; (def switch (r/adapt-react-class (.-Switch js/React)))
;; (def tab-bar-ios (r/adapt-react-class (.-TabBarIOS js/React)))
;; (def tab-bar-ios-item (r/adapt-react-class (.-TabBarIOS.Item js/React)))
;; (def text (r/adapt-react-class (.-Text js/React)))
;; (def text-input (r/adapt-react-class (.-TextInput js/React)))
;; (def toolbar-android (r/adapt-react-class (.-ToolbarAndroid js/React)))
;; (def touchable-highlight (r/adapt-react-class (.-TouchableHighlight js/React)))
;; (def touchable-native-feedback (r/adapt-react-class (.-TouchableNativeFeedback js/React)))
;; (def touchable-opacity (r/adapt-react-class (.-TouchableOpacity js/React)))
;; (def touchable-without-feedback (r/adapt-react-class (.-TouchableWithoutFeedback js/React)))
;; (def view (r/adapt-react-class (.-View js/React)))
;; (def view-pager-android (r/adapt-react-class (.-ViewPagerAndroid js/React)))
;; (def web-view (r/adapt-react-class (.-WebView js/React))))

View File

@ -7,15 +7,3 @@
(defn list-view [props]
[list-view-class (merge {:enableEmptySections true} props)])
(comment
;(set! js/wat (js/require "realm.react-native.ListView"))
;(.-Results js/Realm)
;
;(r/realm)
;
;(require '[syng-im.persistence.realm :as r])
)

View File

@ -12,8 +12,7 @@
color-purple
text1-color
text2-color
toolbar-background1]]
[syng-im.utils.listview :refer [to-realm-datasource]]))
toolbar-background1]]))
(defn toolbar [{:keys [title nav-action action background-color content style]}]
(let [style (merge {:flexDirection :row

View File

@ -2,7 +2,7 @@
(:require
[re-frame.core :refer [subscribe]]
[syng-im.components.react :refer [view list-view list-item]]
[syng-im.utils.listview :refer [to-realm-datasource to-datasource2]]
[syng-im.utils.listview :refer [to-datasource2]]
[syng-im.discovery.styles :as st]
[syng-im.discovery.views.popular-list-item
:refer [popular-list-item]]))

View File

@ -238,12 +238,12 @@
(update-new-participants-selection db identity add?)))
(register-handler :remove-selected-participants
(fn [db [action navigator]]
(fn [db [action]]
(log/debug action)
(let [identities (vec (:new-participants db))
chat-id (:current-chat-id db)]
(chat-remove-participants chat-id identities)
(nav-pop navigator)
(dispatch [:navigate-back])
(doseq [ident identities]
(api/group-remove-participant chat-id ident)
(removed-participant-msg chat-id ident)))))

View File

@ -6,39 +6,46 @@
text
image
icon
touchable-highlight]]
touchable-highlight
list-view
list-item]]
[syng-im.components.styles :refer [color-purple]]
[syng-im.components.toolbar :refer [toolbar]]
[syng-im.components.realm :refer [list-view]]
[syng-im.utils.listview :refer [to-realm-datasource]]
[syng-im.utils.listview :refer [to-datasource2]]
[syng-im.new-group.views.contact :refer [new-group-contact]]
[reagent.core :as r]
[syng-im.new-group.styles :as st]))
(defn new-group-toolbar [group-name]
[toolbar {:title "New group chat"
:action {:image {:source res/v ;; {:uri "icon_search"}
:style st/toolbar-icon}
:handler #(dispatch [:create-new-group group-name])}}])
(defn new-group-toolbar []
(let [group-name (subscribe [:get ::group-name])]
(fn []
[toolbar
{:title "New group chat"
:action {:image {:source res/v ;; {:uri "icon_search"}
:style st/toolbar-icon}
:handler #(dispatch [:create-new-group @group-name])}}])))
(defn group-name-input []
(let [group-name (subscribe [:get ::group-name])]
(fn []
[text-input
{:underlineColorAndroid color-purple
:style st/group-name-input
:autoFocus true
:placeholder "Group Name"
:onChangeText #(dispatch [:set ::group-name %])
:onSubmitEditing #(dispatch [:set ::group-name nil])}
@group-name])))
(defn new-group []
(let [contacts (subscribe [:all-contacts])
group-name (subscribe [:get ::group-name])]
(let [contacts (subscribe [:all-contacts])]
(fn []
(let [contacts-ds (to-realm-datasource @contacts)]
(let [contacts-ds (to-datasource2 @contacts)]
[view st/new-group-container
[new-group-toolbar @group-name]
[new-group-toolbar]
[view st/chat-name-container
[text {:style st/chat-name-text} "Chat name"]
[text-input
{:underlineColorAndroid color-purple
:style st/group-name-input
:autoFocus true
:placeholder "Group Name"
:onChangeText #(dispatch [:set ::group-name %])
:onSubmitEditing #(dispatch [:set ::group-name nil])}
@group-name]
[group-name-input]
[text {:style st/members-text} "Members"]
[touchable-highlight {:on-press (fn [])}
[view st/add-container
@ -47,6 +54,5 @@
[list-view
{:dataSource contacts-ds
:renderRow (fn [row _ _]
(let [row' (js->clj row :keywordize-keys true)]
(r/as-element [new-group-contact row'])))
(list-item [new-group-contact row]))
:style st/contacts-list}]]]))))

View File

@ -1,10 +1,9 @@
(ns syng-im.participants.views.create
(:require [re-frame.core :refer [subscribe dispatch]]
[syng-im.resources :as res]
[syng-im.components.react :refer [view]]
[syng-im.components.realm :refer [list-view]]
[syng-im.components.react :refer [view list-view list-item]]
[syng-im.components.toolbar :refer [toolbar]]
[syng-im.utils.listview :refer [to-realm-datasource]]
[syng-im.utils.listview :refer [to-datasource2]]
[syng-im.participants.views.contact
:refer [participant-contact]]
[reagent.core :as r]
@ -20,13 +19,12 @@
(defn new-participants-row
[row _ _]
(r/as-element
[participant-contact (js->clj row :keywordize-keys true)]))
(list-item [participant-contact row]))
(defn new-participants [{:keys [navigator]}]
(let [contacts (subscribe [:all-new-contacts])]
(fn []
(let [contacts-ds (to-realm-datasource @contacts)]
(let [contacts-ds (to-datasource2 @contacts)]
[view st/participants-container
[new-participants-toolbar navigator]
[list-view {:dataSource contacts-ds

View File

@ -2,34 +2,32 @@
(:require [re-frame.core :refer [subscribe dispatch]]
[syng-im.resources :as res]
[syng-im.components.react :refer [view text-input text image
touchable-highlight]]
[syng-im.components.realm :refer [list-view]]
touchable-highlight list-view
list-item]]
[syng-im.components.toolbar :refer [toolbar]]
[syng-im.utils.listview :refer [to-realm-datasource]]
[syng-im.utils.listview :refer [to-datasource2]]
[syng-im.participants.views.contact
:refer [participant-contact]]
[reagent.core :as r]
[syng-im.participants.styles :as st]))
(defn remove-participants-toolbar [navigator]
(defn remove-participants-toolbar []
[toolbar
{:navigator navigator
:title "Remove Participants"
:action {:handler #(dispatch [:remove-selected-participants navigator])
{:title "Remove Participants"
:action {:handler #(dispatch [:remove-selected-participants])
:image {:source res/trash-icon ;; {:uri "icon_search"}
:style st/remove-participants-image}}}])
(defn remove-participants-row
[row _ _]
(r/as-element
[participant-contact (js->clj row :keywordize-keys true)]))
(r/as-element [participant-contact row]))
(defn remove-participants [{:keys [navigator]}]
(defn remove-participants []
(let [contacts (subscribe [:current-chat-contacts])]
(fn []
(let [contacts-ds (to-realm-datasource @contacts)]
(let [contacts-ds (to-datasource2 @contacts)]
[view st/participants-container
[remove-participants-toolbar navigator]
[remove-participants-toolbar]
[list-view {:dataSource contacts-ds
:renderRow remove-participants-row
:style st/participants-list}]]))))

View File

@ -29,32 +29,30 @@
(reaction (:contacts @db))))
(register-sub :all-contacts
(fn [_ _]
(reaction (get-contacts))))
(fn [db _]
(let [contacts (reaction (:contacts @db))]
(reaction (sort-by :name @contacts)))))
(defn contacts-by-current-chat [fn db]
(let [current-chat-id (:current-chat-id @db)
chat (reaction (get-in @db [:chats current-chat-id]))
contacts (reaction (:contacts @db))]
(reaction
(when @chat
(let [current-participants (->> @chat
:contacts
(map :identity)
set)]
(fn #(current-participants (:whisper-identity %))
@contacts))))))
(register-sub :all-new-contacts
(fn [db _]
(let [current-chat-id (reaction (:current-chat-id @db))
chat (reaction (when-let [chat-id @current-chat-id]
(chat-by-id chat-id)))]
(reaction
(when @chat
(let [current-participants (->> @chat
:contacts
(map :identity))]
(contacts-list-exclude current-participants)))))))
(contacts-by-current-chat remove db)))
(register-sub :current-chat-contacts
(fn [db _]
(let [current-chat-id (reaction (:current-chat-id @db))
chat (reaction (when-let [chat-id @current-chat-id]
(chat-by-id chat-id)))]
(reaction
(when @chat
(let [current-participants (->> @chat
:contacts
(map :identity))]
(contacts-list-include current-participants)))))))
(contacts-by-current-chat filter db)))
(register-sub :db
(fn [db _] (reaction @db)))

View File

@ -5,12 +5,6 @@
(defn to-datasource [items]
(clone-with-rows (data-source {:rowHasChanged not=}) items))
(defn to-realm-datasource [items]
(-> (cljs.core/clj->js {:rowHasChanged not=})
(js/RealmReactNative.ListView.DataSource.)
(clone-with-rows items)))
(defn clone-with-rows2 [ds rows]
(.cloneWithRows ds (reduce (fn [ac el] (.push ac el) ac)
(clj->js []) rows)))