From 3718541b8c0844d76e2fc12944ef494e9cef9c1f Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Fri, 8 Jul 2016 12:26:46 +0300 Subject: [PATCH] validation errors position --- src/status_im/chat/handlers/animation.cljs | 14 ++++++++++---- src/status_im/chat/handlers/commands.cljs | 1 + src/status_im/chat/styles/command_validation.cljs | 5 +++-- src/status_im/chat/views/command_validation.cljs | 15 +++++++-------- src/status_im/chat/views/message_input.cljs | 4 +--- src/status_im/chat/views/response.cljs | 7 ++++--- src/status_im/utils/handlers.cljs | 2 +- 7 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index fde8a8e457..1bb6913651 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -41,10 +41,16 @@ (defn get-minimum-height [{:keys [current-chat-id] :as db}] (let [path [:chats current-chat-id :command-input :command :type] - type (get-in db path)] - (if (= :response type) - minimum-suggestion-height - input-height))) + type (get-in db path) + errors (get-in db [:validation-errors current-chat-id]) + custom-errors (get-in db [:custom-validation-errors current-chat-id]) + validation-height (if (or (seq errors) (seq custom-errors)) + request-info-height + 0)] + (+ validation-height + (if (= :response type) + minimum-suggestion-height + input-height)))) (register-handler :animate-show-response ;[(after #(dispatch [:command-edit-mode]))] diff --git a/src/status_im/chat/handlers/commands.cljs b/src/status_im/chat/handlers/commands.cljs index 5c0caf390f..f1ca4f1945 100644 --- a/src/status_im/chat/handlers/commands.cljs +++ b/src/status_im/chat/handlers/commands.cljs @@ -183,5 +183,6 @@ (register-handler ::set-validation-error + (after #(dispatch [:fix-response-height])) (fn [db [_ chat-id error]] (assoc-in db [:validation-errors chat-id] [error]))) diff --git a/src/status_im/chat/styles/command_validation.cljs b/src/status_im/chat/styles/command_validation.cljs index fc4f75b999..2ffb23cc84 100644 --- a/src/status_im/chat/styles/command_validation.cljs +++ b/src/status_im/chat/styles/command_validation.cljs @@ -1,9 +1,10 @@ (ns status-im.chat.styles.command-validation - (:require [status-im.components.styles :as st])) + (:require [status-im.components.styles :as st] + [status-im.chat.constants :as constants])) (def messages-container {:background-color :red - :height 61 + :height constants/request-info-height :padding-left 16 :padding-top 14}) diff --git a/src/status_im/chat/views/command_validation.cljs b/src/status_im/chat/views/command_validation.cljs index 1c36b91ceb..6d7a705bd5 100644 --- a/src/status_im/chat/views/command_validation.cljs +++ b/src/status_im/chat/views/command_validation.cljs @@ -20,12 +20,11 @@ [validation-messages [:validation-errors] custom-errors [:custom-validation-errors] command? [:command?]] - (when (and command? - (or (seq validation-messages) - (seq custom-errors))) - [c/scroll-view - (cond (seq custom-errors) - (vec (concat [c/view] custom-errors)) + [c/view + (cond (seq custom-errors) + (vec (concat [c/view] custom-errors)) - (seq validation-messages) - [messages-list validation-messages])])) + (seq validation-messages) + [messages-list validation-messages] + + :else nil)]) diff --git a/src/status_im/chat/views/message_input.cljs b/src/status_im/chat/views/message_input.cljs index 87f08c5ad2..81ea2dd4a7 100644 --- a/src/status_im/chat/views/message_input.cljs +++ b/src/status_im/chat/views/message_input.cljs @@ -11,8 +11,7 @@ [status-im.chat.views.command :as command] [status-im.chat.styles.message-input :as st] [status-im.chat.styles.plain-message :as st-message] - [status-im.chat.styles.response :as st-response] - [status-im.chat.views.command-validation :as cv])) + [status-im.chat.styles.response :as st-response])) (defn send-button [{:keys [on-press accessibility-label]}] [touchable-highlight {:on-press on-press @@ -56,7 +55,6 @@ input-command [:get-chat-command-content] valid-plain-message? [:valid-plain-message?]] [view st/input-container - [cv/validation-messages] [view st/input-view [plain-message/commands-button] [message-input-container diff --git a/src/status_im/chat/views/response.cljs b/src/status_im/chat/views/response.cljs index a0d8e876bc..6e016f5e00 100644 --- a/src/status_im/chat/views/response.cljs +++ b/src/status_im/chat/views/response.cljs @@ -15,7 +15,8 @@ [status-im.chat.styles.dragdown :as ddst] [status-im.components.animation :as anim] [status-im.chat.suggestions-responder :as resp] - [status-im.chat.constants :as c])) + [status-im.chat.constants :as c] + [status-im.chat.views.command-validation :as cv])) (defn drag-icon [] [view st/drag-container @@ -83,8 +84,7 @@ (defview placeholder [] [suggestions [:get-content-suggestions]] - (when (seq suggestions) - [view st/input-placeholder])) + [view st/input-placeholder]) (defview response-suggestions-view [] [suggestions [:get-content-suggestions]] @@ -95,4 +95,5 @@ [container response-height [request-info response-height] [response-suggestions-view] + [cv/validation-messages] [placeholder]])) diff --git a/src/status_im/utils/handlers.cljs b/src/status_im/utils/handlers.cljs index 4d2777e335..083196375e 100644 --- a/src/status_im/utils/handlers.cljs +++ b/src/status_im/utils/handlers.cljs @@ -11,4 +11,4 @@ (defn register-handler ([name handler] (register-handler name nil handler)) ([name middleware handler] - (re-core/register-handler name [debug middleware] handler))) + (re-core/register-handler name [#_debug middleware] handler)))