Start special (command) input

Former-commit-id: 21178a625d
This commit is contained in:
virvar 2016-03-30 16:40:08 +03:00
parent d3b48f156c
commit fddf80b126
7 changed files with 104 additions and 34 deletions

View File

@ -7,41 +7,54 @@
[syng-im.components.react :refer [view
image
text
touchable-highlight
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 set-command-input [command]
(dispatch [:set-input-command command]))
(defn suggestion-list-item [suggestion]
[touchable-highlight {:onPress (fn []
(set-command-input (keyword (:command suggestion))))}
[view {:style {:flexDirection "row"
:marginVertical 5
:marginHorizontal 10
:height 20
;; :backgroundColor "white"
}}
[text {:underlineColorAndroid "#9CBFC0"
:style {:flex 1
[text {:style {:flex 1
:marginLeft 18
:lineHeight 18
:fontSize 14
:fontFamily "Avenir-Roman"
:color "#9CBFC0"}}
(:text suggestion)]])
(: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]
(list-item [suggestion-list-item (js->clj row :keywordize-keys true)]))
(defn suggestions-view []
(let [suggestions (subscribe [:get-suggestions])]
(let [suggestions-atom (subscribe [:get-suggestions])]
(fn []
(when @suggestions
(let [suggestions @suggestions-atom]
(when (not (empty? suggestions))
[view {:style {:flexDirection "row"
:marginVertical 5
:marginHorizontal 10
:height 120
:backgroundColor "#E5F5F6"
:borderRadius 5}}
[list-view {:dataSource (to-datasource @suggestions)
[list-view {:dataSource (to-datasource suggestions)
:renderRow render-row
:style {}}]]))))
:style {}}]])))))

View File

@ -5,12 +5,12 @@
image
text-input]]
[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.resources :as res]
[reagent.core :as r]))
(defn chat-message-new []
(defn message-input []
(let [text (r/atom nil)
chat-id (subscribe [:get-current-chat-id])]
(fn []
@ -53,3 +53,32 @@
:width 17
:height 14}}]]
[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])))))

View File

@ -9,7 +9,8 @@
:identity-password "replace-me-with-user-entered-password"
:contacts []
:chat {:current-chat-id "0x0479a5ed1f38cadfad1db6cd56c4b659b0ebe052bbe9efa950f6660058519fa4ca6be2dda66afa80de96ab00eb97a2605d5267a1e8f4c2a166ab551f6826608cdd"
:suggestions []}
:suggestions []
:command nil}
:chats {}
:chats-updated-signal 0})
@ -18,6 +19,7 @@
(def identity-password-path [:identity-password])
(def current-chat-id-path [:chat :current-chat-id])
(def input-suggestions-path [:chat :suggestions])
(def input-command-path [:chat :command])
(def updated-chats-signal-path [:chats-updated-signal])
(defn updated-chat-signal-path [chat-id]
[:chats chat-id :chat-updated-signal])

View File

@ -15,6 +15,7 @@
[syng-im.handlers.server :as server]
[syng-im.handlers.contacts :as contacts-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.chat :refer [signal-chat-updated
@ -150,3 +151,7 @@
(register-handler :generate-suggestions
(fn [db [_ text]]
(suggestions-service/generate-suggestions db text)))
(register-handler :set-input-command
(fn [db [_ command]]
(commands-service/set-input-command db command)))

View File

@ -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))

View File

@ -4,14 +4,23 @@
[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"}])
(def commands [{:command :phone
:text "!phone"
:description "Send phone number"}
{:command :send
:text "!send"
:description "Send location"}
{:command :request
:text "!request"
:description "Send request"}
{:command :help
:text "!help"
:description "Help"}])
(defn get-suggestions [text]
(when (= (get text 0) "!")
(filterv #(.startsWith (:text %) text) commands)))
(if (= (get text 0) "!")
(filterv #(.startsWith (:text %) text) commands)
[]))
(defn generate-suggestions [db text]
(assoc-in db db/input-suggestions-path (get-suggestions text)))

View File

@ -29,6 +29,10 @@
(fn [db _]
(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 --------------------------------------------------------------
(register-sub :get-chats