mirror of
https://github.com/status-im/status-react.git
synced 2025-01-09 18:46:19 +00:00
use debounce-and-dispatch to improve mention performance (#15887)
* use debounce-and-dispatch to improve mention performance * increase time to 400ms * decrease time to 300ms * update status-go-version.json * update status-go-version.json
This commit is contained in:
parent
409c0a9e60
commit
d2e38772b9
@ -70,13 +70,12 @@
|
|||||||
[{:keys [db] :as cofx} text-input-ref {:keys [primary-name searched-text match public-key] :as user}]
|
[{:keys [db] :as cofx} text-input-ref {:keys [primary-name searched-text match public-key] :as user}]
|
||||||
(let [chat-id (:current-chat-id db)
|
(let [chat-id (:current-chat-id db)
|
||||||
text (get-in db [:chat/inputs chat-id :input-text])
|
text (get-in db [:chat/inputs chat-id :input-text])
|
||||||
method "wakuext_chatMentionNewInputTextWithMention"
|
method "wakuext_chatMentionSelectMention"
|
||||||
params [chat-id text primary-name]]
|
params [chat-id text primary-name public-key]]
|
||||||
{:json-rpc/call [{:method method
|
{:json-rpc/call [{:method method
|
||||||
:params params
|
:params params
|
||||||
:on-success #(rf/dispatch [:mention/on-new-input-text-with-mentions-success %
|
:on-success #(rf/dispatch [:mention/on-select-mention-success %
|
||||||
primary-name text-input-ref match searched-text
|
primary-name match searched-text public-key])
|
||||||
public-key])
|
|
||||||
:on-error #(rf/dispatch [:mention/on-error
|
:on-error #(rf/dispatch [:mention/on-error
|
||||||
{:method method
|
{:method method
|
||||||
:params params} %])}]}))
|
:params params} %])}]}))
|
||||||
@ -250,21 +249,21 @@
|
|||||||
[{{:keys [current-chat-id] :as db} :db :as cofx}]
|
[{{:keys [current-chat-id] :as db} :db :as cofx}]
|
||||||
(let [{:keys [input-text metadata]} (get-in db [:chat/inputs current-chat-id])
|
(let [{:keys [input-text metadata]} (get-in db [:chat/inputs current-chat-id])
|
||||||
editing-message (:editing-message metadata)
|
editing-message (:editing-message metadata)
|
||||||
method "wakuext_chatMentionCheckMentions"
|
method "wakuext_chatMentionReplaceWithPublicKey"
|
||||||
params [current-chat-id input-text]]
|
params [current-chat-id input-text]]
|
||||||
{:json-rpc/call [{:method method
|
{:json-rpc/call [{:method method
|
||||||
:params params
|
:params params
|
||||||
:on-error #(rf/dispatch [:mention/on-error {:method method :params params} %])
|
:on-error #(rf/dispatch [:mention/on-error {:method method :params params} %])
|
||||||
:on-success #(rf/dispatch [:mention/on-check-mentions-success
|
:on-success #(rf/dispatch [:mention/on-replace-with-public-key-success
|
||||||
current-chat-id
|
current-chat-id
|
||||||
editing-message
|
editing-message
|
||||||
input-text
|
input-text
|
||||||
%])}]}))
|
%])}]}))
|
||||||
|
|
||||||
(rf/defn on-check-mentions-success
|
(rf/defn on-replace-with-public-key-success
|
||||||
{:events [:mention/on-check-mentions-success]}
|
{:events [:mention/on-replace-with-public-key-success]}
|
||||||
[{:keys [db] :as cofx} current-chat-id editing-message input-text new-text]
|
[{:keys [db] :as cofx} current-chat-id editing-message input-text new-text]
|
||||||
(log/debug "[mentions] on-check-mentions-success"
|
(log/debug "[mentions] on-replace-with-public-key-success"
|
||||||
{:chat-id current-chat-id
|
{:chat-id current-chat-id
|
||||||
:editing-message editing-message
|
:editing-message editing-message
|
||||||
:input-text input-text
|
:input-text input-text
|
||||||
|
@ -1,11 +1,7 @@
|
|||||||
(ns status-im.chat.models.mentions
|
(ns status-im.chat.models.mentions
|
||||||
(:require [clojure.set :as set]
|
(:require [clojure.set :as set]
|
||||||
[quo.react :as react]
|
|
||||||
[quo.react-native :as rn]
|
|
||||||
[re-frame.core :as re-frame]
|
|
||||||
[utils.re-frame :as rf]
|
[utils.re-frame :as rf]
|
||||||
[taoensso.timbre :as log]
|
[taoensso.timbre :as log]))
|
||||||
[native-module.core :as native-module]))
|
|
||||||
|
|
||||||
(defn- transfer-input-segments
|
(defn- transfer-input-segments
|
||||||
[segments]
|
[segments]
|
||||||
@ -126,47 +122,21 @@
|
|||||||
(assoc-in [:chats/mentions chat-id :mentions] state)
|
(assoc-in [:chats/mentions chat-id :mentions] state)
|
||||||
(assoc-in [:chat/inputs-with-mentions chat-id] input-segments))}))
|
(assoc-in [:chat/inputs-with-mentions chat-id] input-segments))}))
|
||||||
|
|
||||||
(rf/defn recheck-at-idxs
|
(rf/defn on-select-mention-success
|
||||||
[{:keys [db]} public-key]
|
{:events [:mention/on-select-mention-success]}
|
||||||
(let [chat-id (:current-chat-id db)
|
[{:keys [db] :as cofx} result primary-name match searched-text public-key]
|
||||||
text (get-in db [:chat/inputs chat-id :input-text])
|
(log/debug "[mentions] on-select-mention-success"
|
||||||
params [chat-id text public-key]
|
|
||||||
method "wakuext_chatMentionRecheckAtIdxs"]
|
|
||||||
{:json-rpc/call [{:method method
|
|
||||||
:params params
|
|
||||||
:on-success #(rf/dispatch [:mention/on-recheck-at-idxs-success %])
|
|
||||||
:on-error #(rf/dispatch [:mention/on-error
|
|
||||||
{:method method
|
|
||||||
:params params} %])}]}))
|
|
||||||
|
|
||||||
(rf/defn on-recheck-at-idxs-success
|
|
||||||
{:events [:mention/on-recheck-at-idxs-success]}
|
|
||||||
[{:keys [db]} result]
|
|
||||||
(log/debug "[mentions] on-recheck-at-idxs-success" {:result result})
|
|
||||||
(let [{:keys [input-segments state chat-id]} (transfer-mention-result result)]
|
|
||||||
{:db (-> db
|
|
||||||
(assoc-in [:chats/mentions chat-id :mentions] state)
|
|
||||||
(assoc-in [:chat/inputs-with-mentions chat-id] input-segments))}))
|
|
||||||
|
|
||||||
(rf/defn reset-text-input-cursor
|
|
||||||
[_ ref cursor]
|
|
||||||
{::reset-text-input-cursor [ref cursor]})
|
|
||||||
|
|
||||||
(rf/defn on-new-input-text-with-mentions-success
|
|
||||||
{:events [:mention/on-new-input-text-with-mentions-success]}
|
|
||||||
[{:keys [db] :as cofx} result primary-name text-input-ref match searched-text public-key]
|
|
||||||
(log/debug "[mentions] on-new-input-text-with-mentions-success"
|
|
||||||
{:result result
|
{:result result
|
||||||
:primary-name primary-name
|
:primary-name primary-name
|
||||||
:match match
|
:match match
|
||||||
:searched-text searched-text
|
:searched-text searched-text
|
||||||
:public-key public-key})
|
:public-key public-key})
|
||||||
(let [{:keys [new-text chat-id]} (transfer-mention-result result)]
|
(let [{:keys [new-text chat-id state input-segments]} (transfer-mention-result result)]
|
||||||
(rf/merge
|
{:db (-> db
|
||||||
cofx
|
(assoc-in [:chats/mentions chat-id :mentions] state)
|
||||||
{:db (assoc-in db [:chats/mention-suggestions chat-id] nil)
|
(assoc-in [:chat/inputs-with-mentions chat-id] input-segments)
|
||||||
:dispatch [:chat.ui/set-chat-input-text new-text chat-id]}
|
(assoc-in [:chats/mention-suggestions chat-id] nil))
|
||||||
(recheck-at-idxs public-key))))
|
:dispatch [:chat.ui/set-chat-input-text new-text chat-id]}))
|
||||||
|
|
||||||
(rf/defn clear-suggestions
|
(rf/defn clear-suggestions
|
||||||
[{:keys [db]}]
|
[{:keys [db]}]
|
||||||
@ -189,38 +159,3 @@
|
|||||||
:on-error #(log/error "Error while calling wakuext_chatMentionClearMentions"
|
:on-error #(log/error "Error while calling wakuext_chatMentionClearMentions"
|
||||||
{:error %})}]}
|
{:error %})}]}
|
||||||
(clear-suggestions))))
|
(clear-suggestions))))
|
||||||
|
|
||||||
(rf/defn check-selection
|
|
||||||
{:events [:mention/on-selection-change]}
|
|
||||||
[{:keys [db]}
|
|
||||||
{:keys [start end]}]
|
|
||||||
(let [chat-id (:current-chat-id db)
|
|
||||||
text (get-in db [:chat/inputs chat-id :input-text])
|
|
||||||
params [chat-id text start end]
|
|
||||||
method "wakuext_chatMentionHandleSelectionChange"]
|
|
||||||
(when text
|
|
||||||
(log/debug "[mentions] check-selection" {:params params})
|
|
||||||
{:json-rpc/call [{:method method
|
|
||||||
:params params
|
|
||||||
:on-success #(rf/dispatch [:mention/on-handle-selection-change-success %])
|
|
||||||
:on-error #(rf/dispatch [:mention/on-error
|
|
||||||
{:method method
|
|
||||||
:params params} %])}]})))
|
|
||||||
|
|
||||||
(rf/defn on-check-selection-success
|
|
||||||
{:events [:mention/on-handle-selection-change-success]}
|
|
||||||
[{:keys [db]} result]
|
|
||||||
(log/debug "[mentions] on-check-selection-success" {:result result})
|
|
||||||
(let [{:keys [state chat-id mentionable-users input-segments]} (transfer-mention-result result)]
|
|
||||||
{:db (-> db
|
|
||||||
(assoc-in [:chats/mention-suggestions chat-id] mentionable-users)
|
|
||||||
(assoc-in [:chats/mentions chat-id :mentions] state)
|
|
||||||
(assoc-in [:chat/inputs-with-mentions chat-id] input-segments))}))
|
|
||||||
|
|
||||||
(re-frame/reg-fx
|
|
||||||
::reset-text-input-cursor
|
|
||||||
(fn [[ref cursor]]
|
|
||||||
(when ref
|
|
||||||
(native-module/reset-keyboard-input
|
|
||||||
(rn/find-node-handle (react/current-ref ref))
|
|
||||||
cursor))))
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
[status-im2.contexts.chat.composer.keyboard :as kb]
|
[status-im2.contexts.chat.composer.keyboard :as kb]
|
||||||
[utils.number :as utils.number]
|
[utils.number :as utils.number]
|
||||||
[oops.core :as oops]
|
[oops.core :as oops]
|
||||||
[utils.re-frame :as rf]))
|
[utils.debounce :as debounce]))
|
||||||
|
|
||||||
(defn reenter-screen-effect
|
(defn reenter-screen-effect
|
||||||
[{:keys [text-value saved-cursor-position maximized?]}
|
[{:keys [text-value saved-cursor-position maximized?]}
|
||||||
@ -159,7 +159,7 @@
|
|||||||
(when @input-ref
|
(when @input-ref
|
||||||
(.setNativeProps ^js @input-ref (clj->js {:text input-text})))
|
(.setNativeProps ^js @input-ref (clj->js {:text input-text})))
|
||||||
(reset! text-value input-text)
|
(reset! text-value input-text)
|
||||||
(rf/dispatch [:mention/on-change-text input-text])))
|
(debounce/debounce-and-dispatch [:mention/on-change-text input-text] 300)))
|
||||||
[input-text]))
|
[input-text]))
|
||||||
|
|
||||||
(defn did-mount
|
(defn did-mount
|
||||||
|
@ -8,7 +8,8 @@
|
|||||||
[status-im2.contexts.chat.composer.keyboard :as kb]
|
[status-im2.contexts.chat.composer.keyboard :as kb]
|
||||||
[status-im2.contexts.chat.composer.utils :as utils]
|
[status-im2.contexts.chat.composer.utils :as utils]
|
||||||
[status-im2.contexts.chat.composer.selection :as selection]
|
[status-im2.contexts.chat.composer.selection :as selection]
|
||||||
[utils.re-frame :as rf]))
|
[utils.re-frame :as rf]
|
||||||
|
[utils.debounce :as debounce]))
|
||||||
|
|
||||||
(defn focus
|
(defn focus
|
||||||
[{:keys [input-ref] :as props}
|
[{:keys [input-ref] :as props}
|
||||||
@ -118,7 +119,7 @@
|
|||||||
(@record-reset-fn)
|
(@record-reset-fn)
|
||||||
(reset! recording? false))
|
(reset! recording? false))
|
||||||
(rf/dispatch [:chat.ui/set-chat-input-text text])
|
(rf/dispatch [:chat.ui/set-chat-input-text text])
|
||||||
(rf/dispatch [:mention/on-change-text text]))
|
(debounce/debounce-and-dispatch [:mention/on-change-text text] 300))
|
||||||
|
|
||||||
(defn selection-change
|
(defn selection-change
|
||||||
[event
|
[event
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
|
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
|
||||||
"owner": "status-im",
|
"owner": "status-im",
|
||||||
"repo": "status-go",
|
"repo": "status-go",
|
||||||
"version": "v0.150.2",
|
"version": "v0.151.4",
|
||||||
"commit-sha1": "31144ed5a38589fd129945b634f54e800b39645a",
|
"commit-sha1": "39f486a47ad04a224416ff23f06363bc4991d7e1",
|
||||||
"src-sha256": "0jh6bidhf0gs15samqh5whw4iigr7ql11cx0v6ma7achr6j4r1d2"
|
"src-sha256": "04djwki409xcjsqgv59k5vh1nwfw7hxq64kh3kh6m4cz14symqk3"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user