mirror of
https://github.com/status-im/status-react.git
synced 2025-01-11 19:44:47 +00:00
commands canceling
This commit is contained in:
parent
026b678e20
commit
471f637e0d
@ -45,33 +45,44 @@
|
|||||||
(update-in [:chats current-chat-id :input-text] safe-trim))))
|
(update-in [:chats current-chat-id :input-text] safe-trim))))
|
||||||
|
|
||||||
(defn invoke-suggestions-handler!
|
(defn invoke-suggestions-handler!
|
||||||
[{:keys [current-chat-id] :as db} _]
|
[{:keys [current-chat-id canceled-command] :as db} _]
|
||||||
(let [{:keys [command content]} (get-in db [:chats current-chat-id :command-input])
|
(when-not canceled-command
|
||||||
{:keys [name type]} command
|
(let [{:keys [command content]} (get-in db [:chats current-chat-id :command-input])
|
||||||
path [(if (= :command type) :commands :responses)
|
{:keys [name type]} command
|
||||||
name
|
path [(if (= :command type) :commands :responses)
|
||||||
:params
|
name
|
||||||
0
|
:params
|
||||||
:suggestions]
|
0
|
||||||
params {:value content}]
|
:suggestions]
|
||||||
(j/call current-chat-id
|
params {:value content}]
|
||||||
path
|
(j/call current-chat-id
|
||||||
params
|
path
|
||||||
#(dispatch [:suggestions-handler {:command command
|
params
|
||||||
:content content
|
#(dispatch [:suggestions-handler {:command command
|
||||||
:chat-id current-chat-id} %]))))
|
:content content
|
||||||
|
:chat-id current-chat-id} %])))))
|
||||||
|
|
||||||
(register-handler :start-cancel-command
|
(register-handler :start-cancel-command
|
||||||
(u/side-effect!
|
(u/side-effect!
|
||||||
(fn [db _]
|
(fn [db _]
|
||||||
(dispatch [:animate-cancel-command]))))
|
(dispatch [:animate-cancel-command]))))
|
||||||
|
|
||||||
|
(def command-prefix "c ")
|
||||||
|
|
||||||
|
(defn cancel-command!
|
||||||
|
[{:keys [canceled-command]}]
|
||||||
|
(when canceled-command
|
||||||
|
(dispatch [:start-cancel-command])))
|
||||||
|
|
||||||
(register-handler :set-chat-command-content
|
(register-handler :set-chat-command-content
|
||||||
[(after invoke-suggestions-handler!)]
|
[(after invoke-suggestions-handler!)
|
||||||
|
(after cancel-command!)]
|
||||||
(fn [{:keys [current-chat-id] :as db} [_ content]]
|
(fn [{:keys [current-chat-id] :as db} [_ content]]
|
||||||
(as-> db db
|
(let [starts-as-command? (str/starts-with? content command-prefix)]
|
||||||
(commands/set-chat-command-content db content)
|
(as-> db db
|
||||||
(assoc-in db [:chats current-chat-id :input-text] nil))))
|
(commands/set-chat-command-content db content)
|
||||||
|
(assoc-in db [:chats current-chat-id :input-text] nil)
|
||||||
|
(assoc db :canceled-command (not starts-as-command?))))))
|
||||||
|
|
||||||
(defn update-input-text
|
(defn update-input-text
|
||||||
[{:keys [current-chat-id] :as db} text]
|
[{:keys [current-chat-id] :as db} text]
|
||||||
@ -81,10 +92,10 @@
|
|||||||
[{:keys [current-chat-id staged-command]} _]
|
[{:keys [current-chat-id staged-command]} _]
|
||||||
(let [{:keys [command content]} staged-command
|
(let [{:keys [command content]} staged-command
|
||||||
{:keys [name type]} command
|
{:keys [name type]} command
|
||||||
path [(if (= :command type) :commands :responses)
|
path [(if (= :command type) :commands :responses)
|
||||||
name
|
name
|
||||||
:preview]
|
:preview]
|
||||||
params {:value content}]
|
params {:value content}]
|
||||||
(j/call current-chat-id
|
(j/call current-chat-id
|
||||||
path
|
path
|
||||||
params
|
params
|
||||||
@ -93,7 +104,7 @@
|
|||||||
(register-handler :stage-command
|
(register-handler :stage-command
|
||||||
(after invoke-command-preview!)
|
(after invoke-command-preview!)
|
||||||
(fn [{:keys [current-chat-id] :as db} _]
|
(fn [{:keys [current-chat-id] :as db} _]
|
||||||
(let [db (update-input-text db nil)
|
(let [db (update-input-text db nil)
|
||||||
{:keys [command content]}
|
{:keys [command content]}
|
||||||
(get-in db [:chats current-chat-id :command-input])
|
(get-in db [:chats current-chat-id :command-input])
|
||||||
command-info {:command command
|
command-info {:command command
|
||||||
@ -120,8 +131,12 @@
|
|||||||
(commands/set-response-chat-command db to-msg-id command-key)))
|
(commands/set-response-chat-command db to-msg-id command-key)))
|
||||||
|
|
||||||
(defn update-text
|
(defn update-text
|
||||||
[db [_ text]]
|
[{:keys [current-chat-id] :as db} [_ text]]
|
||||||
(update-input-text db text))
|
(let [suggestions (get-in db [:command-suggestions current-chat-id])]
|
||||||
|
(println :hui (count suggestions) text :bla)
|
||||||
|
(if-not (= 1 (count suggestions))
|
||||||
|
(update-input-text db text)
|
||||||
|
db)))
|
||||||
|
|
||||||
(defn update-command [db [_ text]]
|
(defn update-command [db [_ text]]
|
||||||
(if-not (commands/get-chat-command db)
|
(if-not (commands/get-chat-command db)
|
||||||
@ -145,9 +160,8 @@
|
|||||||
(register-handler :set-chat-input-text
|
(register-handler :set-chat-input-text
|
||||||
[(enrich update-command)
|
[(enrich update-command)
|
||||||
(after select-suggestion!)
|
(after select-suggestion!)
|
||||||
(enrich check-suggestions)
|
|
||||||
(after #(dispatch [:animate-command-suggestions]))]
|
(after #(dispatch [:animate-command-suggestions]))]
|
||||||
update-text)
|
((enrich update-text) check-suggestions))
|
||||||
|
|
||||||
(defn console? [s]
|
(defn console? [s]
|
||||||
(= "console" s))
|
(= "console" s))
|
||||||
@ -187,7 +201,7 @@
|
|||||||
|
|
||||||
(defn prepare-message
|
(defn prepare-message
|
||||||
[{:keys [identity current-chat-id] :as db} _]
|
[{:keys [identity current-chat-id] :as db} _]
|
||||||
(let [text (get-in db [:chats current-chat-id :input-text])
|
(let [text (get-in db [:chats current-chat-id :input-text])
|
||||||
[command] (suggestions/check-suggestion db (str text " "))
|
[command] (suggestions/check-suggestion db (str text " "))
|
||||||
message (check-author-direction
|
message (check-author-direction
|
||||||
db current-chat-id
|
db current-chat-id
|
||||||
@ -312,8 +326,11 @@
|
|||||||
(register-handler :set-chat-command
|
(register-handler :set-chat-command
|
||||||
[(after invoke-suggestions-handler!)
|
[(after invoke-suggestions-handler!)
|
||||||
(after #(dispatch [:command-edit-mode]))]
|
(after #(dispatch [:command-edit-mode]))]
|
||||||
(fn [db [_ command-key]]
|
(fn [{:keys [current-chat-id] :as db} [_ command-key]]
|
||||||
(commands/set-chat-command db command-key)))
|
(-> db
|
||||||
|
(commands/set-chat-command command-key)
|
||||||
|
(assoc-in [:chats current-chat-id :command-input :content] "c ")
|
||||||
|
(assoc :disable-input true))))
|
||||||
|
|
||||||
(register-handler :init-console-chat
|
(register-handler :init-console-chat
|
||||||
(fn [db [_]]
|
(fn [db [_]]
|
||||||
@ -406,9 +423,9 @@
|
|||||||
|
|
||||||
(defmethod nav/preload-data! :chat
|
(defmethod nav/preload-data! :chat
|
||||||
[{:keys [current-chat-id] :as db} [_ _ id]]
|
[{:keys [current-chat-id] :as db} [_ _ id]]
|
||||||
(let [chat-id (or id current-chat-id)
|
(let [chat-id (or id current-chat-id)
|
||||||
messages (get-in db [:chats chat-id :messages])
|
messages (get-in db [:chats chat-id :messages])
|
||||||
db' (assoc db :current-chat-id chat-id)]
|
db' (assoc db :current-chat-id chat-id)]
|
||||||
(if (seq messages)
|
(if (seq messages)
|
||||||
db'
|
db'
|
||||||
(-> db'
|
(-> db'
|
||||||
@ -499,8 +516,8 @@
|
|||||||
(assoc-in db [:edit-mode current-chat-id] mode)))
|
(assoc-in db [:edit-mode current-chat-id] mode)))
|
||||||
|
|
||||||
(register-handler :command-edit-mode
|
(register-handler :command-edit-mode
|
||||||
[(after #(dispatch [:set-chat-input-text ""]))]
|
|
||||||
(edit-mode-handler :command))
|
(edit-mode-handler :command))
|
||||||
|
|
||||||
(register-handler :text-edit-mode
|
(register-handler :text-edit-mode
|
||||||
|
(after #(dispatch [:set-chat-input-text ""]))
|
||||||
(edit-mode-handler :text))
|
(edit-mode-handler :text))
|
||||||
|
@ -16,12 +16,17 @@
|
|||||||
:backgroundColor color-white
|
:backgroundColor color-white
|
||||||
:elevation 4})
|
:elevation 4})
|
||||||
|
|
||||||
|
(def command-container
|
||||||
|
{:left 0
|
||||||
|
:backgroundColor :white
|
||||||
|
:position :absolute})
|
||||||
|
|
||||||
(defn command-text-container
|
(defn command-text-container
|
||||||
[{:keys [color]}]
|
[{:keys [color]}]
|
||||||
{:flexDirection :column
|
{:flexDirection :column
|
||||||
:marginTop 16
|
:marginTop 16
|
||||||
:marginBottom 16
|
:marginBottom 16
|
||||||
:marginLeft 0
|
:marginLeft 16
|
||||||
:marginRight 8
|
:marginRight 8
|
||||||
:backgroundColor color
|
:backgroundColor color
|
||||||
:height 24
|
:height 24
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
[status-im.chat.constants :refer [input-height]]))
|
[status-im.chat.constants :refer [input-height]]))
|
||||||
|
|
||||||
(def message-input-container
|
(def message-input-container
|
||||||
{:flex 1
|
{:flex 1
|
||||||
:marginRight 0})
|
:marginRight 0})
|
||||||
|
|
||||||
(def input-container
|
(def input-container
|
||||||
|
@ -83,11 +83,12 @@
|
|||||||
:width 12
|
:width 12
|
||||||
:height 12})
|
:height 12})
|
||||||
|
|
||||||
(def command-input
|
(defn command-input [ml disbale?]
|
||||||
{:flex 1
|
{:flex 1
|
||||||
:marginRight 16
|
:marginRight 16
|
||||||
|
:margin-left (- ml 5)
|
||||||
:marginTop -2
|
:marginTop -2
|
||||||
:padding 0
|
:padding 0
|
||||||
:fontSize 14
|
:fontSize 14
|
||||||
:fontFamily font
|
:fontFamily font
|
||||||
:color text1-color})
|
:color (if disbale? color-white text1-color)})
|
||||||
|
@ -127,16 +127,33 @@
|
|||||||
(= :command)
|
(= :command)
|
||||||
(reaction))))
|
(reaction))))
|
||||||
|
|
||||||
|
(register-sub :command-type
|
||||||
|
(fn []
|
||||||
|
(let [command (subscribe [:get-chat-command])]
|
||||||
|
(reaction (:type @command)))))
|
||||||
|
|
||||||
(register-sub :messages-offset
|
(register-sub :messages-offset
|
||||||
(fn []
|
(fn []
|
||||||
(let [command? (subscribe [:command?])
|
(let [command? (subscribe [:command?])
|
||||||
command (subscribe [:get-chat-command])
|
type (subscribe [:command-type])
|
||||||
command-suggestions (subscribe [:get-content-suggestions])
|
command-suggestions (subscribe [:get-content-suggestions])
|
||||||
suggestions (subscribe [:get-suggestions])]
|
suggestions (subscribe [:get-suggestions])]
|
||||||
(reaction
|
(reaction
|
||||||
(let [type (:type @command)]
|
(cond (and @command? (= @type :response))
|
||||||
(cond (and @command? (= type :response)) c/request-info-height
|
c/request-info-height
|
||||||
(and @command? (= type :command) (seq @command-suggestions))
|
|
||||||
c/suggestions-header-height
|
(and @command? (= @type :command) (seq @command-suggestions))
|
||||||
(seq @suggestions) c/suggestions-header-height
|
c/suggestions-header-height
|
||||||
:else 0))))))
|
|
||||||
|
(and (not @command?) (seq @suggestions))
|
||||||
|
c/suggestions-header-height
|
||||||
|
|
||||||
|
:else 0)))))
|
||||||
|
|
||||||
|
(register-sub :command-icon-width
|
||||||
|
(fn []
|
||||||
|
(let [width (subscribe [:get :command-icon-width])
|
||||||
|
type (subscribe [:command-type])]
|
||||||
|
(reaction (if (= :command @type)
|
||||||
|
@width
|
||||||
|
0)))))
|
||||||
|
@ -27,9 +27,15 @@
|
|||||||
(when (valid? message validator)
|
(when (valid? message validator)
|
||||||
(send-command)))
|
(send-command)))
|
||||||
|
|
||||||
(defn command-icon [command]
|
(defview command-icon [command]
|
||||||
[view (st/command-text-container command)
|
[icon-width [:get :command-icon-width]]
|
||||||
[text {:style st/command-text} (str "!" (:name command))]])
|
[view st/command-container
|
||||||
|
[view {:style (st/command-text-container command)
|
||||||
|
:onLayout (fn [event]
|
||||||
|
(let [width (.. event -nativeEvent -layout -width)]
|
||||||
|
(when (not= icon-width width)
|
||||||
|
(dispatch [:set :command-icon-width width]))))}
|
||||||
|
[text {:style st/command-text} (str "!" (:name command))]]])
|
||||||
|
|
||||||
(defn cancel-button []
|
(defn cancel-button []
|
||||||
[touchable-highlight {:on-press cancel-command-input}
|
[touchable-highlight {:on-press cancel-command-input}
|
||||||
|
@ -21,24 +21,27 @@
|
|||||||
(defn message-input-container [input]
|
(defn message-input-container [input]
|
||||||
[view st/message-input-container input])
|
[view st/message-input-container input])
|
||||||
|
|
||||||
(def plain-input-options
|
(defn plain-input-options [disbale?]
|
||||||
{:style st-message/message-input
|
{:style st-message/message-input
|
||||||
:onChangeText plain-message/set-input-message
|
:onChangeText (when-not disbale? plain-message/set-input-message)
|
||||||
|
:editable (not disbale?)
|
||||||
:onSubmitEditing plain-message/send})
|
:onSubmitEditing plain-message/send})
|
||||||
|
|
||||||
(def command-input-options
|
(defn command-input-options [icon-width disbale?]
|
||||||
{:style st-response/command-input
|
{:style (st-response/command-input icon-width disbale?)
|
||||||
:onChangeText command/set-input-message
|
:onChangeText command/set-input-message
|
||||||
:onSubmitEditing command/send-command})
|
:onSubmitEditing command/send-command})
|
||||||
|
|
||||||
(defview message-input [input-options]
|
(defview message-input [input-options]
|
||||||
[command? [:command?]
|
[command? [:command?]
|
||||||
input-message [:get-chat-input-text]
|
input-message [:get-chat-input-text]
|
||||||
input-command [:get-chat-command-content]]
|
input-command [:get-chat-command-content]
|
||||||
|
icon-width [:command-icon-width]
|
||||||
|
disbale? [:get :disable-input]]
|
||||||
[text-input (merge
|
[text-input (merge
|
||||||
(if command?
|
(if command?
|
||||||
command-input-options
|
(command-input-options icon-width disbale?)
|
||||||
plain-input-options)
|
(plain-input-options disbale?))
|
||||||
{:autoFocus false
|
{:autoFocus false
|
||||||
:blurOnSubmit false
|
:blurOnSubmit false
|
||||||
:accessibility-label :input}
|
:accessibility-label :input}
|
||||||
@ -54,8 +57,6 @@
|
|||||||
[view st/input-container
|
[view st/input-container
|
||||||
[view st/input-view
|
[view st/input-view
|
||||||
[plain-message/commands-button]
|
[plain-message/commands-button]
|
||||||
(when (and command? (= :command type))
|
|
||||||
[command/command-icon command])
|
|
||||||
[message-input-container
|
[message-input-container
|
||||||
[message-input input-options validator]]
|
[message-input input-options validator]]
|
||||||
;; TODO emoticons: not implemented
|
;; TODO emoticons: not implemented
|
||||||
@ -65,4 +66,6 @@
|
|||||||
command/send-command
|
command/send-command
|
||||||
plain-message/send)]
|
plain-message/send)]
|
||||||
[send-button {:on-press on-press
|
[send-button {:on-press on-press
|
||||||
:accessibility-label :send-message}]))]])
|
:accessibility-label :send-message}]))
|
||||||
|
(when (and command? (= :command type))
|
||||||
|
[command/command-icon command])]])
|
||||||
|
@ -24,10 +24,7 @@
|
|||||||
:number {:input-options {:keyboardType :numeric}}
|
:number {:input-options {:keyboardType :numeric}}
|
||||||
;; todo maybe nil is fine for now :)
|
;; todo maybe nil is fine for now :)
|
||||||
nil #_(throw (js/Error. "Uknown command type")))]
|
nil #_(throw (js/Error. "Uknown command type")))]
|
||||||
(println :plc placeholder)
|
(assoc-in options [:input-options :placeholder] "")))
|
||||||
(if placeholder
|
|
||||||
(assoc-in options [:input-options :placeholder] placeholder)
|
|
||||||
options)))
|
|
||||||
|
|
||||||
(defview show-input []
|
(defview show-input []
|
||||||
[parameter [:get-command-parameter]
|
[parameter [:get-command-parameter]
|
||||||
|
@ -33,7 +33,8 @@
|
|||||||
delay (if @command? 100 0)]
|
delay (if @command? 100 0)]
|
||||||
(anim/start (anim/timing width {:toValue n-width
|
(anim/start (anim/timing width {:toValue n-width
|
||||||
:duration response-input-hiding-duration
|
:duration response-input-hiding-duration
|
||||||
:delay delay})))))
|
:delay delay})
|
||||||
|
#(dispatch [:set :disable-input false])))))
|
||||||
|
|
||||||
(defn commands-button []
|
(defn commands-button []
|
||||||
(let [command? (subscribe [:command?])
|
(let [command? (subscribe [:command?])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user