From d44ae85092af3bcdc4b59593fc7e2460d7f1f7fb Mon Sep 17 00:00:00 2001 From: virvar Date: Tue, 29 Mar 2016 13:07:05 +0300 Subject: [PATCH] Little refactoring Former-commit-id: a358507be42cfa786b515ec0af4c83e019d68bc2 --- syng-im/src/syng_im/android/core.cljs | 16 +-- syng-im/src/syng_im/components/chat/chat.cljs | 79 --------------- .../src/syng_im/components/chat/message.cljs | 99 ------------------- .../syng_im/components/chat/new_message.cljs | 53 ---------- .../components/invertible-scroll-view.cljs | 7 +- .../components/{login.cljs => sign_up.cljs} | 11 +-- .../syng_im/components/sign_up_confirm.cljs | 2 +- syng-im/src/syng_im/components/spinner.cljs | 7 +- 8 files changed, 13 insertions(+), 261 deletions(-) delete mode 100644 syng-im/src/syng_im/components/chat/chat.cljs delete mode 100644 syng-im/src/syng_im/components/chat/message.cljs delete mode 100644 syng-im/src/syng_im/components/chat/new_message.cljs rename syng-im/src/syng_im/components/{login.cljs => sign_up.cljs} (92%) diff --git a/syng-im/src/syng_im/android/core.cljs b/syng-im/src/syng_im/android/core.cljs index 5a180101aa..39b591b92a 100644 --- a/syng-im/src/syng_im/android/core.cljs +++ b/syng-im/src/syng_im/android/core.cljs @@ -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}])))))}]) diff --git a/syng-im/src/syng_im/components/chat/chat.cljs b/syng-im/src/syng_im/components/chat/chat.cljs deleted file mode 100644 index d893dd9edb..0000000000 --- a/syng-im/src/syng_im/components/chat/chat.cljs +++ /dev/null @@ -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}) - ])))) diff --git a/syng-im/src/syng_im/components/chat/message.cljs b/syng-im/src/syng_im/components/chat/message.cljs deleted file mode 100644 index 7e1b3fb7dd..0000000000 --- a/syng-im/src/syng_im/components/chat/message.cljs +++ /dev/null @@ -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")]])]])))) diff --git a/syng-im/src/syng_im/components/chat/new_message.cljs b/syng-im/src/syng_im/components/chat/new_message.cljs deleted file mode 100644 index 46c042031f..0000000000 --- a/syng-im/src/syng_im/components/chat/new_message.cljs +++ /dev/null @@ -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}})))) diff --git a/syng-im/src/syng_im/components/invertible-scroll-view.cljs b/syng-im/src/syng_im/components/invertible-scroll-view.cljs index 89065cd72e..6066fd6cc0 100644 --- a/syng-im/src/syng_im/components/invertible-scroll-view.cljs +++ b/syng-im/src/syng_im/components/invertible-scroll-view.cljs @@ -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)) diff --git a/syng-im/src/syng_im/components/login.cljs b/syng-im/src/syng_im/components/sign_up.cljs similarity index 92% rename from syng-im/src/syng_im/components/login.cljs rename to syng-im/src/syng_im/components/sign_up.cljs index 11b8df3c99..6b287fd8df 100644 --- a/syng-im/src/syng_im/components/login.cljs +++ b/syng-im/src/syng_im/components/sign_up.cljs @@ -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 diff --git a/syng-im/src/syng_im/components/sign_up_confirm.cljs b/syng-im/src/syng_im/components/sign_up_confirm.cljs index de4566824a..a694340c02 100644 --- a/syng-im/src/syng_im/components/sign_up_confirm.cljs +++ b/syng-im/src/syng_im/components/sign_up_confirm.cljs @@ -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)])) diff --git a/syng-im/src/syng_im/components/spinner.cljs b/syng-im/src/syng_im/components/spinner.cljs index 7202074a81..1526967e10 100644 --- a/syng-im/src/syng_im/components/spinner.cljs +++ b/syng-im/src/syng_im/components/spinner.cljs @@ -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))