-
Notifications
You must be signed in to change notification settings - Fork 990
/
Copy pathview.cljs
169 lines (161 loc) · 8.25 KB
/
view.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
(ns status-im.contexts.chat.home.view
(:require
[oops.core :as oops]
[quo.theme :as quo.theme]
[re-frame.core :as re-frame]
[react-native.core :as rn]
[react-native.reanimated :as reanimated]
[status-im.common.contact-list-item.view :as contact-list-item]
[status-im.common.contact-list.view :as contact-list]
[status-im.common.home.actions.view :as actions]
[status-im.common.home.banner.view :as common.banner]
[status-im.common.home.empty-state.view :as common.empty-state]
[status-im.common.home.header-spacing.view :as common.header-spacing]
[status-im.common.resources :as resources]
[status-im.contexts.chat.actions.view :as chat.actions.view]
[status-im.contexts.chat.home.chat-list-item.view :as chat-list-item]
[status-im.contexts.chat.home.contact-request.view :as contact-request]
[status-im.contexts.shell.constants :as shell.constants]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
(defn get-item-layout
[_ index]
#js {:length 56 :offset (* 56 index) :index index})
(defn filter-and-sort-items-by-tab
[tab items]
(let [k (if (= tab :tab/groups) :group-chat :chat-id)]
(->> items
(filter k)
(sort-by :timestamp >))))
(defn empty-state-content
[theme]
#:tab{:contacts
{:title (i18n/label :t/no-contacts)
:description (i18n/label :t/no-contacts-description)
:image (resources/get-themed-image :no-contacts theme)}
:groups
{:title (i18n/label :t/no-group-chats)
:description (i18n/label :t/no-group-chats-description)
:image (resources/get-themed-image :no-group-chats theme)}
:recent
{:title (i18n/label :t/no-messages)
:description (i18n/label :t/no-messages-description)
:image (resources/get-themed-image :cat-in-box theme)}})
(defn chats
[{:keys [theme selected-tab set-scroll-ref scroll-shared-value]}]
(let [unfiltered-items (rf/sub [:chats/chats-stack-items])
items (filter-and-sort-items-by-tab selected-tab unfiltered-items)]
(if (empty? items)
[common.empty-state/view
{:selected-tab selected-tab
:tab->content (empty-state-content theme)}]
[reanimated/flat-list
{:ref set-scroll-ref
:key-fn #(or (:chat-id %) (:public-key %) (:id %))
:content-inset-adjustment-behavior :never
:header [common.header-spacing/view]
:get-item-layout get-item-layout
:on-end-reached #(re-frame/dispatch [:chat/show-more-chats])
:keyboard-should-persist-taps :always
:data items
:render-data {:theme theme}
:render-fn chat-list-item/chat-list-item
:scroll-event-throttle 8
:content-container-style {:padding-bottom
shell.constants/floating-shell-button-height
:padding-top 8}
:on-scroll #(common.banner/set-scroll-shared-value
{:scroll-input (oops/oget % "nativeEvent.contentOffset.y")
:shared-value scroll-shared-value})}])))
(defn contact-item-render
[{:keys [public-key] :as item} theme]
(let [current-pk (rf/sub [:multiaccount/public-key])
show-profile-actions #(rf/dispatch [:show-bottom-sheet
{:content (fn [] [actions/contact-actions item])}])]
[contact-list-item/contact-list-item
(when (not= public-key current-pk)
{:on-press #(rf/dispatch [:chat.ui/show-profile public-key])
:on-long-press show-profile-actions
:accessory {:type :options
:on-press show-profile-actions}})
item
theme]))
(defn contacts
[{:keys [theme pending-contact-requests set-scroll-ref scroll-shared-value]}]
(let [items (rf/sub [:contacts/active-sections])]
(if (and (empty? items) (empty? pending-contact-requests))
[common.empty-state/view
{:selected-tab :tab/contacts
:tab->content (empty-state-content theme)}]
[rn/section-list
{:ref (when (seq items) set-scroll-ref)
:key-fn :public-key
:get-item-layout get-item-layout
:content-inset-adjustment-behavior :never
:header [:<>
[common.header-spacing/view]
(when (seq pending-contact-requests)
[contact-request/view
{:requests pending-contact-requests}])]
:sections items
:sticky-section-headers-enabled false
:render-section-header-fn contact-list/contacts-section-header
:render-section-footer-fn contact-list/contacts-section-footer
:render-data {:theme theme}
:render-fn contact-item-render
:scroll-event-throttle 8
:on-scroll #(common.banner/set-scroll-shared-value
{:scroll-input (oops/oget % "nativeEvent.contentOffset.y")
:shared-value scroll-shared-value})}])))
(defn- banner-data
[profile-link]
{:title-props
{:beta? true
:label (i18n/label :t/messages)
:handler #(rf/dispatch
[:show-bottom-sheet {:content chat.actions.view/new-chat}])
:accessibility-label :new-chat-button}
:card-props
{:on-press #(rf/dispatch [:open-share {:options {:url profile-link}}])
:banner (resources/get-image :invite-friends)
:title (i18n/label :t/invite-friends-to-status)
:description (i18n/label :t/share-invite-link)}})
(defn view
[]
(let [theme (quo.theme/use-theme)
scroll-ref (rn/use-ref-atom nil)
set-scroll-ref (rn/use-callback #(reset! scroll-ref %))
{:keys [universal-profile-url]} (rf/sub [:profile/profile])
customization-color (rf/sub [:profile/customization-color])
pending-contact-requests (rf/sub [:activity-center/pending-contact-requests])
selected-tab (or (rf/sub [:messages-home/selected-tab]) :tab/recent)
scroll-shared-value (reanimated/use-shared-value 0)]
[:<>
(if (= selected-tab :tab/contacts)
[contacts
{:pending-contact-requests pending-contact-requests
:set-scroll-ref set-scroll-ref
:scroll-shared-value scroll-shared-value
:theme theme}]
[chats
{:selected-tab selected-tab
:set-scroll-ref set-scroll-ref
:scroll-shared-value scroll-shared-value
:theme theme}])
[common.banner/animated-banner
{:content (banner-data universal-profile-url)
:customization-color customization-color
:scroll-ref scroll-ref
:tabs [{:id :tab/recent
:label (i18n/label :t/recent)
:accessibility-label :tab-recent}
{:id :tab/groups
:label (i18n/label :t/groups)
:accessibility-label :tab-groups}
{:id :tab/contacts
:label (i18n/label :t/contacts)
:accessibility-label :tab-contacts
:notification-dot? (pos? (count pending-contact-requests))}]
:selected-tab selected-tab
:on-tab-change (fn [tab] (rf/dispatch [:messages-home/select-tab tab]))
:scroll-shared-value scroll-shared-value}]]))