diff --git a/syng-im/src/syng_im/components/chat/chat_message_new.cljs b/syng-im/src/syng_im/components/chat/chat_message_new.cljs index b610236392..2d90dc40dc 100644 --- a/syng-im/src/syng_im/components/chat/chat_message_new.cljs +++ b/syng-im/src/syng_im/components/chat/chat_message_new.cljs @@ -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"}} - "!"]] - [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])] diff --git a/syng-im/src/syng_im/components/chat/phone_input.cljs b/syng-im/src/syng_im/components/chat/phone_input.cljs index 8cc26340b1..b5f75fe212 100644 --- a/syng-im/src/syng_im/components/chat/phone_input.cljs +++ b/syng-im/src/syng_im/components/chat/phone_input.cljs @@ -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"]) diff --git a/syng-im/src/syng_im/components/chat/simple_command_input.cljs b/syng-im/src/syng_im/components/chat/simple_command_input.cljs new file mode 100644 index 0000000000..1aed8cebf0 --- /dev/null +++ b/syng-im/src/syng_im/components/chat/simple_command_input.cljs @@ -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}}]]])))) diff --git a/syng-im/src/syng_im/handlers/commands.cljs b/syng-im/src/syng_im/handlers/commands.cljs index 83b4f3b8a9..a305cf629a 100644 --- a/syng-im/src/syng_im/handlers/commands.cljs +++ b/syng-im/src/syng_im/handlers/commands.cljs @@ -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))) diff --git a/syng-im/src/syng_im/handlers/suggestions.cljs b/syng-im/src/syng_im/handlers/suggestions.cljs index b9468e9cac..e442e4144e 100644 --- a/syng-im/src/syng_im/handlers/suggestions.cljs +++ b/syng-im/src/syng_im/handlers/suggestions.cljs @@ -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) [])) diff --git a/syng-im/src/syng_im/models/commands.cljs b/syng-im/src/syng_im/models/commands.cljs new file mode 100644 index 0000000000..0e46eb8c33 --- /dev/null +++ b/syng-im/src/syng_im/models/commands.cljs @@ -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))) diff --git a/syng-im/src/syng_im/subs.cljs b/syng-im/src/syng_im/subs.cljs index 0d548c485b..20c120fbd5 100644 --- a/syng-im/src/syng_im/subs.cljs +++ b/syng-im/src/syng_im/subs.cljs @@ -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 --------------------------------------------------------------