parent
d3b48f156c
commit
fddf80b126
|
@ -7,41 +7,54 @@
|
||||||
[syng-im.components.react :refer [view
|
[syng-im.components.react :refer [view
|
||||||
image
|
image
|
||||||
text
|
text
|
||||||
|
touchable-highlight
|
||||||
list-view
|
list-view
|
||||||
list-item]]
|
list-item]]
|
||||||
[syng-im.utils.listview :refer [to-datasource]]
|
[syng-im.utils.listview :refer [to-datasource]]
|
||||||
[syng-im.utils.utils :refer [log toast http-post]]
|
[syng-im.utils.utils :refer [log toast http-post]]
|
||||||
[syng-im.utils.logging :as log]))
|
[syng-im.utils.logging :as log]))
|
||||||
|
|
||||||
|
(defn set-command-input [command]
|
||||||
|
(dispatch [:set-input-command command]))
|
||||||
|
|
||||||
(defn suggestion-list-item [suggestion]
|
(defn suggestion-list-item [suggestion]
|
||||||
[view {:style {:flexDirection "row"
|
[touchable-highlight {:onPress (fn []
|
||||||
:marginVertical 5
|
(set-command-input (keyword (:command suggestion))))}
|
||||||
:marginHorizontal 10
|
[view {:style {:flexDirection "row"
|
||||||
:height 20
|
:marginVertical 5
|
||||||
;; :backgroundColor "white"
|
:marginHorizontal 10
|
||||||
}}
|
:height 20
|
||||||
[text {:underlineColorAndroid "#9CBFC0"
|
;; :backgroundColor "white"
|
||||||
:style {:flex 1
|
}}
|
||||||
:marginLeft 18
|
[text {:style {:flex 1
|
||||||
:lineHeight 18
|
:marginLeft 18
|
||||||
:fontSize 14
|
:lineHeight 18
|
||||||
:fontFamily "Avenir-Roman"
|
:fontSize 14
|
||||||
:color "#9CBFC0"}}
|
:fontFamily "Avenir-Roman"
|
||||||
(:text suggestion)]])
|
:color "#9CBFC0"}}
|
||||||
|
(:text suggestion)]
|
||||||
|
[text {:style {:flex 1
|
||||||
|
:marginLeft 18
|
||||||
|
:lineHeight 18
|
||||||
|
:fontSize 14
|
||||||
|
:fontFamily "Avenir-Roman"
|
||||||
|
:color "#9CBFC0"}}
|
||||||
|
(:description suggestion)]]])
|
||||||
|
|
||||||
(defn render-row [row section-id row-id]
|
(defn render-row [row section-id row-id]
|
||||||
(list-item [suggestion-list-item (js->clj row :keywordize-keys true)]))
|
(list-item [suggestion-list-item (js->clj row :keywordize-keys true)]))
|
||||||
|
|
||||||
(defn suggestions-view []
|
(defn suggestions-view []
|
||||||
(let [suggestions (subscribe [:get-suggestions])]
|
(let [suggestions-atom (subscribe [:get-suggestions])]
|
||||||
(fn []
|
(fn []
|
||||||
(when @suggestions
|
(let [suggestions @suggestions-atom]
|
||||||
[view {:style {:flexDirection "row"
|
(when (not (empty? suggestions))
|
||||||
:marginVertical 5
|
[view {:style {:flexDirection "row"
|
||||||
:marginHorizontal 10
|
:marginVertical 5
|
||||||
:height 120
|
:marginHorizontal 10
|
||||||
:backgroundColor "#E5F5F6"
|
:height 120
|
||||||
:borderRadius 5}}
|
:backgroundColor "#E5F5F6"
|
||||||
[list-view {:dataSource (to-datasource @suggestions)
|
:borderRadius 5}}
|
||||||
:renderRow render-row
|
[list-view {:dataSource (to-datasource suggestions)
|
||||||
:style {}}]]))))
|
:renderRow render-row
|
||||||
|
:style {}}]])))))
|
||||||
|
|
|
@ -5,12 +5,12 @@
|
||||||
image
|
image
|
||||||
text-input]]
|
text-input]]
|
||||||
[syng-im.components.chat.suggestions :refer [suggestions-view]]
|
[syng-im.components.chat.suggestions :refer [suggestions-view]]
|
||||||
|
[syng-im.utils.utils :refer [log toast http-post]]
|
||||||
[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]))
|
||||||
|
|
||||||
|
(defn message-input []
|
||||||
(defn chat-message-new []
|
|
||||||
(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 []
|
||||||
|
@ -53,3 +53,32 @@
|
||||||
:width 17
|
:width 17
|
||||||
:height 14}}]]
|
:height 14}}]]
|
||||||
[suggestions-view]])))
|
[suggestions-view]])))
|
||||||
|
|
||||||
|
(defn special-input [command]
|
||||||
|
(case command
|
||||||
|
:phone [text-input {:underlineColorAndroid "#9CBFC0"
|
||||||
|
:style {:flex 1
|
||||||
|
:marginLeft 18
|
||||||
|
:lineHeight 42
|
||||||
|
:fontSize 14
|
||||||
|
:fontFamily "Avenir-Roman"
|
||||||
|
:color "#9CBFC0"}
|
||||||
|
:autoFocus true
|
||||||
|
:placeholder "Phone input"}]
|
||||||
|
[text-input {:underlineColorAndroid "#9CBFC0"
|
||||||
|
:style {:flex 1
|
||||||
|
:marginLeft 18
|
||||||
|
:lineHeight 42
|
||||||
|
:fontSize 14
|
||||||
|
:fontFamily "Avenir-Roman"
|
||||||
|
:color "#9CBFC0"}
|
||||||
|
:autoFocus true
|
||||||
|
:placeholder "Command input"}]))
|
||||||
|
|
||||||
|
(defn chat-message-new []
|
||||||
|
(let [input-command-atom (subscribe [:get-input-command])]
|
||||||
|
(fn []
|
||||||
|
(let [input-command @input-command-atom]
|
||||||
|
(if input-command
|
||||||
|
[special-input input-command]
|
||||||
|
[message-input])))))
|
||||||
|
|
|
@ -9,7 +9,8 @@
|
||||||
: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 []}
|
:suggestions []
|
||||||
|
:command nil}
|
||||||
:chats {}
|
:chats {}
|
||||||
:chats-updated-signal 0})
|
:chats-updated-signal 0})
|
||||||
|
|
||||||
|
@ -18,6 +19,7 @@
|
||||||
(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 input-suggestions-path [:chat :suggestions])
|
||||||
|
(def input-command-path [:chat :command])
|
||||||
(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])
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
[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.handlers.suggestions :as suggestions-service]
|
||||||
|
[syng-im.handlers.commands :as commands-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
|
||||||
|
@ -150,3 +151,7 @@
|
||||||
(register-handler :generate-suggestions
|
(register-handler :generate-suggestions
|
||||||
(fn [db [_ text]]
|
(fn [db [_ text]]
|
||||||
(suggestions-service/generate-suggestions db text)))
|
(suggestions-service/generate-suggestions db text)))
|
||||||
|
|
||||||
|
(register-handler :set-input-command
|
||||||
|
(fn [db [_ command]]
|
||||||
|
(commands-service/set-input-command db command)))
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
(ns syng-im.handlers.commands
|
||||||
|
(: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]))
|
||||||
|
|
||||||
|
(defn set-input-command [db command]
|
||||||
|
(assoc-in db db/input-command-path command))
|
|
@ -4,14 +4,23 @@
|
||||||
[syng-im.utils.utils :refer [log on-error http-post]]
|
[syng-im.utils.utils :refer [log on-error http-post]]
|
||||||
[syng-im.utils.logging :as log]))
|
[syng-im.utils.logging :as log]))
|
||||||
|
|
||||||
(def commands [{:text "!phone"}
|
(def commands [{:command :phone
|
||||||
{:text "!send"}
|
:text "!phone"
|
||||||
{:text "!request"}
|
:description "Send phone number"}
|
||||||
{:text "!help"}])
|
{:command :send
|
||||||
|
:text "!send"
|
||||||
|
:description "Send location"}
|
||||||
|
{:command :request
|
||||||
|
:text "!request"
|
||||||
|
:description "Send request"}
|
||||||
|
{:command :help
|
||||||
|
:text "!help"
|
||||||
|
:description "Help"}])
|
||||||
|
|
||||||
(defn get-suggestions [text]
|
(defn get-suggestions [text]
|
||||||
(when (= (get text 0) "!")
|
(if (= (get text 0) "!")
|
||||||
(filterv #(.startsWith (:text %) text) commands)))
|
(filterv #(.startsWith (:text %) text) commands)
|
||||||
|
[]))
|
||||||
|
|
||||||
(defn generate-suggestions [db text]
|
(defn generate-suggestions [db text]
|
||||||
(assoc-in db db/input-suggestions-path (get-suggestions text)))
|
(assoc-in db db/input-suggestions-path (get-suggestions text)))
|
||||||
|
|
|
@ -29,6 +29,10 @@
|
||||||
(fn [db _]
|
(fn [db _]
|
||||||
(reaction (get-in @db db/input-suggestions-path))))
|
(reaction (get-in @db db/input-suggestions-path))))
|
||||||
|
|
||||||
|
(register-sub :get-input-command
|
||||||
|
(fn [db _]
|
||||||
|
(reaction (get-in @db db/input-command-path))))
|
||||||
|
|
||||||
;; -- Chats list --------------------------------------------------------------
|
;; -- Chats list --------------------------------------------------------------
|
||||||
|
|
||||||
(register-sub :get-chats
|
(register-sub :get-chats
|
||||||
|
|
Loading…
Reference in New Issue