parent
0af746b06b
commit
d3b48f156c
|
@ -32,7 +32,8 @@
|
||||||
(add-event-listener "hardwareBackPress" new-listener)))))
|
(add-event-listener "hardwareBackPress" new-listener)))))
|
||||||
|
|
||||||
(defn app-root []
|
(defn app-root []
|
||||||
[navigator {:initial-route (clj->js {:view-id :chat-list})
|
[navigator {:initial-route (clj->js {:view-id ;:chat-list
|
||||||
|
:chat})
|
||||||
:render-scene (fn [route nav]
|
:render-scene (fn [route nav]
|
||||||
(log/debug "route" route)
|
(log/debug "route" route)
|
||||||
(when true ;; nav/*nav-render*
|
(when true ;; nav/*nav-render*
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
(ns syng-im.components.chat.suggestions
|
||||||
|
(:require-macros
|
||||||
|
[natal-shell.core :refer [with-error-view]])
|
||||||
|
(:require [clojure.string :as cstr]
|
||||||
|
[reagent.core :as r]
|
||||||
|
[re-frame.core :refer [subscribe dispatch dispatch-sync]]
|
||||||
|
[syng-im.components.react :refer [view
|
||||||
|
image
|
||||||
|
text
|
||||||
|
list-view
|
||||||
|
list-item]]
|
||||||
|
[syng-im.utils.listview :refer [to-datasource]]
|
||||||
|
[syng-im.utils.utils :refer [log toast http-post]]
|
||||||
|
[syng-im.utils.logging :as log]))
|
||||||
|
|
||||||
|
(defn suggestion-list-item [suggestion]
|
||||||
|
[view {:style {:flexDirection "row"
|
||||||
|
:marginVertical 5
|
||||||
|
:marginHorizontal 10
|
||||||
|
:height 20
|
||||||
|
;; :backgroundColor "white"
|
||||||
|
}}
|
||||||
|
[text {:underlineColorAndroid "#9CBFC0"
|
||||||
|
:style {:flex 1
|
||||||
|
:marginLeft 18
|
||||||
|
:lineHeight 18
|
||||||
|
:fontSize 14
|
||||||
|
:fontFamily "Avenir-Roman"
|
||||||
|
:color "#9CBFC0"}}
|
||||||
|
(:text suggestion)]])
|
||||||
|
|
||||||
|
(defn render-row [row section-id row-id]
|
||||||
|
(list-item [suggestion-list-item (js->clj row :keywordize-keys true)]))
|
||||||
|
|
||||||
|
(defn suggestions-view []
|
||||||
|
(let [suggestions (subscribe [:get-suggestions])]
|
||||||
|
(fn []
|
||||||
|
(when @suggestions
|
||||||
|
[view {:style {:flexDirection "row"
|
||||||
|
:marginVertical 5
|
||||||
|
:marginHorizontal 10
|
||||||
|
:height 120
|
||||||
|
:backgroundColor "#E5F5F6"
|
||||||
|
:borderRadius 5}}
|
||||||
|
[list-view {:dataSource (to-datasource @suggestions)
|
||||||
|
:renderRow render-row
|
||||||
|
:style {}}]]))))
|
|
@ -4,6 +4,7 @@
|
||||||
view
|
view
|
||||||
image
|
image
|
||||||
text-input]]
|
text-input]]
|
||||||
|
[syng-im.components.chat.suggestions :refer [suggestions-view]]
|
||||||
[syng-im.utils.logging :as log]
|
[syng-im.utils.logging :as log]
|
||||||
[syng-im.resources :as res]
|
[syng-im.resources :as res]
|
||||||
[reagent.core :as r]))
|
[reagent.core :as r]))
|
||||||
|
@ -13,39 +14,42 @@
|
||||||
(let [text (r/atom nil)
|
(let [text (r/atom nil)
|
||||||
chat-id (subscribe [:get-current-chat-id])]
|
chat-id (subscribe [:get-current-chat-id])]
|
||||||
(fn []
|
(fn []
|
||||||
[view {:style {:flexDirection "row"
|
[view {:style {:flexDirection "column"}}
|
||||||
:margin 10
|
[view {:style {:flexDirection "row"
|
||||||
:height 40
|
:margin 10
|
||||||
:backgroundColor "#E5F5F6"
|
:height 40
|
||||||
:borderRadius 5}}
|
:backgroundColor "#E5F5F6"
|
||||||
[image {:source res/mic
|
:borderRadius 5}}
|
||||||
:style {:marginTop 11
|
[image {:source res/mic
|
||||||
:marginLeft 14
|
:style {:marginTop 11
|
||||||
:width 13
|
:marginLeft 14
|
||||||
:height 20}}]
|
:width 13
|
||||||
[text-input {:underlineColorAndroid "#9CBFC0"
|
:height 20}}]
|
||||||
:style {:flex 1
|
[text-input {:underlineColorAndroid "#9CBFC0"
|
||||||
:marginLeft 18
|
:style {:flex 1
|
||||||
:lineHeight 42
|
:marginLeft 18
|
||||||
:fontSize 14
|
:lineHeight 42
|
||||||
:fontFamily "Avenir-Roman"
|
:fontSize 14
|
||||||
:color "#9CBFC0"}
|
:fontFamily "Avenir-Roman"
|
||||||
:autoFocus true
|
:color "#9CBFC0"}
|
||||||
:placeholder "Enter your message here"
|
:autoFocus true
|
||||||
:value @text
|
:placeholder "Enter your message here"
|
||||||
:onChangeText (fn [new-text]
|
:value @text
|
||||||
(reset! text new-text)
|
:onChangeText (fn [new-text]
|
||||||
(r/flush))
|
(dispatch [:generate-suggestions new-text])
|
||||||
:onSubmitEditing (fn [e]
|
(reset! text new-text)
|
||||||
(dispatch [:send-chat-msg @chat-id @text])
|
(r/flush))
|
||||||
(reset! text nil))}]
|
:onSubmitEditing (fn [e]
|
||||||
[image {:source res/smile
|
(dispatch [:send-chat-msg @chat-id @text])
|
||||||
:style {:marginTop 11
|
(reset! text nil))}]
|
||||||
:marginRight 12
|
[image {:source res/smile
|
||||||
:width 18
|
:style {:marginTop 11
|
||||||
:height 18}}]
|
:marginRight 12
|
||||||
[image {:source res/att
|
:width 18
|
||||||
:style {:marginTop 14
|
:height 18}}]
|
||||||
:marginRight 16
|
[image {:source res/att
|
||||||
:width 17
|
:style {:marginTop 14
|
||||||
:height 14}}]])))
|
:marginRight 16
|
||||||
|
:width 17
|
||||||
|
:height 14}}]]
|
||||||
|
[suggestions-view]])))
|
||||||
|
|
|
@ -8,11 +8,7 @@
|
||||||
list-item]]
|
list-item]]
|
||||||
[syng-im.components.resources :as res]
|
[syng-im.components.resources :as res]
|
||||||
[syng-im.components.contact-list.contact :refer [contact-view]]
|
[syng-im.components.contact-list.contact :refer [contact-view]]
|
||||||
[syng-im.utils.logging :as log]
|
[syng-im.utils.logging :as log]))
|
||||||
;; [messenger.comm.intercom :as intercom]
|
|
||||||
;; [messenger.components.contact-list.contact :refer [contact]]
|
|
||||||
;; [messenger.components.iname :as in]
|
|
||||||
))
|
|
||||||
|
|
||||||
(defn render-row [navigator row section-id row-id]
|
(defn render-row [navigator row section-id row-id]
|
||||||
(list-item [contact-view {:navigator navigator
|
(list-item [contact-view {:navigator navigator
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
(def ethereum-rpc-url "http://localhost:8545")
|
(def ethereum-rpc-url "http://localhost:8545")
|
||||||
|
|
||||||
;; (def server-address "http://rpc0.syng.im:20000/")
|
(def server-address "http://rpc0.syng.im:20000/")
|
||||||
(def server-address "http://10.0.3.2:3000/")
|
;; (def server-address "http://10.0.3.2:3000/")
|
||||||
|
|
||||||
(def text-content-type "text/plain")
|
(def text-content-type "text/plain")
|
||||||
|
|
|
@ -7,8 +7,9 @@
|
||||||
;; initial state of app-db
|
;; initial state of app-db
|
||||||
(def app-db {:greeting "Hello Clojure in iOS and Android!"
|
(def app-db {:greeting "Hello Clojure in iOS and Android!"
|
||||||
:identity-password "replace-me-with-user-entered-password"
|
:identity-password "replace-me-with-user-entered-password"
|
||||||
:contacts []
|
:contacts []
|
||||||
:chat {:current-chat-id "0x0479a5ed1f38cadfad1db6cd56c4b659b0ebe052bbe9efa950f6660058519fa4ca6be2dda66afa80de96ab00eb97a2605d5267a1e8f4c2a166ab551f6826608cdd"}
|
:chat {:current-chat-id "0x0479a5ed1f38cadfad1db6cd56c4b659b0ebe052bbe9efa950f6660058519fa4ca6be2dda66afa80de96ab00eb97a2605d5267a1e8f4c2a166ab551f6826608cdd"
|
||||||
|
:suggestions []}
|
||||||
:chats {}
|
:chats {}
|
||||||
:chats-updated-signal 0})
|
:chats-updated-signal 0})
|
||||||
|
|
||||||
|
@ -16,6 +17,7 @@
|
||||||
(def protocol-initialized-path [:protocol-initialized])
|
(def protocol-initialized-path [:protocol-initialized])
|
||||||
(def identity-password-path [:identity-password])
|
(def identity-password-path [:identity-password])
|
||||||
(def current-chat-id-path [:chat :current-chat-id])
|
(def current-chat-id-path [:chat :current-chat-id])
|
||||||
|
(def input-suggestions-path [:chat :suggestions])
|
||||||
(def updated-chats-signal-path [:chats-updated-signal])
|
(def updated-chats-signal-path [:chats-updated-signal])
|
||||||
(defn updated-chat-signal-path [chat-id]
|
(defn updated-chat-signal-path [chat-id]
|
||||||
[:chats chat-id :chat-updated-signal])
|
[:chats chat-id :chat-updated-signal])
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
message-by-id]]
|
message-by-id]]
|
||||||
[syng-im.handlers.server :as server]
|
[syng-im.handlers.server :as server]
|
||||||
[syng-im.handlers.contacts :as contacts-service]
|
[syng-im.handlers.contacts :as contacts-service]
|
||||||
|
[syng-im.handlers.suggestions :as suggestions-service]
|
||||||
|
|
||||||
[syng-im.models.chats :refer [create-chat]]
|
[syng-im.models.chats :refer [create-chat]]
|
||||||
[syng-im.models.chat :refer [signal-chat-updated
|
[syng-im.models.chat :refer [signal-chat-updated
|
||||||
|
@ -143,3 +144,9 @@
|
||||||
(log/debug action "chat-id" chat-id)
|
(log/debug action "chat-id" chat-id)
|
||||||
(nav-push navigator {:view-id :chat})
|
(nav-push navigator {:view-id :chat})
|
||||||
(set-current-chat-id db chat-id)))
|
(set-current-chat-id db chat-id)))
|
||||||
|
|
||||||
|
;; -- Chat --------------------------------------------------------------
|
||||||
|
|
||||||
|
(register-handler :generate-suggestions
|
||||||
|
(fn [db [_ text]]
|
||||||
|
(suggestions-service/generate-suggestions db text)))
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
(ns syng-im.handlers.suggestions
|
||||||
|
(:require [re-frame.core :refer [subscribe dispatch dispatch-sync]]
|
||||||
|
[syng-im.db :as db]
|
||||||
|
[syng-im.utils.utils :refer [log on-error http-post]]
|
||||||
|
[syng-im.utils.logging :as log]))
|
||||||
|
|
||||||
|
(def commands [{:text "!phone"}
|
||||||
|
{:text "!send"}
|
||||||
|
{:text "!request"}
|
||||||
|
{:text "!help"}])
|
||||||
|
|
||||||
|
(defn get-suggestions [text]
|
||||||
|
(when (= (get text 0) "!")
|
||||||
|
(filterv #(.startsWith (:text %) text) commands)))
|
||||||
|
|
||||||
|
(defn generate-suggestions [db text]
|
||||||
|
(assoc-in db db/input-suggestions-path (get-suggestions text)))
|
|
@ -1,6 +1,7 @@
|
||||||
(ns syng-im.subs
|
(ns syng-im.subs
|
||||||
(:require-macros [reagent.ratom :refer [reaction]])
|
(:require-macros [reagent.ratom :refer [reaction]])
|
||||||
(:require [re-frame.core :refer [register-sub]]
|
(:require [re-frame.core :refer [register-sub]]
|
||||||
|
[syng-im.db :as db]
|
||||||
[syng-im.models.chat :refer [current-chat-id
|
[syng-im.models.chat :refer [current-chat-id
|
||||||
chat-updated?]]
|
chat-updated?]]
|
||||||
[syng-im.models.chats :refer [chats-list
|
[syng-im.models.chats :refer [chats-list
|
||||||
|
@ -24,6 +25,10 @@
|
||||||
(-> (current-chat-id @db)
|
(-> (current-chat-id @db)
|
||||||
(reaction))))
|
(reaction))))
|
||||||
|
|
||||||
|
(register-sub :get-suggestions
|
||||||
|
(fn [db _]
|
||||||
|
(reaction (get-in @db db/input-suggestions-path))))
|
||||||
|
|
||||||
;; -- Chats list --------------------------------------------------------------
|
;; -- Chats list --------------------------------------------------------------
|
||||||
|
|
||||||
(register-sub :get-chats
|
(register-sub :get-chats
|
||||||
|
|
Loading…
Reference in New Issue