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
|
||||
:input-params input-params
|
||||
: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)))))))
|
||||
|
||||
(defn parse-parameters
|
||||
|
@ -146,8 +147,7 @@
|
|||
input-text (cond-> (str command chat.constants/spacing-char
|
||||
(join-command-args new-params))
|
||||
(and (not last-param?)
|
||||
(or (= 0 param-count)
|
||||
(= param-index (dec param-count))))
|
||||
(= param-index param-count))
|
||||
(str chat.constants/spacing-char))]
|
||||
{:db (-> db
|
||||
(chat/set-chat-ui-props {:validation-messages nil})
|
||||
|
@ -170,3 +170,8 @@
|
|||
[{:keys [db] :as cofx} command-message-id]
|
||||
(let [current-chat-id (:current-chat-id db)]
|
||||
{: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
|
||||
#(protocol/on-send type command-message %)
|
||||
(commands.input/set-command-reference nil)
|
||||
(commands.input/clean-custom-params)
|
||||
(chat.message/send-message command-message)))))))
|
||||
|
||||
(fx/defn send
|
||||
|
@ -48,4 +49,5 @@
|
|||
(fx/merge cofx
|
||||
#(protocol/on-send type (commands/enrich-command-message-for-events db command-message) %)
|
||||
(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/current-chat]
|
||||
:<- [:chats/selected-chat-command]
|
||||
(fn [[{:keys [input-text]} {:keys [params current-param-position]}]]
|
||||
(when (string/ends-with? (or input-text "") chat.constants/spacing-char)
|
||||
(fn [[{:keys [input-text]} {:keys [params current-param-position cursor-in-the-end?]}]]
|
||||
(when (and cursor-in-the-end? (string/ends-with? (or input-text "") chat.constants/spacing-char))
|
||||
(get-in params [current-param-position :placeholder]))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
(defview parameter-box-container []
|
||||
(letsubs [parameter-box [:chats/parameter-box]]
|
||||
(when parameter-box
|
||||
[react/view style/root
|
||||
[react/view
|
||||
[parameter-box]])))
|
||||
|
||||
(defview parameter-box-view []
|
||||
|
|
|
@ -19,6 +19,10 @@
|
|||
:bottom bottom
|
||||
:position :absolute
|
||||
:elevation 2
|
||||
:shadow-offset {:width 0 :height 1}
|
||||
:shadow-radius 12
|
||||
:shadow-opacity 0.12
|
||||
:shadow-color colors/white
|
||||
:max-height max-height})
|
||||
|
||||
(def header-container
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
[:db :chats "test" :input-text])))
|
||||
(is (= "/test-command first-value second-value \"last 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]))))))
|
||||
|
||||
(deftest parse-parameters-test
|
||||
|
|
Loading…
Reference in New Issue