Skip to content

Commit 7f00f96

Browse files
authored
Change view-id as per the selected bottom tab and refactor subscriptions (#15636)
1 parent 3ca120c commit 7f00f96

File tree

11 files changed

+52
-117
lines changed

11 files changed

+52
-117
lines changed

src/status_im/search/core.cljs

-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
(ns status-im.search.core
22
(:require [utils.re-frame :as rf]))
33

4-
(rf/defn home-filter-changed
5-
{:events [:search/home-filter-changed]}
6-
[cofx search-filter]
7-
{:db (assoc-in (:db cofx) [:ui/search :home-filter] search-filter)})
8-
94
(rf/defn currency-filter-changed
105
{:events [:search/currency-filter-changed]}
116
[cofx search-filter]

src/status_im2/contexts/chat/home/chat_list_item/view.cljs

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
[chat-id]
1515
(fn []
1616
(rf/dispatch [:dismiss-keyboard])
17-
(rf/dispatch [:chat/navigate-to-chat chat-id])
18-
(rf/dispatch [:search/home-filter-changed nil])))
17+
(rf/dispatch [:chat/navigate-to-chat chat-id])))
1918

2019
(defn truncate-literal
2120
[literal]

src/status_im2/contexts/chat/home/view.cljs

+3-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@
3737

3838
(defn chats
3939
[selected-tab top]
40-
(let [{:keys [items search-filter]} (rf/sub [:home-items])
41-
items (filter-items-by-tab selected-tab items)]
42-
(if (and (empty? items)
43-
(empty? search-filter))
40+
(let [unfiltered-items (rf/sub [:chats-stack-items])
41+
items (filter-items-by-tab selected-tab unfiltered-items)]
42+
(if (empty? items)
4443
[welcome-blank-chats]
4544
[rn/flat-list
4645
{:key-fn #(or (:chat-id %) (:public-key %) (:id %))

src/status_im2/contexts/communities/overview/view.cljs

+1-2
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@
186186
(when (and (not locked?) id)
187187
{:on-press (fn []
188188
(rf/dispatch [:dismiss-keyboard])
189-
(rf/dispatch [:chat/navigate-to-chat (str community-id id)])
190-
(rf/dispatch [:search/home-filter-changed nil]))}))))
189+
(rf/dispatch [:chat/navigate-to-chat (str community-id id)]))}))))
191190

192191
(defn add-on-press-handler-to-chats
193192
[community-id chats]

src/status_im2/contexts/shell/animation.cljs

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
(calculate-home-stack-state-value stack-id))]
5252
(reset! selected-stack-id stack-id)
5353
(reset! home-stack-state home-stack-state-value)
54+
(rf/dispatch [:set-view-id (or stack-id :shell)])
5455
(when store?
5556
(async-storage/set-item! :selected-stack-id stack-id))))
5657

src/status_im2/navigation/core.cljs

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[react-native.gesture :as gesture]
55
[react-native.navigation :as navigation]
66
[status-im.multiaccounts.login.core :as login-core]
7+
[status-im2.contexts.shell.animation :as shell.animation]
78
[status-im2.navigation.roots :as roots]
89
[status-im2.navigation.state :as state]
910
[status-im2.navigation.view :as views]
@@ -35,8 +36,11 @@
3536
(defn set-view-id
3637
[view-id]
3738
(when-let [{:keys [on-focus]} (get views/screens view-id)]
38-
(re-frame/dispatch [:set-view-id view-id])
3939
(re-frame/dispatch [:screens/on-will-focus view-id])
40+
(re-frame/dispatch [:set-view-id
41+
(if (= view-id :shell-stack)
42+
(or @shell.animation/selected-stack-id :shell)
43+
view-id)])
4044
(when on-focus
4145
(re-frame/dispatch on-focus))))
4246

src/status_im2/subs/communities.cljs

+23-32
Original file line numberDiff line numberDiff line change
@@ -72,57 +72,48 @@
7272

