Merge pull request #193 from status-im/feature/discovery-search
Discovery search
Former-commit-id: bf308bfd21
This commit is contained in:
commit
dd87315e9a
|
@ -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
|
||||
|
|
|
@ -17,3 +17,5 @@
|
|||
(def response-suggesstion-resize-duration 100)
|
||||
|
||||
(def default-number-of-messages 20)
|
||||
|
||||
(def default-number-of-discovery-search-results 20)
|
|
@ -23,6 +23,9 @@
|
|||
|
||||
:new-contact-identity ""
|
||||
:contacts {}
|
||||
:discoveries []
|
||||
:discovery-search-tags []
|
||||
:tags {}
|
||||
|
||||
:contacts-ids #{}
|
||||
:selected-contacts #{}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,7 +65,7 @@
|
|||
:platform-specific platform-specific
|
||||
:font :medium}
|
||||
(label :t/popular-tags)]]
|
||||
[popular {:contacts contacts
|
||||
[discovery-popular {:contacts contacts
|
||||
:platform-specific platform-specific}]
|
||||
|
||||
[view st/section-spacing
|
||||
|
|
|
@ -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}]]))
|
|
@ -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
|
||||
|
|
|
@ -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 %))))
|
||||
(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)]
|
||||
(->> @discoveries
|
||||
(into [] xform)
|
||||
(reaction)))))
|
||||
(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)))))
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue