parent
579269ebca
commit
3fc913b682
|
@ -45,7 +45,8 @@
|
|||
(update-in [:chats current-chat-id :input-text] safe-trim))))
|
||||
|
||||
(defn invoke-suggestions-handler!
|
||||
[{:keys [current-chat-id] :as db} _]
|
||||
[{:keys [current-chat-id canceled-command] :as db} _]
|
||||
(when-not canceled-command
|
||||
(let [{:keys [command content]} (get-in db [:chats current-chat-id :command-input])
|
||||
{:keys [name type]} command
|
||||
path [(if (= :command type) :commands :responses)
|
||||
|
@ -59,19 +60,29 @@
|
|||
params
|
||||
#(dispatch [:suggestions-handler {:command command
|
||||
:content content
|
||||
:chat-id current-chat-id} %]))))
|
||||
:chat-id current-chat-id} %])))))
|
||||
|
||||
(register-handler :start-cancel-command
|
||||
(u/side-effect!
|
||||
(fn [db _]
|
||||
(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
|
||||
[(after invoke-suggestions-handler!)]
|
||||
[(after invoke-suggestions-handler!)
|
||||
(after cancel-command!)]
|
||||
(fn [{:keys [current-chat-id] :as db} [_ content]]
|
||||
(let [starts-as-command? (str/starts-with? content command-prefix)]
|
||||
(as-> db db
|
||||
(commands/set-chat-command-content db content)
|
||||
(assoc-in db [:chats current-chat-id :input-text] nil))))
|
||||
(assoc-in db [:chats current-chat-id :input-text] nil)
|
||||
(assoc db :canceled-command (not starts-as-command?))))))
|
||||
|
||||
(defn update-input-text
|
||||
[{:keys [current-chat-id] :as db} text]
|
||||
|
@ -120,8 +131,12 @@
|
|||
(commands/set-response-chat-command db to-msg-id command-key)))
|
||||
|
||||
(defn update-text
|
||||
[db [_ text]]
|
||||
(update-input-text db text))
|
||||
[{:keys [current-chat-id] :as 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]]
|
||||
(if-not (commands/get-chat-command db)
|
||||
|
@ -145,9 +160,8 @@
|
|||
(register-handler :set-chat-input-text
|
||||
[(enrich update-command)
|
||||
(after select-suggestion!)
|
||||
(enrich check-suggestions)
|
||||
(after #(dispatch [:animate-command-suggestions]))]
|
||||
update-text)
|
||||
((enrich update-text) check-suggestions))
|
||||
|
||||
(defn console? [s]
|
||||
(= "console" s))
|
||||
|
@ -312,8 +326,11 @@
|
|||
(register-handler :set-chat-command
|
||||
[(after invoke-suggestions-handler!)
|
||||
(after #(dispatch [:command-edit-mode]))]
|
||||
(fn [db [_ command-key]]
|
||||
(commands/set-chat-command db command-key)))
|
||||
(fn [{:keys [current-chat-id] :as 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
|
||||
(fn [db [_]]
|
||||
|
@ -499,8 +516,8 @@
|
|||
(assoc-in db [:edit-mode current-chat-id] mode)))
|
||||
|
||||
(register-handler :command-edit-mode
|
||||
[(after #(dispatch [:set-chat-input-text ""]))]
|
||||
(edit-mode-handler :command))
|
||||
|
||||
(register-handler :text-edit-mode
|
||||
(after #(dispatch [:set-chat-input-text ""]))
|
||||
(edit-mode-handler :text))
|
||||
|
|
|
@ -16,12 +16,17 @@
|
|||
:backgroundColor color-white
|
||||
:elevation 4})
|
||||
|
||||
(def command-container
|
||||
{:left 0
|
||||
:backgroundColor :white
|
||||
:position :absolute})
|
||||
|
||||
(defn command-text-container
|
||||
[{:keys [color]}]
|
||||
{:flexDirection :column
|
||||
:marginTop 16
|
||||
:marginBottom 16
|
||||
:marginLeft 0
|
||||
:marginLeft 16
|
||||
:marginRight 8
|
||||
:backgroundColor color
|
||||
:height 24
|
||||
|
|
|
@ -83,11 +83,12 @@
|
|||
:width 12
|
||||
:height 12})
|
||||
|
||||
(def command-input
|
||||
(defn command-input [ml disbale?]
|
||||
{:flex 1
|
||||
:marginRight 16
|
||||
:margin-left (- ml 5)
|
||||
:marginTop -2
|
||||
:padding 0
|
||||
:fontSize 14
|
||||
:fontFamily font
|
||||
:color text1-color})
|
||||
:color (if disbale? color-white text1-color)})
|
||||
|
|
|
@ -127,16 +127,33 @@
|
|||
(= :command)
|
||||
(reaction))))
|
||||
|
||||
(register-sub :command-type
|
||||
(fn []
|
||||
(let [command (subscribe [:get-chat-command])]
|
||||
(reaction (:type @command)))))
|
||||
|
||||
(register-sub :messages-offset
|
||||
(fn []
|
||||
(let [command? (subscribe [:command?])
|
||||
command (subscribe [:get-chat-command])
|
||||
type (subscribe [:command-type])
|
||||
command-suggestions (subscribe [:get-content-suggestions])
|
||||
suggestions (subscribe [:get-suggestions])]
|
||||
(reaction
|
||||
(let [type (:type @command)]
|
||||
(cond (and @command? (= type :response)) c/request-info-height
|
||||
(and @command? (= type :command) (seq @command-suggestions))
|
||||
(cond (and @command? (= @type :response))
|
||||
c/request-info-height
|
||||
|
||||
(and @command? (= @type :command) (seq @command-suggestions))
|
||||
c/suggestions-header-height
|
||||
(seq @suggestions) 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)
|
||||
(send-command)))
|
||||
|
||||
(defn command-icon [command]
|
||||
[view (st/command-text-container command)
|
||||
[text {:style st/command-text} (str "!" (:name command))]])
|
||||
(defview command-icon [command]
|
||||
[icon-width [:get :command-icon-width]]
|
||||
[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 []
|
||||
[touchable-highlight {:on-press cancel-command-input}
|
||||
|
|
|
@ -21,24 +21,27 @@
|
|||
(defn message-input-container [input]
|
||||
[view st/message-input-container input])
|
||||
|
||||
(def plain-input-options
|
||||
(defn plain-input-options [disbale?]
|
||||
{: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})
|
||||
|
||||
(def command-input-options
|
||||
{:style st-response/command-input
|
||||
(defn command-input-options [icon-width disbale?]
|
||||
{:style (st-response/command-input icon-width disbale?)
|
||||
:onChangeText command/set-input-message
|
||||
:onSubmitEditing command/send-command})
|
||||
|
||||
(defview message-input [input-options]
|
||||
[command? [:command?]
|
||||
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
|
||||
(if command?
|
||||
command-input-options
|
||||
plain-input-options)
|
||||
(command-input-options icon-width disbale?)
|
||||
(plain-input-options disbale?))
|
||||
{:autoFocus false
|
||||
:blurOnSubmit false
|
||||
:accessibility-label :input}
|
||||
|
@ -54,8 +57,6 @@
|
|||
[view st/input-container
|
||||
[view st/input-view
|
||||
[plain-message/commands-button]
|
||||
(when (and command? (= :command type))
|
||||
[command/command-icon command])
|
||||
[message-input-container
|
||||
[message-input input-options validator]]
|
||||
;; TODO emoticons: not implemented
|
||||
|
@ -65,4 +66,6 @@
|
|||
command/send-command
|
||||
plain-message/send)]
|
||||
[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}}
|
||||
;; todo maybe nil is fine for now :)
|
||||
nil #_(throw (js/Error. "Uknown command type")))]
|
||||
(println :plc placeholder)
|
||||
(if placeholder
|
||||
(assoc-in options [:input-options :placeholder] placeholder)
|
||||
options)))
|
||||
(assoc-in options [:input-options :placeholder] "")))
|
||||
|
||||
(defview show-input []
|
||||
[parameter [:get-command-parameter]
|
||||
|
|
|
@ -33,7 +33,8 @@
|
|||
delay (if @command? 100 0)]
|
||||
(anim/start (anim/timing width {:toValue n-width
|
||||
:duration response-input-hiding-duration
|
||||
:delay delay})))))
|
||||
:delay delay})
|
||||
#(dispatch [:set :disable-input false])))))
|
||||
|
||||
(defn commands-button []
|
||||
(let [command? (subscribe [:command?])
|
||||
|
|
Loading…
Reference in New Issue