7373
(re-frame/reg-sub
7474
:communities/featured-communities
75-
:<- [:search/home-filter]
7675
:<- [:communities]
77-
(fn [[search-filter communities]]
78-
(filterv
79-
(fn [{:keys [name]}]
80-
(or (empty? search-filter)
81-
(string/includes? (string/lower-case (str name)) search-filter)))
82-
(vals communities))))
76+
(fn [communities]
77+
(vals communities)))
8378

8479
(re-frame/reg-sub
8580
:communities/sorted-communities
8681
:<- [:communities]
8782
(fn [communities]
8883
(sort-by :name (vals communities))))
8984

90-
(re-frame/reg-sub
91-
:communities/communities
92-
:<- [:search/home-filter]
93-
:<- [:communities]
94-
(fn [[search-filter communities]]
95-
(filterv
96-
(fn [{:keys [name]}]
97-
(or (empty? search-filter)
98-
(string/includes? (string/lower-case (str name)) search-filter)))
99-
(vals communities))))
100-
10185
(re-frame/reg-sub
10286
:communities/community-ids
103-
:<- [:communities/communities]
87+
:<- [:communities]
10488
(fn [communities]
105-
(map :id communities)))
89+
(map :id (vals communities))))
90+
91+
(def memo-communities-stack-items (atom nil))
10692

10793
(re-frame/reg-sub
10894
:communities/grouped-by-status
109-
:<- [:communities/communities]
95+
:<- [:view-id]
96+
:<- [:communities]
11097
:<- [:communities/my-pending-requests-to-join]
11198
;; Return communities splitted by level of user participation. Some communities user
11299
;; already joined, to some of them join request sent and others were opened one day
113100
;; and their data remained in app-db.
114101
;; Result map has form: {:joined [id1, id2] :pending [id3, id5] :opened [id4]}"
115-
(fn [[communities requests]]
116-
(reduce (fn [acc community]
117-
(let [joined? (:joined community)
118-
community-id (:id community)
119-
pending? (boolean (get requests community-id))]
120-
(cond
121-
joined? (update acc :joined conj community)
122-
pending? (update acc :pending conj community)
123-
:else (update acc :opened conj community))))
124-
{:joined [] :pending [] :opened []}
125-
communities)))
102+
(fn [[view-id communities requests]]
103+
(if (= view-id :communities-stack)
104+
(let [grouped-communities (reduce (fn [acc community]
105+
(let [joined? (:joined community)
106+
community-id (:id community)
107+
pending? (boolean (get requests community-id))]
108+
(cond
109+
joined? (update acc :joined conj community)
110+
pending? (update acc :pending conj community)
111+
:else (update acc :opened conj community))))
112+
{:joined [] :pending [] :opened []}
113+
(vals communities))]
114+
(reset! memo-communities-stack-items grouped-communities)
115+
grouped-communities)
116+
@memo-communities-stack-items)))
126117

127118
(defn community->home-item
128119
[community counts]

src/status_im2/subs/general.cljs

-6
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,6 @@
145145
(fn [animations [_ type item-id]]
146146
(get-in animations [type item-id :delete-swiped])))
147147

