From b00ebe5e024f6ece54baabce6ce4c24c3faeb0d4 Mon Sep 17 00:00:00 2001 From: Goran Jovic Date: Tue, 24 Oct 2017 11:56:59 +0200 Subject: [PATCH] bug #2281 - wrong hashtags in discover main screen --- src/status_im/ui/screens/discover/subs.cljs | 8 +++ src/status_im/ui/screens/discover/views.cljs | 62 +++++++++++--------- 2 files changed, 41 insertions(+), 29 deletions(-) diff --git a/src/status_im/ui/screens/discover/subs.cljs b/src/status_im/ui/screens/discover/subs.cljs index e5976c7b95..5aab0cb84c 100644 --- a/src/status_im/ui/screens/discover/subs.cljs +++ b/src/status_im/ui/screens/discover/subs.cljs @@ -35,6 +35,14 @@ {:discoveries (take limit discoveries) :total (count discoveries)})))) +(reg-sub :get-top-discovery-per-tag + (fn [{:keys [discoveries tags]} [_ limit]] + (let [tag-names (map :name (take limit tags))] + (for [tag tag-names] + (let [results (get-discoveries-by-tags discoveries tag nil)] + [tag {:discovery (first results) + :total (count results)}]))))) + (reg-sub :get-recent-discoveries (fn [db] (sort-by :created-at > (vals (:discoveries db))))) diff --git a/src/status_im/ui/screens/discover/views.cljs b/src/status_im/ui/screens/discover/views.cljs index 7cf73b8373..0962bb50b0 100644 --- a/src/status_im/ui/screens/discover/views.cljs +++ b/src/status_im/ui/screens/discover/views.cljs @@ -47,8 +47,8 @@ (re-frame/dispatch [:navigate-to :discover-search-results]))))}]) -(defview top-status-for-popular-hashtag [{:keys [tag current-account contacts]}] - (letsubs [discoveries [:get-popular-discoveries 1 [tag]]] +(defn top-status-for-popular-hashtag [{:keys [tag item current-account contacts]}] + (let [{:keys [discovery total]} item] [react/view styles/popular-list-container [react/view styles/row [react/view {} @@ -62,29 +62,29 @@ [react/view styles/tag-count-container [react/text {:style styles/tag-count :font :default} - (str (:total discoveries))]]] - [components/discover-list-item {:message (first (:discoveries discoveries)) + (str total)]]] + [components/discover-list-item {:message discovery :show-separator? false :current-account current-account :contacts contacts}]])) -(defview popular-hashtags-preview [{:keys [contacts current-account]}] - (letsubs [popular-tags [:get-popular-tags 10]] - (let [has-content? (seq popular-tags)] - [react/view styles/popular-container - ;; TODO (goranjovic) - refactor double dispatch to a single call - [components/title :t/popular-tags :t/all #(do (re-frame/dispatch [:set :discover-search-tags (map :name popular-tags)]) - (re-frame/dispatch [:navigate-to :discover-all-hashtags])) has-content?] - (if has-content? - [carousel/carousel {:pageStyle styles/carousel-page-style - :gap 8 - :sneak 16 - :count (count popular-tags)} - (for [{:keys [name]} popular-tags] - [top-status-for-popular-hashtag {:tag name - :contacts contacts - :current-account current-account}])] - [empty-section :empty-hashtags :t/no-hashtags-discovered-title :t/no-hashtags-discovered-body])]))) +(defn popular-hashtags-preview [{:keys [popular-discoveries popular-tags contacts current-account]}] + (let [has-content? (seq popular-tags)] + [react/view styles/popular-container + ;; TODO (goranjovic) - refactor double dispatch to a single call + [components/title :t/popular-tags :t/all #(do (re-frame/dispatch [:set :discover-search-tags (map :name popular-tags)]) + (re-frame/dispatch [:navigate-to :discover-all-hashtags])) has-content?] + (if has-content? + [carousel/carousel {:pageStyle styles/carousel-page-style + :gap 8 + :sneak 16 + :count (count popular-tags)} + (for [[tag item] popular-discoveries] + [top-status-for-popular-hashtag {:tag tag + :item item + :contacts contacts + :current-account current-account}])] + [empty-section :empty-hashtags :t/no-hashtags-discovered-title :t/no-hashtags-discovered-body])])) (defn recent-statuses-preview [{:keys [current-account contacts discoveries]}] (let [has-content? (seq discoveries)] @@ -139,12 +139,14 @@ :render-fn render-public-chats-item}]]) (defview discover [current-view?] - (letsubs [show-search [:get-in [:toolbar-search :show]] - search-text [:get-in [:toolbar-search :text]] - contacts [:get-contacts] - current-account [:get-current-account] - discoveries [:get-recent-discoveries] - all-dapps [:get-all-dapps]] + (letsubs [show-search [:get-in [:toolbar-search :show]] + search-text [:get-in [:toolbar-search :text]] + contacts [:get-contacts] + current-account [:get-current-account] + discoveries [:get-recent-discoveries] + all-dapps [:get-all-dapps] + popular-tags [:get-popular-tags 10] + popular-discoveries [:get-top-discovery-per-tag 10]] [react/view styles/discover-container [toolbar-view (and current-view? (= show-search :discover)) search-text] @@ -152,7 +154,9 @@ [recent-statuses-preview {:contacts contacts :current-account current-account :discoveries discoveries}] - [popular-hashtags-preview {:contacts contacts - :current-account current-account}] + [popular-hashtags-preview {:popular-tags popular-tags + :popular-discoveries popular-discoveries + :contacts contacts + :current-account current-account}] [all-dapps/preview all-dapps] [public-chats-teaser]]]))