diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index 59a7c644a8..a9084f4c47 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -15,6 +15,7 @@ [status-im.contacts.views.new-contact :refer [new-contact]] [status-im.qr-scanner.screen :refer [qr-scanner]] [status-im.discovery.tag :refer [discovery-tag]] + [status-im.discovery.search-results :refer [discovery-search-results]] [status-im.chat.screen :refer [chat]] [status-im.accounts.login.screen :refer [login]] [status-im.accounts.screen :refer [accounts]] @@ -85,6 +86,7 @@ (let [component (case (if true startup-view :chat) :discovery main-tabs :discovery-tag discovery-tag + :discovery-search-results discovery-search-results :add-participants new-participants :remove-participants remove-participants :chat-list main-tabs diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index d01788d834..c1067da47a 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -17,3 +17,5 @@ (def response-suggesstion-resize-duration 100) (def default-number-of-messages 20) + +(def default-number-of-discovery-search-results 20) \ No newline at end of file diff --git a/src/status_im/db.cljs b/src/status_im/db.cljs index 563ab6e8d4..6d74f7aa0c 100644 --- a/src/status_im/db.cljs +++ b/src/status_im/db.cljs @@ -23,6 +23,9 @@ :new-contact-identity "" :contacts {} + :discoveries [] + :discovery-search-tags [] + :tags {} :contacts-ids #{} :selected-contacts #{} diff --git a/src/status_im/discovery/model.cljs b/src/status_im/discovery/model.cljs index f1c4e11600..4388cd41d3 100644 --- a/src/status_im/discovery/model.cljs +++ b/src/status_im/discovery/model.cljs @@ -1,7 +1,8 @@ (ns status-im.discovery.model ;status-im.models.discoveries (:require [status-im.utils.logging :as log] - [status-im.persistence.realm.core :as r])) + [status-im.persistence.realm.core :as r] + [status-im.constants :as c])) (defn get-tag [tag] (log/debug "Getting tag: " tag) @@ -61,14 +62,6 @@ (log/debug (str "Deleting " (r/get-count to-delete) " discoveries")) (r/delete :account to-delete))))))) -(defn discoveries-by-tag [tag limit] - (let [discoveries (-> (r/get-by-filter :account :discovery (str "tags.name = '" tag "'")) - (r/sorted :priority :desc))] - (log/debug "Discoveries by tag: " tag) - (if (pos? limit) - (r/page discoveries 0 limit) - discoveries))) - (defn all-tags [] (-> (r/get-all :account :tag) (r/sorted :count :desc) diff --git a/src/status_im/discovery/screen.cljs b/src/status_im/discovery/screen.cljs index 660bb1fb0b..8b96f7a2c6 100644 --- a/src/status_im/discovery/screen.cljs +++ b/src/status_im/discovery/screen.cljs @@ -2,6 +2,7 @@ (:require-macros [status-im.utils.views :refer [defview]]) (:require [re-frame.core :refer [dispatch subscribe]] + [clojure.string :as str] [status-im.components.react :refer [view scroll-view text @@ -9,27 +10,27 @@ [status-im.components.status-bar :refer [status-bar]] [status-im.components.toolbar :refer [toolbar]] [status-im.components.drawer.view :refer [open-drawer]] - [status-im.discovery.views.popular :refer [popular]] + [status-im.discovery.views.popular :refer [discovery-popular]] [status-im.discovery.views.recent :refer [discovery-recent]] [status-im.discovery.styles :as st] - [status-im.components.styles :as cst] [status-im.components.tabs.bottom-gradient :refer [bottom-gradient]] [status-im.i18n :refer [label]])) (defn get-hashtags [status] - (let [hashtags (map #(subs % 1) (re-seq #"#[^ !?,;:.]+" status))] + (let [hashtags (map #(str/replace % #"#" "") (re-seq #"[^ !?,;:.]+" status))] (or hashtags []))) -(defn title-content [platform-specific show-search] +(defn title-content [platform-specific show-search?] [view st/discovery-toolbar-content - (if show-search + (if show-search? [text-input {:style st/discovery-search-input :autoFocus true :placeholder (label :t/search-tags) :onSubmitEditing (fn [e] (let [search (aget e "nativeEvent" "text") hashtags (get-hashtags search)] - (dispatch [:broadcast-status search hashtags])))}] + (dispatch [:set :discovery-search-tags hashtags]) + (dispatch [:navigate-to :discovery-search-results])))}] [view [text {:style st/discovery-title :platform-specific platform-specific @@ -37,9 +38,9 @@ (label :t/discovery)]])]) (defn toogle-search [current-value] - (dispatch [:set ::show-search (not current-value)])) + (dispatch [:set ::show-search? (not current-value)])) -(defn discovery-toolbar [show-search platform-specific] +(defn discovery-toolbar [show-search? platform-specific] [view [status-bar {:platform-specific platform-specific}] [toolbar @@ -47,16 +48,16 @@ :nav-action {:image {:source {:uri :icon_hamburger} :style st/hamburger-icon} :handler open-drawer} - :custom-content [title-content platform-specific show-search] + :custom-content [title-content platform-specific show-search?] :action {:image {:source {:uri :icon_search} :style st/search-icon} - :handler #(toogle-search show-search)}}]]) + :handler #(toogle-search show-search?)}}]]) (defview discovery [{platform-specific :platform-specific}] - [show-search [:get ::show-search] + [show-search? [:get ::show-search?] contacts [:get :contacts]] [view st/discovery-container - [discovery-toolbar show-search platform-specific] + [discovery-toolbar show-search? platform-specific] [scroll-view st/scroll-view-container [view st/section-spacing @@ -64,8 +65,8 @@ :platform-specific platform-specific :font :medium} (label :t/popular-tags)]] - [popular {:contacts contacts - :platform-specific platform-specific}] + [discovery-popular {:contacts contacts + :platform-specific platform-specific}] [view st/section-spacing [text {:style st/discovery-subtitle diff --git a/src/status_im/discovery/search_results.cljs b/src/status_im/discovery/search_results.cljs new file mode 100644 index 0000000000..6fdf3420c7 --- /dev/null +++ b/src/status_im/discovery/search_results.cljs @@ -0,0 +1,41 @@ +(ns status-im.discovery.search-results + (:require-macros [status-im.utils.views :refer [defview]]) + (:require [re-frame.core :refer [subscribe dispatch]] + [status-im.utils.listview :refer [to-datasource]] + [status-im.components.react :refer [view text list-view list-item]] + [status-im.components.toolbar :refer [toolbar]] + [status-im.discovery.views.discovery-list-item :refer [discovery-list-item]] + [status-im.discovery.styles :as st])) + +(defn render-separator [_ row-id _] + (list-item [view {:style st/row-separator + :key row-id}])) + +(defn title-content [tags platform-specific] + [view st/tag-title-container + (for [tag (take 3 tags)] + ^{:key (str "tag-" tag)} + [view {:style st/tag-container} + [text {:style st/tag-title + :platform-specific platform-specific + :font :default} + (str " #" tag)]])]) + +(defview discovery-search-results [{platform-specific :platform-specific}] + [discoveries [:get-discovery-search-results] + tags [:get :discovery-search-tags]] + (let [datasource (to-datasource discoveries)] + [view st/discovery-tag-container + [toolbar {:nav-action {:image {:source {:uri :icon_back} + :style st/icon-back} + :handler #(dispatch [:navigate-back])} + :custom-content (title-content tags platform-specific) + :action {:image {:source {:uri :icon_search} + :style st/icon-search} + :handler (fn [])}}] + + [list-view {:dataSource datasource + :renderRow (fn [row _ _] + (list-item [discovery-list-item row platform-specific])) + :renderSeparator render-separator + :style st/recent-list}]])) diff --git a/src/status_im/discovery/styles.cljs b/src/status_im/discovery/styles.cljs index 80fb34691e..09868c7e73 100644 --- a/src/status_im/discovery/styles.cljs +++ b/src/status_im/discovery/styles.cljs @@ -152,20 +152,22 @@ (def tag-title-container {:flex 1 :alignItems "center" - :justifyContent "center"}) + :justifyContent "center" + :flex-direction "row"}) (def tag-title {:color "#7099e6" - :fontFamily "sans-serif-medium" - :fontSize 14 - :paddingRight 5 - :paddingBottom 2}) + :font-size 14 + :padding-right 5 + :padding-bottom 2}) (def tag-container {:backgroundColor "#eef2f5" :flexWrap :wrap :borderRadius 5 - :padding 4}) + :padding 4 + :margin-left 2 + :margin-right 2}) (def icon-back {:width 8 diff --git a/src/status_im/discovery/subs.cljs b/src/status_im/discovery/subs.cljs index 3426ccf178..daede5ab7f 100644 --- a/src/status_im/discovery/subs.cljs +++ b/src/status_im/discovery/subs.cljs @@ -2,19 +2,28 @@ (:require-macros [reagent.ratom :refer [reaction]]) (:require [re-frame.core :refer [register-sub]])) -(register-sub :get-discoveries-by-tag - (fn [db [_ tag limit]] - (let [discoveries (reaction (:discoveries @db)) - tag' (or tag (:current-tag @db)) - filter-tag (filter #(some #{tag'} (map :name (:tags %)))) - xform (if limit - (comp filter-tag (take limit)) - filter-tag)] - (->> @discoveries - (into [] xform) - (reaction))))) +(defn- get-discoveries-by-tags [{:keys [discoveries current-tag]} tags limit] + (let [tags' (or tags [current-tag]) + filter-tag (filter #(every? (->> (map :name (:tags %)) + (into (hash-set))) + tags')) + xform (if limit + (comp filter-tag (take limit)) + filter-tag)] + (into [] xform discoveries))) + +(register-sub :get-discoveries-by-tags + (fn [db [_ tags limit]] + (-> (get-discoveries-by-tags @db tags limit) + (reaction)))) (register-sub :get-popular-tags (fn [db [_ limit]] - (reaction (take limit (:tags @db))))) + (-> (take limit (:tags @db)) + (reaction)))) +(register-sub :get-discovery-search-results + (fn [db _] + (let [tags (get-in @db [:discovery-search-tags])] + (-> (get-discoveries-by-tags @db tags nil) + (reaction))))) diff --git a/src/status_im/discovery/tag.cljs b/src/status_im/discovery/tag.cljs index df138105f9..ecbef79403 100644 --- a/src/status_im/discovery/tag.cljs +++ b/src/status_im/discovery/tag.cljs @@ -18,7 +18,7 @@ (defview discovery-tag [{platform-specific :platform-specific}] [tag [:get :current-tag] - discoveries [:get-discoveries-by-tag]] + discoveries [:get-discoveries-by-tags]] (let [datasource (to-datasource discoveries)] [view st/discovery-tag-container [toolbar {:nav-action {:image {:source {:uri :icon_back} diff --git a/src/status_im/discovery/views/popular.cljs b/src/status_im/discovery/views/popular.cljs index 3b9a021405..cc48a007ba 100644 --- a/src/status_im/discovery/views/popular.cljs +++ b/src/status_im/discovery/views/popular.cljs @@ -13,7 +13,7 @@ (defn page-width [] (.-width (.get (.. r/react-native -Dimensions) "window"))) -(defview popular [{:keys [contacts platform-specific]}] +(defview discovery-popular [{:keys [contacts platform-specific]}] [popular-tags [:get-popular-tags 10]] (if (pos? (count popular-tags)) [carousel {:pageStyle st/carousel-page-style} diff --git a/src/status_im/discovery/views/popular_list.cljs b/src/status_im/discovery/views/popular_list.cljs index f5d6b32bb1..9a156c1da1 100644 --- a/src/status_im/discovery/views/popular_list.cljs +++ b/src/status_im/discovery/views/popular_list.cljs @@ -16,7 +16,7 @@ :key row-id}])) (defview discovery-popular-list [{:keys [tag count contacts platform-specific]}] - [discoveries [:get-discoveries-by-tag tag 3]] + [discoveries [:get-discoveries-by-tags [tag] 3]] [view st/popular-list-container [view st/row [view st/tag-name-container diff --git a/src/status_im/ios/core.cljs b/src/status_im/ios/core.cljs index af2f9af54c..5b9ac512ea 100644 --- a/src/status_im/ios/core.cljs +++ b/src/status_im/ios/core.cljs @@ -13,6 +13,7 @@ [status-im.contacts.views.new-contact :refer [new-contact]] [status-im.qr-scanner.screen :refer [qr-scanner]] [status-im.discovery.tag :refer [discovery-tag]] + [status-im.discovery.search-results :refer [discovery-search-results]] [status-im.chat.screen :refer [chat]] [status-im.accounts.login.screen :refer [login]] [status-im.accounts.screen :refer [accounts]] @@ -70,6 +71,7 @@ (let [component (case (if true startup-view :chat) :discovery main-tabs :discovery-tag discovery-tag + :discovery-search-results discovery-search-results :add-participants new-participants :remove-participants remove-participants :chat-list main-tabs