[#5934] persist text in message input field after navigating to user profile and back

This commit is contained in:
Roman Volosovskyi 2018-09-22 22:34:45 +03:00
parent f558e94e99
commit d35b15e54e
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
1 changed files with 31 additions and 26 deletions

View File

@ -180,8 +180,12 @@
:current-public-key current-public-key)]))]]
[connectivity/error-view]])))
(views/defview chat-text-input []
(views/defview chat-text-input [chat-id input-text]
(views/letsubs [inp-ref (atom nil)]
{:should-component-update
(fn [_ [_ old-chat-id] [_ new-chat-id]]
;; update component only when switch to another chat
(not= old-chat-id new-chat-id))}
(let [component (reagent/current-component)
set-container-height-fn #(reagent/set-state component {:container-height %})
{:keys [container-height empty?] :or {empty? true}} (reagent/state component)]
@ -193,6 +197,7 @@
:style (styles/chat-text-input container-height)
:font :default
:ref #(reset! inp-ref %)
:default-value input-text
:on-content-size-change #(set-container-height-fn (.-height (.-contentSize (.-nativeEvent %))))
:on-key-press (fn [e]
(let [native-event (.-nativeEvent e)
@ -217,11 +222,11 @@
[icons/icon :icons/arrow-left {:style (styles/send-icon-arrow empty?)}]]]])))
(views/defview chat-view []
(views/letsubs [current-chat [:get-current-chat]]
(views/letsubs [{:keys [input-text chat-id] :as current-chat} [:get-current-chat]]
[react/view {:style styles/chat-view}
[toolbar-chat-view current-chat]
[messages-view current-chat]
[chat-text-input]]))
[chat-text-input chat-id input-text]]))
(views/defview chat-profile []
(letsubs [identity [:get-current-contact-identity]