From d6040491fb570470ee051492a32070b629f88066 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Tue, 21 Jun 2016 12:46:02 +0300 Subject: [PATCH] edit mode --- src/status_im/chat/handlers.cljs | 20 +++++++++++++++----- src/status_im/chat/handlers/animation.cljs | 4 ++-- src/status_im/chat/screen.cljs | 2 +- src/status_im/chat/subs.cljs | 6 ++++++ src/status_im/chat/views/message_input.cljs | 4 ++-- src/status_im/chat/views/new_message.cljs | 2 +- src/status_im/chat/views/plain_message.cljs | 4 ++-- src/status_im/db.cljs | 1 - 8 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index db7c198ec3..ae8cdd5dc0 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -86,7 +86,8 @@ (.blur message-input))))) (register-handler :set-response-chat-command - (after #(dispatch [:animate-show-response])) + [(after #(dispatch [:command-edit-mode])) + (after #(dispatch [:animate-show-response]))] (fn [db [_ to-msg-id command-key]] (commands/set-response-chat-command db to-msg-id command-key))) @@ -248,11 +249,10 @@ (commands/unstage-command db staged-command))) (register-handler :set-chat-command - (after #(dispatch [:animate-show-response])) + [(after #(dispatch [:command-edit-mode])) + (after #(dispatch [:animate-show-response]))] (fn [db [_ command-key]] - (-> db - (commands/set-chat-command command-key) - (assoc-in [:animations :command?] true)))) + (commands/set-chat-command db command-key))) (register-handler :init-console-chat (fn [db [_]] @@ -428,3 +428,13 @@ ;((after leaving-message!)) ((after delete-messages!)) ((after delete-chat!)))) + +(defn edit-mode-handler [mode] + (fn [{:keys [current-chat-id] :as db} _] + (assoc-in db [:edit-mode current-chat-id] mode))) + +(register-handler :command-edit-mode + (edit-mode-handler :command)) + +(register-handler :text-edit-mode + (edit-mode-handler :text)) diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index 66869b356d..994a32e85f 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -16,9 +16,9 @@ (register-handler name [(path :animations) middleware] handler))) (animation-handler :animate-cancel-command + (after #(dispatch [:text-edit-mode])) (fn [db _] (assoc db - :command? false :to-response-height zero-height :messages-offset 0))) @@ -37,9 +37,9 @@ (assoc-in db [:animations :to-response-height] (get-response-height db))) (register-handler :animate-show-response + (after #(dispatch [:command-edit-mode])) (fn [db _] (-> db - (assoc-in [:animations :command?] true) (assoc-in [:animations :messages-offset] request-info-height) (update-response-height)))) diff --git a/src/status_im/chat/screen.cljs b/src/status_im/chat/screen.cljs index 35e39bf7ef..4927858f1e 100644 --- a/src/status_im/chat/screen.cljs +++ b/src/status_im/chat/screen.cljs @@ -259,7 +259,7 @@ [group-chat [:chat :group-chat] show-actions-atom [:show-actions] command [:get-chat-command] - command? [:animations :command?] + command? [:command?] to-msg-id [:get-chat-command-to-msg-id]] [view {:style st/chat-view :onLayout (fn [event] diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index 4486741df5..804085ad4b 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -111,3 +111,9 @@ (let [command (reaction (commands/get-chat-command @db)) text (reaction (commands/get-chat-command-content @db))] (reaction (get-content-suggestions @command @text))))) + +(register-sub :command? + (fn [db ] + (->> (get-in @db [:edit-mode (:current-chat-id @db)]) + (= :command) + (reaction)))) diff --git a/src/status_im/chat/views/message_input.cljs b/src/status_im/chat/views/message_input.cljs index fe2900ce63..1df66f9c3d 100644 --- a/src/status_im/chat/views/message_input.cljs +++ b/src/status_im/chat/views/message_input.cljs @@ -32,7 +32,7 @@ :onSubmitEditing command/send-command}) (defview message-input [input-options] - [command? [:animations :command?] + [command? [:command?] input-message [:get-chat-input-text] input-command [:get-chat-command-content]] [text-input (merge @@ -46,7 +46,7 @@ (if command? input-command input-message)]) (defview plain-message-input-view [{:keys [input-options validator]}] - [command? [:animations :command?] + [command? [:command?] input-command [:get-chat-command-content] valid-plain-message? [:valid-plain-message?] valid-command? [:valid-command? validator]] diff --git a/src/status_im/chat/views/new_message.cljs b/src/status_im/chat/views/new_message.cljs index e8e53d2681..cb5865a5d0 100644 --- a/src/status_im/chat/views/new_message.cljs +++ b/src/status_im/chat/views/new_message.cljs @@ -18,7 +18,7 @@ (defview show-input [] [command [:get-chat-command] - command? [:animations :command?]] + command? [:command?]] [plain-message-input-view (when command? (case (:command command) diff --git a/src/status_im/chat/views/plain_message.cljs b/src/status_im/chat/views/plain_message.cljs index 906fa17a93..b5fef1c43c 100644 --- a/src/status_im/chat/views/plain_message.cljs +++ b/src/status_im/chat/views/plain_message.cljs @@ -36,7 +36,7 @@ :delay delay}))))) (defn commands-button [] - (let [command? (subscribe [:animations :command?]) + (let [command? (subscribe [:command?]) buttons-scale (anim/create-value (if @command? 1 0)) container-width (anim/create-value (if @command? 20 56)) context {:command? command? @@ -69,7 +69,7 @@ (anim/set-value width 0.1))))))) (defn smile-button [] - (let [command? (subscribe [:animations :command?]) + (let [command? (subscribe [:command?]) buttons-scale (anim/create-value (if @command? 1 0)) container-width (anim/create-value (if @command? 0.1 56)) context {:command? command? diff --git a/src/status_im/db.cljs b/src/status_im/db.cljs index c10422e8f7..c5b87f3448 100644 --- a/src/status_im/db.cljs +++ b/src/status_im/db.cljs @@ -38,7 +38,6 @@ :phone-number ""} :disable-group-creation false :animations {:to-response-height 0.1 - :command? false :messages-offset 0}}) (def protocol-initialized-path [:protocol-initialized])