148-
(re-frame/reg-sub
149-
:search/home-filter
150-
:<- [:ui/search]
151-
(fn [search]
152-
(get search :home-filter)))
153-
154148
(re-frame/reg-sub
155149
:search/recipient-filter
156150
:<- [:ui/search]

src/status_im2/subs/home.cljs

+8-26
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,20 @@
11
(ns status-im2.subs.home
22
(:require [re-frame.core :as re-frame]))
33

4-
(def memo-home-items (atom nil))
4+
(def memo-chats-stack-items (atom nil))
55

66
(re-frame/reg-sub
7-
:home-items
8-
:<- [:search/home-filter]
9-
:<- [:search/filtered-chats]
10-
:<- [:communities/communities]
7+
:chats-stack-items
8+
:<- [:chats/home-list-chats]
119
:<- [:view-id]
1210
:<- [:home-items-show-number]
13-
(fn [[search-filter filtered-chats communities view-id home-items-show-number]]
14-
(if (= view-id :shell-stack)
15-
(let [communities-count (count communities)
16-
chats-count (count filtered-chats)
17-
;; If we have both communities & chats we want to display
18-
;; a separator between them
19-
20-
communities-with-separator (if (and (pos? communities-count)
21-
(pos? chats-count))
22-
(update communities
23-
(dec communities-count)
24-
assoc
25-
:last?
26-
true)
27-
communities)
28-
res {:search-filter search-filter
29-
:items (concat communities-with-separator
30-
(take home-items-show-number
31-
filtered-chats))}]
32-
(reset! memo-home-items res)
11+
(fn [[chats view-id home-items-show-number]]
12+
(if (= view-id :chats-stack)
13+
(let [res (take home-items-show-number chats)]
14+
(reset! memo-chats-stack-items res)
3315
res)
3416
;;we want to keep data unchanged so react doesn't change component when we leave screen
35-
@memo-home-items)))
17+
@memo-chats-stack-items)))
3618

3719
(re-frame/reg-sub
3820
:hide-home-tooltip?

src/status_im2/subs/search.cljs

+1-37
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
(ns status-im2.subs.search
22
(:require [clojure.string :as string])
33
(:require [clojure.string :as string]
4-
[status-im.utils.gfycat.core :as gfycat]
54
[re-frame.core :as re-frame]
65
[status-im.utils.currency :as currency]))
76

@@ -36,41 +35,6 @@
3635
(sort-by-timestamp results)
3736
results)))
3837

39-
(defn filter-chat
40-
[contacts search-filter {:keys [group-chat alias name chat-id]}]
41-
(let [alias (if-not group-chat
42-
(string/lower-case (or alias
43-
(get-in contacts [chat-id :alias])
44-
(gfycat/generate-gfy chat-id)))
45-
"")
46-
nickname (get-in contacts [chat-id :nickname])]
47-
(or
48-
(string/includes? (string/lower-case (str name)) search-filter)
49-
(string/includes? (string/lower-case alias) search-filter)
50-
(when nickname
51-
(string/includes? (string/lower-case nickname) search-filter))
52-
(and
53-
(get-in contacts [chat-id :ens-verified])
54-
(string/includes? (string/lower-case
55-
(str (get-in contacts [chat-id :name])))
56-
search-filter)))))
57-
58-
(re-frame/reg-sub
59-
:search/filtered-chats
60-
:<- [:chats/home-list-chats]
61-
:<- [:contacts/contacts]
62-
:<- [:search/home-filter]
63-
(fn [[chats contacts search-filter]]
64-
;; Short-circuit if search-filter is empty
65-
(let [filtered-chats (if (seq search-filter)
66-
(filter
67-
(partial filter-chat
68-
contacts
69-
(string/lower-case search-filter))
70-
chats)
71-
chats)]
72-
(sort-by :timestamp > filtered-chats))))
73-
7438
(defn extract-currency-attributes
7539
[currency]
7640
(let [{:keys [code display-name]} (val currency)]
@@ -101,4 +65,4 @@
10165
nil (apply-filter search-token-filter
10266
default-tokens
10367
extract-token-attributes
104-
false)}}))
68+
false)}}))

src/status_im2/subs/shell.cljs

+9-2
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,18 @@
103103
#(re-frame/dispatch [:chat/navigate-to-chat channel-id])
104104
100))}))
105105

106+
(def memo-shell-cards (atom nil))
107+
106108
(re-frame/reg-sub
107109
:shell/sorted-switcher-cards
108110
:<- [:shell/switcher-cards]
109-
(fn [stacks]
110-
(sort-by :clock > (map val stacks))))
111+
:<- [:view-id]
112+
(fn [[stacks view-id]]
113+
(if (= view-id :shell)
114+
(let [sorted-shell-cards (sort-by :clock > (map val stacks))]
115+
(reset! memo-shell-cards sorted-shell-cards)
116+
sorted-shell-cards)
117+
@memo-shell-cards)))
111118

112119
(re-frame/reg-sub
113120
:shell/shell-pass-through?

0 commit comments

Comments
 (0)