Little refactoring

Former-commit-id: a358507be4
This commit is contained in:
virvar 2016-03-29 13:07:05 +03:00
parent e7e623c659
commit d44ae85092
8 changed files with 13 additions and 261 deletions

View File

@ -9,17 +9,11 @@
[syng-im.components.react :refer [navigator app-registry]]
[syng-im.components.contact-list.contact-list :refer [contact-list]]
[syng-im.components.chat :refer [chat]]
[syng-im.components.login :refer [login-view]]
[syng-im.components.sign-up :refer [sign-up-view]]
[syng-im.components.sign-up-confirm :refer [sign-up-confirm-view]]
;; [syng-im.components.chat.chat :refer [chat]]
[syng-im.components.nav :as nav]
[syng-im.utils.logging :as log]))
;; (def ^{:dynamic true :private true} *nav-render*
;; "Flag to suppress navigator re-renders from outside om when pushing/popping."
;; true)
(def back-button-handler (cljs/atom {:nav nil
:handler nil}))
@ -37,10 +31,7 @@
(add-event-listener "hardwareBackPress" new-listener)))))
(defn app-root []
[navigator {:initial-route (clj->js {:view-id ;; :chat
;; :contact-list
:login
})
[navigator {:initial-route (clj->js {:view-id :sign-up})
:render-scene (fn [route nav]
(log/debug "route" route)
(when true ;; nav/*nav-render*
@ -51,7 +42,8 @@
:contact-list (r/as-element [contact-list
{:navigator nav}])
:chat (r/as-element [chat {:navigator nav}])
:login (r/as-element [login-view {:navigator nav}])
:sign-up (r/as-element [sign-up-view
{:navigator nav}])
:sign-up-confirm (r/as-element [sign-up-confirm-view
{:navigator nav}])))))}])

View File

@ -1,79 +0,0 @@
(ns syng-im.components.chat.chat
(:require-macros
[natal-shell.data-source :refer [data-source clone-with-rows]])
(:require [reagent.core :as r]
[syng-im.components.nav :as nav]
[syng-im.components.react :refer [view list-view toolbar-android list-item]]
[syng-im.components.resources :as res]
[syng-im.components.invertible-scroll-view :refer [invertible-scroll-view]]
;; [syng-im.components.chat.message :refer [message]]
;; [syng-im.components.chat.new-message :refer [new-message NewMessage]]
))
;(defn generate-message [n]
; {:id n
; :type (if (= (rem n 4) 3)
; :audio
; :text)
; :body (if (= (rem n 3) 0)
; (apply str n "." (repeat 5 " This is a text."))
; (str n ". This is a text."))
; :outgoing (< (rand) 0.5)
; :delivery-status (if (< (rand) 0.5) :delivered :seen)
; :date "TODAY"
; :new-day (= (rem n 3) 0)})
;
;(defn generate-messages [n]
; (map generate-message (range 1 (inc n))))
;(defn load-messages []
; (clone-with-rows (data-source {:rowHasChanged (fn [row1 row2]
; (not= row1 row2))})
; (vec (generate-messages 100))))
;
;;temp
;; (swap! state/app-state assoc :abc "xyz")
(defn to-datasource [msgs]
(-> (data-source {:rowHasChanged (fn [row1 row2]
(not= row1 row2))})
(clone-with-rows msgs)))
(defn render-row [row section-id row-id]
(list-item [message-view {} (js->clj row :keywordize-keys true)]))
(defn chat [{:keys [navigator]}]
(let [greeting (subscribe [:get-greeting])
chat-id 1
;; messages (subscribe [:get-messages chat-id])
]
(fn []
(let [messages-ds (when messages
(to-datasource messages))]
[view {:style {:flex 1
:backgroundColor "white"}}
[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/nav-pop nav))}]
;; temp commented
;; (when messages-ds
;; [list-view {:dataSource messages-ds
;; :renderScrollComponent
;; (fn [props]
;; (r/as-element [invertible-scroll-view {:inverted true}]))
;; :renderRow render-row
;; :style {:backgroundColor "white"}}])
;; (new-message {:chat-id chat-id})
]))))

View File

@ -1,99 +0,0 @@
(ns syng-im.components.chat.message
(:require [re-frame.core :refer [subscribe dispatch dispatch-sync]]
[syng-im.components.react :refer [view text image]]
[syng-im.components.resources :as res]
[syng-im.constants :refer [text-content-type]]))
(defn message-view []
(let [greeting (subscribe [:get-greeting])]
(fn []
(let [msg-id "1"
content "1"
content-type "1"
outgoing true
delivery-status :seen
date "1"
new-day true]
[view {:paddingHorizontal 15}
(when new-day
[text {:style {:marginVertical 10
:fontFamily "Avenir-Roman"
:fontSize 11
:color "#AAB2B2"
:letterSpacing 1
:lineHeight 15
:textAlign "center"
:opacity 0.8}}
date])
[view {:style (merge {:flexDirection "column"
:width 260
:marginVertical 5}
(if outgoing
{:alignSelf "flex-end"
:alignItems "flex-end"}
{:alignSelf "flex-start"
:alignItems "flex-start"}))}
[view {:style (merge {:borderRadius 6}
(if (= content-type text-content-type)
{:paddingVertical 12
:paddingHorizontal 16}
{:paddingVertical 14
:paddingHorizontal 10})
(if outgoing
{:backgroundColor "#D3EEEF"}
{:backgroundColor "#FBF6E3"}))}
(if (= content-type text-content-type)
[text {:style {:fontSize 14
:fontFamily "Avenir-Roman"
:color "#4A5258"}}
content]
[view {:style {:flexDirection "row"
:alignItems "center"}}
[view {:style {:width 33
:height 33
:borderRadius 50
:elevation 1}}
[image {:source res/play
:style {:width 33
:height 33}}]]
[view {:style {:marginTop 10
:marginLeft 10
:width 120
:height 26
:elevation 1}}
[view {:style {:position "absolute"
:top 4
:width 120
:height 2
:backgroundColor "#EC7262"}}]
[view {:style {:position "absolute"
:left 0
:top 0
:width 2
:height 10
:backgroundColor "#4A5258"}}]
[text {:style {:position "absolute"
:left 1
:top 11
:fontFamily "Avenir-Roman"
:fontSize 11
:color "#4A5258"
:letterSpacing 1
:lineHeight 15}}
"03:39"]]])]
(when (and outgoing delivery-status)
[view {:style {:flexDirection "row"
:marginTop 2}}
[image {:source (if (= (keyword delivery-status) :seen)
res/seen-icon
res/delivered-icon)
:style {:marginTop 6
:opacity 0.6}}]
[text {:style {:fontFamily "Avenir-Roman"
:fontSize 11
:color "#AAB2B2"
:opacity 0.8
:marginLeft 5}}
(if (= (keyword delivery-status) :seen)
"Seen"
"Delivered")]])]]))))

View File

@ -1,53 +0,0 @@
(ns syng-im.components.chat.new-message
;; (:require [syng-im.components.react :refer [view text image text-input]]
;; [syng-im.components.resources :as res]
;; [syng-im.constants :refer [text-content-type]])
)
;; (defui NewMessage
;; static om/IQuery
;; (query [this]
;; '[:chat/chat-id])
;; Object
;; (render [this]
;; (view {:style {:flexDirection "row"
;; :margin 10
;; :height 40
;; :backgroundColor "#E5F5F6"
;; :borderRadius 5}}
;; (image {:source res/mic
;; :style {:marginTop 11
;; :marginLeft 14
;; :width 13
;; :height 20}})
;; (text-input {:underlineColorAndroid "#9CBFC0"
;; :style {:flex 1
;; :marginLeft 18
;; :lineHeight 42
;; :fontSize 14
;; :fontFamily "Avenir-Roman"
;; :color "#9CBFC0"}
;; :autoFocus true
;; :placeholder "Enter your message here"
;; :value (from-state this :text)
;; :onChangeText (fn [text]
;; ;(log/debug (with-out-str (pr (js->clj (om/props this)))) (-> (om/props this) :chat-id))
;; ;(om/set-state! this (clj->js {:text text}))
;; (swap! local-state assoc :text text)
;; )
;; :onSubmitEditing (fn [e]
;; (let [chat-id (-> (om/props this) :chat-id)
;; ;text (from-state this :text)
;; text (get @local-state :text)]
;; ;(om/set-state! this (clj->js {:text nil}))
;; (send-msg chat-id text)))})
;; (image {:source res/smile
;; :style {:marginTop 11
;; :marginRight 12
;; :width 18
;; :height 18}})
;; (image {:source res/att
;; :style {:marginTop 14
;; :marginRight 16
;; :width 17
;; :height 14}}))))

View File

@ -1,9 +1,6 @@
(ns syng-im.components.invertible-scroll-view
(:require [reagent.core :as r]))
(set! js/InvertibleScrollView (js/require "react-native-invertible-scroll-view"))
(def react-invertible-scroll-view (js/require "react-native-invertible-scroll-view"))
(def invertible-scroll-view (r/adapt-react-class js/Spinner))
;; (defn invertible-scroll-view [props]
;; (js/React.createElement js/InvertibleScrollView
;; (clj->js (merge {:inverted true} props))))
(def invertible-scroll-view (r/adapt-react-class react-invertible-scroll-view))

View File

@ -1,4 +1,4 @@
(ns syng-im.components.login
(ns syng-im.components.sign-up
(:require [re-frame.core :refer [subscribe dispatch dispatch-sync]]
[syng-im.components.react :refer [view text image touchable-highlight
toolbar-android text-input]]
@ -8,12 +8,9 @@
[syng-im.utils.utils :refer [log toast http-post]]
[syng-im.utils.phone-number :refer [format-phone-number]]))
;; (def nav-atom (atom nil))
(defn show-confirm-view [navigator]
(dispatch [:set-loading false])
;; TODO 'nav-replace
(nav/nav-push navigator {:view-id :sign-up-confirm}))
(nav/nav-replace navigator {:view-id :sign-up-confirm}))
(defn sign-up [user-phone-number user-identity navigator]
(dispatch [:set-loading true])
@ -23,7 +20,7 @@
(let [formatted (format-phone-number value)]
(dispatch [:set-user-phone-number formatted])))
(defn login-view [{:keys [navigator]}]
(defn sign-up-view [{:keys [navigator]}]
(let [loading (subscribe [:get-loading])
user-phone-number (subscribe [:get-user-phone-number])
user-identity (subscribe [:get-user-identity])]
@ -33,7 +30,7 @@
[view {:style {:flex 1
:backgroundColor "white"}}
[toolbar-android {:logo res/logo-icon
:title "Login"
:title "Sign up"
:titleColor "#4A5258"
:style {:backgroundColor "white"
:height 56

View File

@ -11,7 +11,7 @@
(defn show-home-view [navigator]
(dispatch [:set-loading false])
(nav/nav-push navigator {:view-id :contact-list}))
(nav/nav-replace navigator {:view-id :contact-list}))
(defn sync-contacts [navigator]
(dispatch [:sync-contacts #(show-home-view navigator)]))

View File

@ -1,9 +1,6 @@
(ns syng-im.components.spinner
(:require [reagent.core :as r]))
(set! js/Spinner (.-default (js/require "react-native-loading-spinner-overlay")))
(def react-spinner (.-default (js/require "react-native-loading-spinner-overlay")))
(def spinner (r/adapt-react-class js/Spinner))
;; (defn spinner [props]
;; (js/React.createElement js/Spinner
;; (clj->js props)))
(def spinner (r/adapt-react-class react-spinner))