Default command input

This commit is contained in:
virvar 2016-04-01 11:58:42 +03:00
parent 7f761944a9
commit 1ed93ffd49
7 changed files with 156 additions and 175 deletions

View File

@ -1,83 +1,27 @@
(ns syng-im.components.chat.chat-message-new
(:require [re-frame.core :refer [subscribe dispatch dispatch-sync]]
[syng-im.components.react :refer [android?
view
image
text
text-input
touchable-highlight]]
[syng-im.components.chat.plain-message-input :refer [plain-message-input-view]]
[syng-im.components.chat.phone-input :refer [phone-input-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]))
(:require
[re-frame.core :refer [subscribe dispatch dispatch-sync]]
[syng-im.components.react :refer [android?
view
image
text
text-input
touchable-highlight]]
[syng-im.components.chat.plain-message-input :refer [plain-message-input-view]]
[syng-im.components.chat.simple-command-input :refer [simple-command-input-view]]
[syng-im.components.chat.phone-input :refer [phone-input-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 cancel-command-input []
(dispatch [:set-input-command nil]))
(defn default-command-input-view []
(let [message-atom (r/atom nil)
chat-id (subscribe [:get-current-chat-id])]
(fn []
(let [message @message-atom]
[view {:style {:flexDirection "row"}}
[view {:style {:flexDirection "column"
:backgroundColor "white"}}
[view {:style {:flexDirection "column"
:margin 10
:width 200
:backgroundColor "#E5F5F6"
:borderRadius 10}}
[view {:style {:flexDirection "row"}}
[view {:style {:flexDirection "column"
:margin 10
:backgroundColor "blue"
:borderRadius 10}}
[text {:style {:marginVertical 3
:marginHorizontal 10
:fontSize 14
:fontFamily "Avenir-Roman"
:color "white"}}
"!<command>"]]
[touchable-highlight {:style {:marginTop 14
:marginRight 16
:position "absolute"
:top 3
:right 20}
:onPress (fn []
(cancel-command-input))}
[image {:source res/att
:style {:width 17
:height 14}}]]]
[text-input {:style {:flex 1
:marginLeft 8
:lineHeight 42
:fontSize 14
:fontFamily "Avenir-Roman"
:color "#9CBFC0"}
:underlineColorAndroid "transparent"
:autoFocus true
:value message
:onChangeText (fn [new-text]
)
:onSubmitEditing (fn [e]
)}]]]
[touchable-highlight {:style {:marginTop 14
:marginRight 16
:position "absolute"
:right 20
:bottom 20}
:onPress (fn []
(cancel-command-input))}
[image {:source res/att
:style {:width 34
:height 28}}]]]))))
(defn default-command-input-view [command]
[simple-command-input-view command "default"])
(defn special-input-view [command]
(case command
:phone [phone-input-view]
[default-command-input-view]))
(case (:command command)
:phone [phone-input-view command]
[default-command-input-view command]))
(defn chat-message-new []
(let [input-command-atom (subscribe [:get-input-command])]

View File

@ -1,74 +1,9 @@
(ns syng-im.components.chat.phone-input
(:require [re-frame.core :refer [subscribe dispatch dispatch-sync]]
[syng-im.components.react :refer [android?
view
image
text
text-input
touchable-highlight]]
[syng-im.utils.utils :refer [log toast http-post]]
[syng-im.utils.logging :as log]
[syng-im.resources :as res]
[reagent.core :as r]))
(:require
[re-frame.core :refer [subscribe dispatch dispatch-sync]]
[syng-im.components.chat.simple-command-input :refer [simple-command-input-view]]
[syng-im.utils.utils :refer [log toast http-post]]
[syng-im.utils.logging :as log]))
(defn cancel-command-input []
(dispatch [:set-input-command nil]))
(defn phone-input-view []
(let [message-atom (r/atom nil)
chat-id (subscribe [:get-current-chat-id])]
(fn []
(let [message @message-atom]
[view {:style {:flexDirection "row"}}
[view {:style {:flexDirection "column"
:backgroundColor "white"}}
[view {:style {:flexDirection "column"
:margin 10
:width 200
:backgroundColor "#E5F5F6"
:borderRadius 10}}
[view {:style {:flexDirection "row"}}
[view {:style {:flexDirection "column"
:margin 10
:backgroundColor "blue"
:borderRadius 10}}
[text {:style {:marginVertical 3
:marginHorizontal 10
:fontSize 14
:fontFamily "Avenir-Roman"
:color "white"}}
"!phone"]]
[touchable-highlight {:style {:marginTop 14
:marginRight 16
:position "absolute"
:top 3
:right 20}
:onPress (fn []
(cancel-command-input))}
[image {:source res/att
:style {:width 17
:height 14}}]]]
[text-input {:style {:flex 1
:marginLeft 8
:lineHeight 42
:fontSize 14
:fontFamily "Avenir-Roman"
:color "#9CBFC0"}
:underlineColorAndroid "transparent"
:autoFocus true
:keyboardType "phone-pad"
:value message
:onChangeText (fn [new-text]
)
:onSubmitEditing (fn [e]
)}]]]
[touchable-highlight {:style {:marginTop 14
:marginRight 16
:position "absolute"
:right 20
:bottom 20}
:onPress (fn []
(cancel-command-input))}
[image {:source res/att
:style {:width 34
:height 28}}]]]))))
(defn phone-input-view [command]
[simple-command-input-view command "phone-pad"])

View File

@ -0,0 +1,75 @@
(ns syng-im.components.chat.simple-command-input
(:require [re-frame.core :refer [subscribe dispatch dispatch-sync]]
[syng-im.components.react :refer [android?
view
image
text
text-input
touchable-highlight]]
[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 cancel-command-input []
(dispatch [:set-input-command nil]))
(defn simple-command-input-view [command input-type]
(let [message-atom (r/atom nil)
chat-id (subscribe [:get-current-chat-id])]
(fn []
(let [message @message-atom]
[view {:style {:flexDirection "row"}}
[view {:style {:flex 1
:flexDirection "column"
:backgroundColor "white"}}
[view {:style {:flexDirection "column"
:margin 10
:width 200
:backgroundColor "#ebf0f4"
:borderRadius 10}}
[view {:style {:flexDirection "row"}}
[view {:style {:flexDirection "column"
:margin 10
:backgroundColor (:color command)
:borderRadius 10}}
[text {:style {:marginTop -2
:marginHorizontal 10
:fontSize 14
:fontFamily "Avenir-Roman"
:color "white"}}
(:text command)]]
[touchable-highlight {:style {:marginTop 14
:marginRight 16
:position "absolute"
:top 3
:right 20}
:onPress (fn []
(cancel-command-input))}
[image {:source res/att
:style {:width 17
:height 14}}]]]
[text-input {:style {:flex 1
:marginLeft 8
:lineHeight 42
:fontSize 14
:fontFamily "Avenir-Roman"
:color "#9CBFC0"}
:underlineColorAndroid "transparent"
:autoFocus true
:keyboardType input-type
:value message
:onChangeText (fn [new-text]
)
:onSubmitEditing (fn [e]
)}]]]
[touchable-highlight {:style {:marginTop 14
:marginRight 16
:position "absolute"
:right 20
:bottom 20}
:onPress (fn []
(cancel-command-input))}
[image {:source res/att
:style {:width 34
:height 28}}]]]))))

View File

@ -1,8 +1,9 @@
(ns syng-im.handlers.commands
(:require [re-frame.core :refer [subscribe dispatch dispatch-sync]]
[syng-im.db :as db]
[syng-im.models.commands :refer [get-command]]
[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))
(assoc-in db db/input-command-path (get-command command)))

View File

@ -1,36 +1,13 @@
(ns syng-im.handlers.suggestions
(:require [re-frame.core :refer [subscribe dispatch dispatch-sync]]
[syng-im.db :as db]
[syng-im.models.commands :refer [commands suggestions]]
[syng-im.utils.utils :refer [log on-error http-post]]
[syng-im.utils.logging :as log]))
(def commands [{:command :money
:text "!money"
:description "Send money"
:color "#48ba30"}
{:command :location
:text "!location"
:description "Send location"
:color "#9a5dcf"}
{:command :phone
:text "!phone"
:description "Send phone number"
:color "#48ba30"}
{:command :send
:text "!send"
:description "Send location"
:color "#9a5dcf"}
{:command :request
:text "!request"
:description "Send request"
:color "#48ba30"}
{:command :help
:text "!help"
:description "Help"
:color "#9a5dcf"}])
(defn get-suggestions [text]
(if (= (get text 0) "!")
;; TODO change 'commands' to 'suggestions'
(filterv #(.startsWith (:text %) text) commands)
[]))

View File

@ -0,0 +1,46 @@
(ns syng-im.models.commands
(:require [cljs.core.async :as async :refer [chan put! <! >!]]
[re-frame.core :refer [subscribe dispatch dispatch-sync]]
[syng-im.utils.utils :refer [log toast]]
[syng-im.persistence.realm :as realm]))
(def commands [{:command :money
:text "!money"
:description "Send money"
:color "#48ba30"
:suggestion true}
{:command :location
:text "!location"
:description "Send location"
:color "#9a5dcf"
:suggestion true}
{:command :phone
:text "!phone"
:description "Send phone number"
:color "#48ba30"
:suggestion false}
{:command :send
:text "!send"
:description "Send location"
:color "#9a5dcf"
:suggestion true}
{:command :request
:text "!request"
:description "Send request"
:color "#48ba30"
:suggestion true}
{:command :keypair-password
:text "!keypairPassword"
:description ""
:color "#019af0"
:suggestion false}
{:command :help
:text "!help"
:description "Help"
:color "#9a5dcf"
:suggestion true}])
(def suggestions (filterv :suggestion commands))
(defn get-command [command-key]
(first (filter #(= command-key (:command %)) commands)))

View File

@ -31,7 +31,10 @@
(register-sub :get-input-command
(fn [db _]
(reaction (get-in @db db/input-command-path))))
(reaction (get-in @db db/input-command-path))
;; (let [input-command-name ]
;; (reaction @input-command-name))
))
;; -- Chats list --------------------------------------------------------------