Little refactoring

This commit is contained in:
virvar 2016-06-09 16:49:32 +03:00
parent 16d8060c28
commit b2cd5fe1cc
3 changed files with 29 additions and 19 deletions

View File

@ -52,14 +52,18 @@
(dispatch [:animate-cancel-command])
(dispatch [:cancel-command])))))
(defn animate-set-chat-command-content [db _]
(when (commands/get-chat-command-to-msg-id db)
(dispatch [:animate-response-resize])))
(register-handler :set-chat-command-content
(after animate-set-chat-command-content)
(fn [{:keys [current-chat-id] :as db} [_ content]]
(as-> db db
(commands/set-chat-command-content db content)
(assoc-in db [:chats current-chat-id :input-text] nil)
(if (commands/get-chat-command-to-msg-id db)
(do (dispatch [:animate-response-resize])
(update-response-height db))
(update-response-height db)
db))))
(defn update-input-text
@ -80,13 +84,6 @@
(fn [db [_ input]]
(assoc db :message-input input)))
(register-handler :prepare-message-input
(u/side-effect!
(fn [db _]
(when-let [message-input (:message-input db)]
(.clear message-input)
(.focus message-input)))))
(register-handler :blur-message-input
(u/side-effect!
(fn [db _]

View File

@ -56,7 +56,6 @@
(assoc-in db [:animations :to-response-height] (get-response-height db)))
(register-handler :finish-show-response
(after #(dispatch [:prepare-message-input]))
(fn [db _]
(assoc-in db [:animations :commands-input-is-switching?] false)))

View File

@ -28,7 +28,20 @@
(when (message-valid? staged-commands message)
(send dismiss-keyboard)))
(defn commands-button-animation-logic [{:keys [to-value val]}]
(defn prepare-message-input [message-input]
(when message-input
(.clear message-input)
(.focus message-input)))
(defn commands-button-animation-callback [message-input]
(fn [arg to-value]
(when (.-finished arg)
(dispatch [:set-in [:animations ::message-input-buttons-scale-current] to-value])
(when (<= to-value 0.1)
(dispatch [:finish-show-response])
(prepare-message-input @message-input)))))
(defn button-animation-logic [{:keys [to-value val callback]}]
(fn [_]
(let [to-scale @to-value
minimum 0.1
@ -37,21 +50,22 @@
:else to-scale)]
(anim/start (anim/timing val {:toValue scale
:duration response-input-hiding-duration})
(fn [arg]
(when (.-finished arg)
(dispatch [:set-in [:animations ::message-input-buttons-scale-current] scale])
(when (= to-scale minimum)
(dispatch [:finish-show-response]))))))))
(when callback
(fn [arg]
(callback arg to-scale)))))))
(defn commands-button []
(let [typing-command? (subscribe [:typing-command?])
message-input (subscribe [:get :message-input])
animation? (subscribe [:get-in [:animations :commands-input-is-switching?]])
to-scale (subscribe [:get-in [:animations :message-input-buttons-scale]])
cur-scale (subscribe [:get-in [:animations ::message-input-buttons-scale-current]])
buttons-scale (anim/create-value (or @cur-scale 1))
anim-callback (commands-button-animation-callback message-input)
context {:to-value to-scale
:val buttons-scale}
on-update (commands-button-animation-logic context)]
:val buttons-scale
:callback anim-callback}
on-update (button-animation-logic context)]
(r/create-class
{:component-did-mount
on-update
@ -76,7 +90,7 @@
buttons-scale (anim/create-value (or @cur-scale 1))
context {:to-value to-scale
:val buttons-scale}
on-update (commands-button-animation-logic context)]
on-update (button-animation-logic context)]
(r/create-class
{:component-did-mount
on-update