Chat name validation
This commit is contained in:
parent
ea09dcb1a6
commit
4d70e318b3
|
@ -7,14 +7,14 @@
|
||||||
[status-im.utils.datetime :as time]))
|
[status-im.utils.datetime :as time]))
|
||||||
|
|
||||||
(defn chat-list-item-inner-view
|
(defn chat-list-item-inner-view
|
||||||
[{:keys [chat-id name color photo-path new-messages-count
|
[{:keys [chat-id name color new-messages-count
|
||||||
online group-chat contacts] :as chat}]
|
online group-chat contacts] :as chat}]
|
||||||
(let [last-message (first (:messages chat))]
|
(let [last-message (first (:messages chat))]
|
||||||
[view st/chat-container
|
[view st/chat-container
|
||||||
[view st/chat-icon-container
|
[view st/chat-icon-container
|
||||||
[chat-icon-view-chat-list chat-id group-chat name color online]]
|
[chat-icon-view-chat-list chat-id group-chat name color online]]
|
||||||
[view st/item-container
|
[view st/item-container
|
||||||
#_[view st/name-view
|
[view st/name-view
|
||||||
[text {:style st/name-text} (truncate-str name 20)]
|
[text {:style st/name-text} (truncate-str name 20)]
|
||||||
(when group-chat
|
(when group-chat
|
||||||
[icon :group st/group-icon])
|
[icon :group st/group-icon])
|
||||||
|
|
|
@ -10,3 +10,5 @@
|
||||||
(def content-type-command "command")
|
(def content-type-command "command")
|
||||||
(def content-type-command-request "command-request")
|
(def content-type-command-request "command-request")
|
||||||
(def content-type-status "status")
|
(def content-type-status "status")
|
||||||
|
|
||||||
|
(def max-chat-name-length 20)
|
||||||
|
|
|
@ -145,7 +145,9 @@
|
||||||
(defview chat-name []
|
(defview chat-name []
|
||||||
[name [:chat :name]
|
[name [:chat :name]
|
||||||
new-name [:get :new-chat-name]
|
new-name [:get :new-chat-name]
|
||||||
focused? [:get ::name-input-focused]]
|
validation-messages [:new-chat-name-validation-messages]
|
||||||
|
focused? [:get ::name-input-focused]
|
||||||
|
valid? [:new-chat-name-valid?]]
|
||||||
[view
|
[view
|
||||||
[text {:style st/chat-name-text} "Chat name"]
|
[text {:style st/chat-name-text} "Chat name"]
|
||||||
[view (st/chat-name-value-container focused?)
|
[view (st/chat-name-value-container focused?)
|
||||||
|
@ -156,12 +158,14 @@
|
||||||
:on-blur blur}
|
:on-blur blur}
|
||||||
name]
|
name]
|
||||||
(if (or focused? (not= name new-name))
|
(if (or focused? (not= name new-name))
|
||||||
[touchable-highlight {:style st/chat-name-btn-edit-container
|
[touchable-highlight {:style (st/chat-name-btn-edit-container valid?)
|
||||||
:on-press save}
|
:on-press save}
|
||||||
[view [icon :ok-purple st/add-members-icon]]]
|
[view [icon :ok-purple st/add-members-icon]]]
|
||||||
[touchable-highlight {:style st/chat-name-btn-edit-container
|
[touchable-highlight {:style (st/chat-name-btn-edit-container true)
|
||||||
:on-press focus}
|
:on-press focus}
|
||||||
[text {:style st/chat-name-btn-edit-text} "Edit"]])]])
|
[text {:style st/chat-name-btn-edit-text} "Edit"]])]
|
||||||
|
(when (pos? (count validation-messages))
|
||||||
|
[text {:style st/chat-name-validation-message} (first validation-messages)])])
|
||||||
|
|
||||||
(defview group-settings []
|
(defview group-settings []
|
||||||
[show-color-picker [:group-settings :show-color-picker]]
|
[show-color-picker [:group-settings :show-color-picker]]
|
||||||
|
|
|
@ -91,9 +91,15 @@
|
||||||
:fontFamily font
|
:fontFamily font
|
||||||
:color text1-color})
|
:color text1-color})
|
||||||
|
|
||||||
(def chat-name-btn-edit-container
|
(def chat-name-validation-message
|
||||||
|
{:marginTop 8
|
||||||
|
:marginLeft 16
|
||||||
|
:color :red})
|
||||||
|
|
||||||
|
(defn chat-name-btn-edit-container [enabled?]
|
||||||
{:padding 16
|
{:padding 16
|
||||||
:justifyContent :center})
|
:justifyContent :center
|
||||||
|
:opacity (if enabled? 1 0.3)})
|
||||||
|
|
||||||
(def chat-name-btn-edit-text
|
(def chat-name-btn-edit-text
|
||||||
{:marginTop -1
|
{:marginTop -1
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
(ns status-im.group-settings.subs
|
(ns status-im.group-settings.subs
|
||||||
(:require-macros [reagent.ratom :refer [reaction]])
|
(:require-macros [reagent.ratom :refer [reaction]])
|
||||||
(:require [re-frame.core :refer [register-sub]]))
|
(:require [re-frame.core :refer [register-sub]]
|
||||||
|
[status-im.constants :refer [max-chat-name-length]]))
|
||||||
|
|
||||||
(register-sub :selected-participant
|
(register-sub :selected-participant
|
||||||
(fn [db _]
|
(fn [db _]
|
||||||
|
@ -11,3 +12,20 @@
|
||||||
(register-sub :group-settings
|
(register-sub :group-settings
|
||||||
(fn [db [_ k]]
|
(fn [db [_ k]]
|
||||||
(reaction (get-in @db [:group-settings k]))))
|
(reaction (get-in @db [:group-settings k]))))
|
||||||
|
|
||||||
|
(defn get-chat-name-validation-messages [chat-name]
|
||||||
|
(filter some?
|
||||||
|
(list (when (zero? (count chat-name))
|
||||||
|
"Chat name can't be empty")
|
||||||
|
(when (< max-chat-name-length (count chat-name))
|
||||||
|
"Chat name is too long"))))
|
||||||
|
|
||||||
|
(register-sub :new-chat-name-validation-messages
|
||||||
|
(fn [db [_]]
|
||||||
|
(let [chat-name (reaction (:new-chat-name @db))]
|
||||||
|
(reaction (get-chat-name-validation-messages @chat-name)))))
|
||||||
|
|
||||||
|
(register-sub :new-chat-name-valid?
|
||||||
|
(fn [db [_]]
|
||||||
|
(let [chat-name (reaction (:new-chat-name @db))]
|
||||||
|
(reaction (zero? (count (get-chat-name-validation-messages @chat-name)))))))
|
||||||
|
|
|
@ -48,7 +48,8 @@
|
||||||
(fn [db _]
|
(fn [db _]
|
||||||
(-> db
|
(-> db
|
||||||
(push-view :new-group)
|
(push-view :new-group)
|
||||||
(assoc :new-group #{})))))
|
(assoc :new-group #{})
|
||||||
|
(assoc :new-chat-name nil)))))
|
||||||
|
|
||||||
(register-handler :show-contacts
|
(register-handler :show-contacts
|
||||||
(fn [db _]
|
(fn [db _]
|
||||||
|
|
|
@ -3,13 +3,13 @@
|
||||||
(:require [re-frame.core :refer [subscribe dispatch]]
|
(:require [re-frame.core :refer [subscribe dispatch]]
|
||||||
[status-im.resources :as res]
|
[status-im.resources :as res]
|
||||||
[status-im.components.react :refer [view
|
[status-im.components.react :refer [view
|
||||||
text-input
|
text-input
|
||||||
text
|
text
|
||||||
image
|
image
|
||||||
icon
|
icon
|
||||||
touchable-highlight
|
touchable-highlight
|
||||||
list-view
|
list-view
|
||||||
list-item]]
|
list-item]]
|
||||||
[status-im.components.styles :refer [color-purple]]
|
[status-im.components.styles :refer [color-purple]]
|
||||||
[status-im.components.toolbar :refer [toolbar]]
|
[status-im.components.toolbar :refer [toolbar]]
|
||||||
[status-im.utils.listview :refer [to-datasource]]
|
[status-im.utils.listview :refer [to-datasource]]
|
||||||
|
@ -18,24 +18,30 @@
|
||||||
|
|
||||||
|
|
||||||
(defview new-group-toolbar []
|
(defview new-group-toolbar []
|
||||||
[group-name [:get ::group-name]
|
[group-name [:get :new-chat-name]
|
||||||
creation-disabled? [:get :disable-group-creation]]
|
creation-disabled? [:get :disable-group-creation]
|
||||||
[toolbar
|
valid? [:new-chat-name-valid?]]
|
||||||
{:title "New group chat"
|
(let [create-btn-enabled? (and valid? (not creation-disabled?))]
|
||||||
:action {:image {:source res/v ;; {:uri "icon_search"}
|
[toolbar
|
||||||
:style st/toolbar-icon}
|
{:title "New group chat"
|
||||||
:handler (when-not creation-disabled?
|
:action {:image {:source res/v ;; {:uri "icon_search"}
|
||||||
#(dispatch [:init-group-creation group-name]))}}])
|
:style (st/toolbar-icon create-btn-enabled?)}
|
||||||
|
:handler (when create-btn-enabled?
|
||||||
|
#(dispatch [:init-group-creation group-name]))}}]))
|
||||||
|
|
||||||
(defview group-name-input []
|
(defview group-name-input []
|
||||||
[group-name [:get ::group-name]]
|
[group-name [:get :new-chat-name]
|
||||||
[text-input
|
validation-messages [:new-chat-name-validation-messages]]
|
||||||
{:underlineColorAndroid color-purple
|
[view nil
|
||||||
:style st/group-name-input
|
[text-input
|
||||||
:autoFocus true
|
{:underlineColorAndroid color-purple
|
||||||
:placeholder "Group Name"
|
:style st/group-name-input
|
||||||
:onChangeText #(dispatch [:set ::group-name %])}
|
:autoFocus true
|
||||||
group-name])
|
:placeholder "Group Name"
|
||||||
|
:onChangeText #(dispatch [:set :new-chat-name %])}
|
||||||
|
group-name]
|
||||||
|
(when (pos? (count validation-messages))
|
||||||
|
[text {:style st/group-name-validation-message} (first validation-messages)])])
|
||||||
|
|
||||||
(defview new-group []
|
(defview new-group []
|
||||||
[contacts [:all-contacts]]
|
[contacts [:all-contacts]]
|
||||||
|
|
|
@ -7,9 +7,10 @@
|
||||||
text2-color
|
text2-color
|
||||||
toolbar-background1]]))
|
toolbar-background1]]))
|
||||||
|
|
||||||
(def toolbar-icon
|
(defn toolbar-icon [enabled?]
|
||||||
{:width 20
|
{:width 20
|
||||||
:height 18})
|
:height 18
|
||||||
|
:opacity (if enabled? 1 0.3)})
|
||||||
|
|
||||||
(def new-group-container
|
(def new-group-container
|
||||||
{:flex 1
|
{:flex 1
|
||||||
|
@ -33,6 +34,9 @@
|
||||||
:fontFamily font
|
:fontFamily font
|
||||||
:color text1-color})
|
:color text1-color})
|
||||||
|
|
||||||
|
(def group-name-validation-message
|
||||||
|
{:color :red})
|
||||||
|
|
||||||
(def members-text
|
(def members-text
|
||||||
{:marginTop 24
|
{:marginTop 24
|
||||||
:marginBottom 16
|
:marginBottom 16
|
||||||
|
|
Loading…
Reference in New Issue