mirror of
https://github.com/status-im/status-react.git
synced 2025-02-02 14:14:39 +00:00
fixes and improvements for chat command
Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
parent
a06ca37de5
commit
b721f4810f
@ -118,6 +118,7 @@
|
|||||||
(assoc command-props
|
(assoc command-props
|
||||||
:input-params input-params
|
:input-params input-params
|
||||||
:current-param-position (current-param-position input-text text-selection)
|
:current-param-position (current-param-position input-text text-selection)
|
||||||
|
:cursor-in-the-end? (= (count input-text) text-selection)
|
||||||
:command-completion (command-completion input-params params)))))))
|
:command-completion (command-completion input-params params)))))))
|
||||||
|
|
||||||
(defn parse-parameters
|
(defn parse-parameters
|
||||||
@ -146,8 +147,7 @@
|
|||||||
input-text (cond-> (str command chat.constants/spacing-char
|
input-text (cond-> (str command chat.constants/spacing-char
|
||||||
(join-command-args new-params))
|
(join-command-args new-params))
|
||||||
(and (not last-param?)
|
(and (not last-param?)
|
||||||
(or (= 0 param-count)
|
(= param-index param-count))
|
||||||
(= param-index (dec param-count))))
|
|
||||||
(str chat.constants/spacing-char))]
|
(str chat.constants/spacing-char))]
|
||||||
{:db (-> db
|
{:db (-> db
|
||||||
(chat/set-chat-ui-props {:validation-messages nil})
|
(chat/set-chat-ui-props {:validation-messages nil})
|
||||||
@ -170,3 +170,8 @@
|
|||||||
[{:keys [db] :as cofx} command-message-id]
|
[{:keys [db] :as cofx} command-message-id]
|
||||||
(let [current-chat-id (:current-chat-id db)]
|
(let [current-chat-id (:current-chat-id db)]
|
||||||
{:db (assoc-in db [:chats current-chat-id :metadata :responding-to-command] command-message-id)}))
|
{:db (assoc-in db [:chats current-chat-id :metadata :responding-to-command] command-message-id)}))
|
||||||
|
|
||||||
|
(fx/defn clean-custom-params
|
||||||
|
[{:keys [db] :as cofx}]
|
||||||
|
(let [current-chat-id (:current-chat-id db)]
|
||||||
|
{:db (assoc-in db [:chats current-chat-id :custom-params] nil)}))
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
#(protocol/on-send type command-message %)
|
#(protocol/on-send type command-message %)
|
||||||
(commands.input/set-command-reference nil)
|
(commands.input/set-command-reference nil)
|
||||||
|
(commands.input/clean-custom-params)
|
||||||
(chat.message/send-message command-message)))))))
|
(chat.message/send-message command-message)))))))
|
||||||
|
|
||||||
(fx/defn send
|
(fx/defn send
|
||||||
@ -48,4 +49,5 @@
|
|||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
#(protocol/on-send type (commands/enrich-command-message-for-events db command-message) %)
|
#(protocol/on-send type (commands/enrich-command-message-for-events db command-message) %)
|
||||||
(commands.input/set-command-reference nil)
|
(commands.input/set-command-reference nil)
|
||||||
(chat.message/send-message command-message))))
|
(commands.input/clean-custom-params)
|
||||||
|
(chat.message/send-message command-message))))
|
@ -233,8 +233,8 @@
|
|||||||
:chats/input-placeholder
|
:chats/input-placeholder
|
||||||
:<- [:chats/current-chat]
|
:<- [:chats/current-chat]
|
||||||
:<- [:chats/selected-chat-command]
|
:<- [:chats/selected-chat-command]
|
||||||
(fn [[{:keys [input-text]} {:keys [params current-param-position]}]]
|
(fn [[{:keys [input-text]} {:keys [params current-param-position cursor-in-the-end?]}]]
|
||||||
(when (string/ends-with? (or input-text "") chat.constants/spacing-char)
|
(when (and cursor-in-the-end? (string/ends-with? (or input-text "") chat.constants/spacing-char))
|
||||||
(get-in params [current-param-position :placeholder]))))
|
(get-in params [current-param-position :placeholder]))))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
(defview parameter-box-container []
|
(defview parameter-box-container []
|
||||||
(letsubs [parameter-box [:chats/parameter-box]]
|
(letsubs [parameter-box [:chats/parameter-box]]
|
||||||
(when parameter-box
|
(when parameter-box
|
||||||
[react/view style/root
|
[react/view
|
||||||
[parameter-box]])))
|
[parameter-box]])))
|
||||||
|
|
||||||
(defview parameter-box-view []
|
(defview parameter-box-view []
|
||||||
|
@ -19,6 +19,10 @@
|
|||||||
:bottom bottom
|
:bottom bottom
|
||||||
:position :absolute
|
:position :absolute
|
||||||
:elevation 2
|
:elevation 2
|
||||||
|
:shadow-offset {:width 0 :height 1}
|
||||||
|
:shadow-radius 12
|
||||||
|
:shadow-opacity 0.12
|
||||||
|
:shadow-color colors/white
|
||||||
:max-height max-height})
|
:max-height max-height})
|
||||||
|
|
||||||
(def header-container
|
(def header-container
|
||||||
|
@ -60,7 +60,7 @@
|
|||||||
[:db :chats "test" :input-text])))
|
[:db :chats "test" :input-text])))
|
||||||
(is (= "/test-command first-value second-value \"last value\""
|
(is (= "/test-command first-value second-value \"last value\""
|
||||||
(get-in (input/set-command-parameter (create-cofx "/test-command first-value second-value")
|
(get-in (input/set-command-parameter (create-cofx "/test-command first-value second-value")
|
||||||
false 2 "last value")
|
true 2 "last value")
|
||||||
[:db :chats "test" :input-text]))))))
|
[:db :chats "test" :input-text]))))))
|
||||||
|
|
||||||
(deftest parse-parameters-test
|
(deftest parse-parameters-test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user