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

View File

@ -8,12 +8,11 @@
[syng-im.chats-list.views.inner-item :refer [syng-im.chats-list.views.inner-item :refer
[chat-list-item-inner-view]])) [chat-list-item-inner-view]]))
(defn chat-list-item [chat-obj] (defn chat-list-item [{:keys [chat-id] :as chat}]
[touchable-highlight [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 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 chat
[view [chat-list-item-inner-view (merge (js->clj chat-obj :keywordize-keys true)
{:photo-path nil {:photo-path nil
:delivery-status :seen :delivery-status :seen
:new-messages-count 3 :new-messages-count 3

View File

@ -40,42 +40,3 @@
(r/as-element component)) (r/as-element component))
(def dismiss-keyboard! (js/require "dismissKeyboard")) (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] (defn list-view [props]
[list-view-class (merge {:enableEmptySections true} 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 color-purple
text1-color text1-color
text2-color text2-color
toolbar-background1]] toolbar-background1]]))
[syng-im.utils.listview :refer [to-realm-datasource]]))
(defn toolbar [{:keys [title nav-action action background-color content style]}] (defn toolbar [{:keys [title nav-action action background-color content style]}]
(let [style (merge {:flexDirection :row (let [style (merge {:flexDirection :row

View File

@ -2,7 +2,7 @@
(:require (:require
[re-frame.core :refer [subscribe]] [re-frame.core :refer [subscribe]]
[syng-im.components.react :refer [view list-view list-item]] [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.styles :as st]
[syng-im.discovery.views.popular-list-item [syng-im.discovery.views.popular-list-item
:refer [popular-list-item]])) :refer [popular-list-item]]))

View File

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

View File

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

View File

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

View File

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

View File

@ -29,32 +29,30 @@
(reaction (:contacts @db)))) (reaction (:contacts @db))))
(register-sub :all-contacts (register-sub :all-contacts
(fn [_ _] (fn [db _]
(reaction (get-contacts)))) (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 (register-sub :all-new-contacts
(fn [db _] (fn [db _]
(let [current-chat-id (reaction (:current-chat-id @db)) (contacts-by-current-chat remove 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)))))))
(register-sub :current-chat-contacts (register-sub :current-chat-contacts
(fn [db _] (fn [db _]
(let [current-chat-id (reaction (:current-chat-id @db)) (contacts-by-current-chat filter 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)))))))
(register-sub :db (register-sub :db
(fn [db _] (reaction @db))) (fn [db _] (reaction @db)))

View File

@ -5,12 +5,6 @@
(defn to-datasource [items] (defn to-datasource [items]
(clone-with-rows (data-source {:rowHasChanged not=}) 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] (defn clone-with-rows2 [ds rows]
(.cloneWithRows ds (reduce (fn [ac el] (.push ac el) ac) (.cloneWithRows ds (reduce (fn [ac el] (.push ac el) ac)
(clj->js []) rows))) (clj->js []) rows)))