Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#10988] Add entry point to start new chat from search results #10997

Merged
merged 1 commit into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added resources/images/icons/private_chat@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/icons/private_chat@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/status_im/ui/components/toolbar.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:or {size :default}}]
(merge {:align-items :center
:padding-horizontal 8
:width "100%"
:flex-direction :row
:justify-content :space-between}
(when center?
Expand Down
8 changes: 4 additions & 4 deletions src/status_im/ui/screens/add_new/new_chat/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@
new-identity
@resolve-last-id])}})))))))

(handlers/register-handler-fx
::new-chat-focus
(fn [{:keys [db]}]
{:db (dissoc db :contacts/new-identity)}))
(fx/defn clear-new-identity
{:events [::clear-new-identity ::new-chat-focus]}
[{:keys [db]}]
{:db (dissoc db :contacts/new-identity)})

(defn- get-validation-label [value]
(case value
Expand Down
61 changes: 48 additions & 13 deletions src/status_im/ui/screens/home/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
[status-im.ui.components.colors :as colors]
[status-im.ui.screens.add-new.new-public-chat.view :as new-public-chat]
[quo.core :as quo]
[status-im.ui.screens.add-new.new-chat.events :as new-chat]
[status-im.ui.components.search-input.view :as search-input]
[status-im.ui.screens.add-new.new-public-chat.db :as db]
[status-im.utils.debounce :as debounce]
[status-im.utils.utils :as utils]
[cljs-bean.core :as bean]
[status-im.ui.components.topbar :as topbar])
(:require-macros [status-im.utils.views :as views]))
Expand Down Expand Up @@ -90,13 +94,42 @@
{:search-active? search-active?
:search-filter search-filter
:on-cancel #(re-frame/dispatch [:search/home-filter-changed nil])
:on-blur #(when-not (seq chats)
(re-frame/dispatch [:search/home-filter-changed nil]))
:on-blur (fn []
(when-not (seq chats)
(re-frame/dispatch [:search/home-filter-changed nil]))
(re-frame/dispatch [::new-chat/clear-new-identity]))
:on-focus (fn [search-filter]
(when-not search-filter
(re-frame/dispatch [:search/home-filter-changed ""])))
(re-frame/dispatch [:search/home-filter-changed ""])
(re-frame/dispatch [::new-chat/clear-new-identity])))
:on-change (fn [text]
(re-frame/dispatch [:search/home-filter-changed text]))}]])
(re-frame/dispatch [:search/home-filter-changed text])
(re-frame/dispatch [:set-in [:contacts/new-identity :state] :searching])
(debounce/debounce-and-dispatch [:new-chat/set-new-identity text] 300))}]])

(defn start-suggestion [search-value]
(let [{:keys [state ens-name public-key]}
@(re-frame/subscribe [:contacts/new-identity])
valid-private? (= state :valid)
valid-public? (db/valid-topic? search-value)]
(when (or valid-public? valid-private?)
[react/view
[quo/list-header (i18n/label :t/search-no-chat-found)]
(when valid-private?
[quo/list-item {:theme :accent
:icon :main-icons/private-chat
:title (or ens-name (utils/get-shortened-address public-key))
:subtitle (i18n/label :t/join-new-private-chat)
:on-press (fn []
(debounce/dispatch-and-chill [:contact.ui/contact-code-submitted false] 3000))}])
(when valid-public?
[quo/list-item {:theme :accent
:icon :main-icons/public-chat
:title (str "#" search-value)
:subtitle (i18n/label :t/join-new-public-chat)
:on-press (fn []
(re-frame/dispatch [:chat.ui/start-public-chat search-value])
(re-frame/dispatch [:set :public-group-topic nil]))}])])))

(views/defview chats-list []
(views/letsubs [loading? [:chats/loading?]
Expand All @@ -111,15 +144,17 @@
(not @search-active?))
[welcome-blank-page]
[list/flat-list
{:key-fn :chat-id
:keyboard-should-persist-taps :always
:data chats
:render-fn (fn [home-item] [inner-item/home-list-item home-item])
:header (when (or (seq chats) @search-active?)
[search-input-wrapper search-filter chats])
:footer (if (and (not hide-home-tooltip?) (not @search-active?))
[home-tooltip-view]
[react/view {:height 68}])}]))))
{:key-fn :chat-id
:keyboard-should-persist-taps :always
:data chats
:render-fn (fn [home-item] [inner-item/home-list-item home-item])
:header (when (or (seq chats) @search-active?)
[search-input-wrapper search-filter chats])
:empty-component (when @search-active?
[start-suggestion search-filter])
:footer (if (and (not hide-home-tooltip?) (not @search-active?))
[home-tooltip-view]
[react/view {:height 68}])}]))))

(views/defview plus-button []
(views/letsubs [logging-in? [:multiaccounts/login]]
Expand Down
3 changes: 3 additions & 0 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,9 @@
"public-chats": "Public chats",
"public-group-status": "Public",
"public-group-topic": "Topic",
"join-new-public-chat": "Join a public chat",
"join-new-private-chat": "Start a new private chat",
"search-no-chat-found": "No search results. Do you mean",
"public-key": "Public key",
"puk-and-pairing-codes-displayed": "PUK and pairing codes displayed",
"puk-code": "PUK code",
Expand Down