Spacing between codeblocks and regular text + fixes for "edited at" message (#15307)

* Spacing between codeblocks and regular text + fixes for "edited at" message

Fixes

Post-review updates

* Lint fixes
This commit is contained in:
Alexander 2023-03-15 11:53:20 +01:00 committed by GitHub
parent de6a736c10
commit 8546727f84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 39 deletions

View File

@ -1,13 +1,22 @@
(ns status-im2.contexts.chat.messages.content.text.style (ns status-im2.contexts.chat.messages.content.text.style
(:require [quo2.foundations.colors :as colors])) (:require [quo2.foundations.colors :as colors]))
(def spacing-between-blocks 10)
(def parsed-text-block
{:margin-top -4})
(def paragraph
{:margin-top spacing-between-blocks})
(def block (def block
{:border-radius 6 {:margin-top spacing-between-blocks
:padding-horizontal 3 :border-radius 6
:transform [{:translateY 4}]}) :padding-horizontal 3})
(def quote (def quote
{:border-left-width 1 {:margin-top spacing-between-blocks
:border-left-width 1
:padding-left 10 :padding-left 10
:border-left-color colors/neutral-40}) :border-left-color colors/neutral-40})
@ -16,3 +25,12 @@
{:background-color (colors/theme-colors colors/neutral-5 colors/white-opa-5) {:background-color (colors/theme-colors colors/neutral-5 colors/white-opa-5)
:border-width 1 :border-width 1
:border-color (colors/theme-colors colors/neutral-20 colors/white-opa-20)}) :border-color (colors/theme-colors colors/neutral-20 colors/white-opa-20)})
(def edited-block
{:margin-top 4})
(defn edited-tag
[]
{:font-size 11
:margin-top 4
:color (colors/theme-colors colors/neutral-40 colors/neutral-50)})

View File

@ -74,59 +74,61 @@
(defn render-block (defn render-block
[blocks {:keys [type literal children]} chat-id edited-at] [blocks {:keys [type literal children]} chat-id]
(case (keyword type) (case (keyword type)
:paragraph :paragraph
(conj blocks (conj blocks
[rn/view {:style style/paragraph}
(reduce (reduce
(fn [acc e] (fn [acc e]
(render-inline acc e chat-id)) (render-inline acc e chat-id))
[quo/text] [quo/text]
children)) children)])
:edited-block
(conj blocks
[rn/view {:style style/paragraph}
(reduce
(fn [acc e]
(render-inline acc e chat-id))
[quo/text]
children)])
:blockquote :blockquote
(conj blocks (conj blocks
[rn/view {:style style/quote} [rn/view {:style style/quote}
[quo/text literal]] [quo/text literal]])
(when edited-at
[quo/text
{:weight :medium
:style {:font-size 11
:margin-top 4
:color (colors/theme-colors colors/neutral-40 colors/neutral-50)}}
(str " (" (i18n/label :t/edited) ")")]))
:codeblock :codeblock
(conj blocks (conj blocks
[rn/view {:style (merge style/block (style/code))} [rn/view {:style (merge style/block (style/code))}
[quo/text (subs literal 0 (dec (count literal)))]] [quo/text (subs literal 0 (dec (count literal)))]])
(when edited-at
[quo/text
{:weight :medium
:style {:font-size 11
:margin-top 4
:color (colors/theme-colors colors/neutral-40 colors/neutral-50)}}
(str " (" (i18n/label :t/edited) ")")]))
blocks)) blocks))
(def edited-tag
{:literal (str "(" (i18n/label :t/edited) ")")
:type :edited})
(defn add-edited-tag (defn add-edited-tag
[parsed-text] [parsed-text]
(let [items-count (count parsed-text)
last-item (get parsed-text (dec items-count))]
(if (= (keyword (:type last-item)) :paragraph)
(update parsed-text (update parsed-text
(dec (count parsed-text)) (dec items-count)
(fn [last-literal] (fn [last-literal]
(update last-literal (update last-literal :children into [{:literal " "} edited-tag])))
:children (conj parsed-text {:type :edited-block :children [edited-tag]}))))
conj
{:literal (str " (" (i18n/label :t/edited) ")")
:type :edited}))))
(defn render-parsed-text (defn render-parsed-text
[{:keys [content chat-id edited-at]}] [{:keys [content chat-id edited-at]}]
[rn/view {:style style/parsed-text-block}
(reduce (fn [acc e] (reduce (fn [acc e]
(render-block acc e chat-id edited-at)) (render-block acc e chat-id))
[:<>] [:<>]
(cond-> (:parsed-text content) (cond-> (:parsed-text content)
edited-at add-edited-tag))) edited-at
add-edited-tag))])
(defn text-content (defn text-content
[message-data context] [message-data context]