[fixes #2546] Add chat-preview-text component to status.js

Apply default styling for message commands preview in chat
This commit is contained in:
Dmitry Novotochinov 2017-12-01 12:50:20 +03:00
parent 56c59c741f
commit 6d966b4648
No known key found for this signature in database
GPG Key ID: 267674DCC86628D9
8 changed files with 40 additions and 7 deletions

View File

@ -483,7 +483,7 @@ var phoneConfig = {
shortPreview: function (params) {
if (params) {
return {
markup: status.components.text(
markup: status.components.chatPreviewText(
{},
params.phone
)
@ -576,7 +576,7 @@ var faucetCommandConfig ={
},
shortPreview: function (params) {
return {
markup: status.components.text(
markup: status.components.chatPreviewText(
{},
I18n.t('faucet_title') + ": " + params.url
)
@ -651,7 +651,7 @@ status.command({
},
shortPreview: function (params) {
return {
markup: status.components.text(
markup: status.components.chatPreviewText(
{},
I18n.t('debug_mode_title') + ": " + params.mode
)
@ -689,7 +689,7 @@ status.response({
},
shortPreview: function (params) {
return {
markup: status.components.text(
markup: status.components.chatPreviewText(
{},
params.code
)

View File

@ -90,7 +90,7 @@ status.command({
},
shortPreview: function (params) {
return {
markup: status.components.text(
markup: status.components.chatPreviewText(
{},
I18n.t('location_title') + ": " + params.address
)

View File

@ -524,7 +524,7 @@ function previewSend(showRecipient, params, context) {
function shortPreviewSend(params, context) {
return {
markup: status.components.text(
markup: status.components.chatPreviewText(
{},
I18n.t('send_title') + ": "
+ status.localizeNumber(params.amount, context.delimiter, context.separator)
@ -669,7 +669,7 @@ function previewRequest(showRecipient, params, context) {
function shortPreviewRequest(params, context) {
return {
markup: status.components.text(
markup: status.components.chatPreviewText(
{},
I18n.t('request_requesting') + " "
+ status.localizeNumber(params.amount, context.delimiter, context.separator)

View File

@ -130,6 +130,10 @@ function text(options, s) {
return ['text', options].concat(s);
}
function chatPreviewText(options, s) {
return ['chat-preview-text', options, s];
}
function textInput(options) {
return ['text-input', options];
}
@ -273,6 +277,7 @@ var status = {
components: {
view: view,
text: text,
chatPreviewText: chatPreviewText,
textInput: textInput,
slider: slider,
image: image,

View File

@ -7,6 +7,7 @@
[status-im.chat.views.input.validation-messages :as chat-validation-messages]
[status-im.chat.views.api.choose-contact :as choose-contact]
[status-im.ui.components.qr-code :as qr]
[status-im.ui.components.chat-preview :as chat-preview]
[status-im.chat.views.api.geolocation.views :as geolocation]
[status-im.utils.handlers :refer [register-handler]]
[taoensso.timbre :as log]))
@ -22,6 +23,7 @@
{:view components/view
:text components/text
:text-input components/text-input
:chat-preview-text chat-preview/text
:image components/image
:qr-code qr/qr-code
:linking components/linking

View File

@ -0,0 +1,13 @@
(ns status-im.ui.components.chat-preview
(:require [status-im.ui.components.react :as components]
[status-im.ui.screens.chats-list.styles :as st]
[status-im.utils.utils :as utils]))
(def default-attributes
{:style st/last-message-text
:number-of-lines 1})
(defn text [attributes s]
(-> default-attributes
(utils/deep-merge attributes)
(components/text s)))

View File

@ -133,3 +133,10 @@
(map (fn [[k v]]
[k (f v)]))
m))
(defn deep-merge
"Recursively merge maps"
[& maps]
(if (every? map? maps)
(apply merge-with deep-merge maps)
(last maps)))

View File

@ -41,3 +41,9 @@
(is (= {} (u/map-values {} inc)))
(is (= {:a 1} (u/map-values {:a 0} inc)))
(is (= {:a 1 :b 2} (u/map-values {:a 0 :b 1} inc))))
(deftest deep-merge-test
(is (= {} (u/deep-merge {} {})))
(is (= {:a 1 :b 2} (u/deep-merge {:a 1} {:b 2})))
(is (= {:a {:b 1 :c 2}} (u/deep-merge {:a {:b 1 :c 1}} {:a {:c 2}})))
(is (= {:a {:b {:c 2}} :d 1} (u/deep-merge {:a {:b {:c 1}} :d 1} {:a {:b {:c 2}}}))))