From 69df1ad3ef385923b31b016bcafdeb28f44f1f1c Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Thu, 5 May 2016 15:55:11 +0300 Subject: [PATCH] added discover tag screen --- src/syng_im/android/core.cljs | 5 ++++- .../components/discovery/discovery.cljs | 8 ++----- .../discovery/discovery_popular.cljs | 9 +++----- .../discovery/discovery_popular_list.cljs | 12 +++++++---- ....cljs => discovery_popular_list_item.cljs} | 2 +- ...very-recent.cljs => discovery_recent.cljs} | 4 ++-- src/syng_im/db.cljs | 5 ++++- src/syng_im/handlers/discovery.cljs | 11 ++++++++++ src/syng_im/models/discoveries.cljs | 21 +++++++++++++++---- src/syng_im/subscribers/discovery.cljs | 13 +++++++++++- 10 files changed, 64 insertions(+), 26 deletions(-) rename src/syng_im/components/discovery/{discovery-popular-list-item.cljs => discovery_popular_list_item.cljs} (95%) rename src/syng_im/components/discovery/{discovery-recent.cljs => discovery_recent.cljs} (90%) diff --git a/src/syng_im/android/core.cljs b/src/syng_im/android/core.cljs index 2a66ca68a9..78342567ee 100644 --- a/src/syng_im/android/core.cljs +++ b/src/syng_im/android/core.cljs @@ -9,6 +9,7 @@ [syng-im.components.react :refer [navigator app-registry]] [syng-im.components.contact-list.contact-list :refer [contact-list]] [syng-im.components.discovery.discovery :refer [discovery]] + [syng-im.components.discovery.discovery-tag :refer [discovery-tag]] [syng-im.components.chat :refer [chat]] [syng-im.components.sign-up :refer [sign-up-view]] [syng-im.components.sign-up-confirm :refer [sign-up-confirm-view]] @@ -46,6 +47,7 @@ (init-back-button-handler! nav) (case view-id :discovery (r/as-element [discovery {:navigator nav}]) + :discovery-tag (r/as-element [discovery-tag {:navigator nav}]) :add-participants (r/as-element [new-participants {:navigator nav}]) :remove-participants (r/as-element [remove-participants {:navigator nav}]) :chat-list (r/as-element [chats-list {:navigator nav}]) @@ -53,7 +55,8 @@ :contact-list (r/as-element [contact-list {:navigator nav}]) :chat (r/as-element [chat {:navigator nav}]) :sign-up (r/as-element [sign-up-view {:navigator nav}]) - :sign-up-confirm (r/as-element [sign-up-confirm-view {:navigator nav}])))))}]) + :sign-up-confirm (r/as-element [sign-up-confirm-view {:navigator nav}]) + (log/error "No matching route: " route nav)))))}]) (defn init [] (dispatch-sync [:initialize-db]) diff --git a/src/syng_im/components/discovery/discovery.cljs b/src/syng_im/components/discovery/discovery.cljs index d92b395eba..f9b9b1340e 100644 --- a/src/syng_im/components/discovery/discovery.cljs +++ b/src/syng_im/components/discovery/discovery.cljs @@ -91,18 +91,14 @@ [text {:style {:color "#8f838c93" :fontFamily "sans-serif-medium" :fontSize 14}} "Popular tags"]] - [discovery-popular] + [discovery-popular navigator] [view {:style {:paddingLeft 30 :paddingTop 15 :paddingBottom 15}} [text {:style {:color "#8f838c93" :fontSize 14 :fontFamily "sans-serif-medium"}} "Recent"]] - [discovery-recent] - ] - ] - ) - )) + [discovery-recent]]]))) (comment (def page-width (aget (natal-shell.dimensions/get "window") "width")) (def page-height (aget (natal-shell.dimensions/get "window") "height")) diff --git a/src/syng_im/components/discovery/discovery_popular.cljs b/src/syng_im/components/discovery/discovery_popular.cljs index e7f03b0dfa..7e2b144e19 100644 --- a/src/syng_im/components/discovery/discovery_popular.cljs +++ b/src/syng_im/components/discovery/discovery_popular.cljs @@ -11,7 +11,7 @@ (defn page-width [] (.-width (.get (.. js/React -Dimensions) "window"))) -(defn discovery-popular [] +(defn discovery-popular [navigator] (let [popular-tags (subscribe [:get-popular-tags 3])] (log/debug "Got popular tags: " @popular-tags) (if (> (count @popular-tags) 0) @@ -24,8 +24,5 @@ :pageWidth (- (page-width) 60) :sneak 20} (for [tag @popular-tags] - (discovery-popular-list (.-name tag) (.-count tag)))] - [text "None"] - ) - ) - ) \ No newline at end of file + (discovery-popular-list (.-name tag) (.-count tag) navigator))] + [text "None"]))) \ No newline at end of file diff --git a/src/syng_im/components/discovery/discovery_popular_list.cljs b/src/syng_im/components/discovery/discovery_popular_list.cljs index 8ac9f0aeba..32e88b536e 100644 --- a/src/syng_im/components/discovery/discovery_popular_list.cljs +++ b/src/syng_im/components/discovery/discovery_popular_list.cljs @@ -5,6 +5,7 @@ [syng-im.components.react :refer [android? view list-view + touchable-highlight text image]] [reagent.core :as r] @@ -25,7 +26,7 @@ :key rowID}])] elem)) -(defn discovery-popular-list [tag count] +(defn discovery-popular-list [tag count navigator] (let [discoveries (subscribe [:get-discoveries-by-tag tag 3])] (log/debug "Got discoveries for tag (" tag "): " @discoveries) [view {:style {:flex 1 @@ -37,17 +38,19 @@ :padding 0}} [view {:style { :flexDirection "column"}} - [view {:style {:backgroundColor "#eef2f5" + [touchable-highlight {:onPress (fn [event] + (dispatch [:show-discovery-tag tag navigator :push]))} + [view {:style {:backgroundColor "#eef2f5" :borderRadius 5 :padding 4}} - [text {:style {:color "#7099e6" + [text {:style {:color "#7099e6" :fontFamily "sans-serif-medium" :fontSize 14 :paddingRight 5 :paddingBottom 2 :alignItems "center" :justifyContent "center"}} - (str " #" (name tag))]]] + (str " #" (name tag))]]]] [view {:style {:flex 0.2 :alignItems "flex-end" :paddingTop 10 @@ -61,6 +64,7 @@ :justifyContent "center"}} count]]] [list-view {:dataSource (to-realm-datasource @discoveries) + :enableEmptySections true :renderRow render-row :renderSeparator render-separator :style {:backgroundColor "white" diff --git a/src/syng_im/components/discovery/discovery-popular-list-item.cljs b/src/syng_im/components/discovery/discovery_popular_list_item.cljs similarity index 95% rename from src/syng_im/components/discovery/discovery-popular-list-item.cljs rename to src/syng_im/components/discovery/discovery_popular_list_item.cljs index 86b11dc3d0..7ce2fb4abe 100644 --- a/src/syng_im/components/discovery/discovery-popular-list-item.cljs +++ b/src/syng_im/components/discovery/discovery_popular_list_item.cljs @@ -1,4 +1,4 @@ -(ns syng-im.components.discovery.discovery-popular-list-item +(ns syng-im.components.discovery.discovery_popular_list_item (:require [syng-im.utils.logging :as log] [syng-im.components.react :refer [android? diff --git a/src/syng_im/components/discovery/discovery-recent.cljs b/src/syng_im/components/discovery/discovery_recent.cljs similarity index 90% rename from src/syng_im/components/discovery/discovery-recent.cljs rename to src/syng_im/components/discovery/discovery_recent.cljs index a7b1fb0566..bcec31b005 100644 --- a/src/syng_im/components/discovery/discovery-recent.cljs +++ b/src/syng_im/components/discovery/discovery_recent.cljs @@ -1,4 +1,4 @@ -(ns syng-im.components.discovery.discovery-recent +(ns syng-im.components.discovery.discovery_recent (:require-macros [natal-shell.data-source :refer [data-source clone-with-rows]] @@ -9,7 +9,7 @@ view]] [syng-im.components.realm :refer [list-view]] [syng-im.utils.listview :refer [to-realm-datasource]] - [syng-im.components.discovery.discovery-popular-list-item :refer [discovery-popular-list-item]] + [syng-im.components.discovery.discovery_popular_list_item :refer [discovery-popular-list-item]] [reagent.core :as r])) diff --git a/src/syng_im/db.cljs b/src/syng_im/db.cljs index a1fd91e52e..1976ed8e19 100644 --- a/src/syng_im/db.cljs +++ b/src/syng_im/db.cljs @@ -14,7 +14,8 @@ :chats-updated-signal 0 :name "My Name" :new-group #{} - :new-participants #{}}) + :new-participants #{} + :current-tag nil}) (def protocol-initialized-path [:protocol-initialized]) @@ -34,3 +35,5 @@ (def updated-discoveries-signal-path [:discovery-updated-signal]) (defn updated-discovery-signal-path [whisper-id] [:discoveries whisper-id :discovery-updated-signal]) +(def current-tag-path [:current-tag]) +(def updated-current-tag-signal-path [:current-tag-updated-signal]) diff --git a/src/syng_im/handlers/discovery.cljs b/src/syng_im/handlers/discovery.cljs index b1d81d472a..45e3b06a6f 100644 --- a/src/syng_im/handlers/discovery.cljs +++ b/src/syng_im/handlers/discovery.cljs @@ -2,7 +2,11 @@ (:require [re-frame.core :refer [register-handler after dispatch]] [syng-im.utils.logging :as log] [syng-im.protocol.api :as api] + [syng-im.navigation :refer [nav-push + nav-replace + nav-pop]] [syng-im.models.discoveries :refer [save-discoveries + set-current-tag signal-discoveries-updated]])) @@ -30,4 +34,11 @@ (let [name (:name db)] (log/debug "Status: " status ", Hashtags: " hashtags) (api/broadcast-discover-status name status hashtags) + db))) + +(register-handler :show-discovery-tag + (fn [db [action tag navigator nav-type]] + (log/debug action "setting current tag: " tag) + (let [db (set-current-tag db tag)] + (dispatch [:navigate-to navigator {:view-id :discovery-tag} nav-type]) db))) \ No newline at end of file diff --git a/src/syng_im/models/discoveries.cljs b/src/syng_im/models/discoveries.cljs index 91cc9d9030..1efa9c5012 100644 --- a/src/syng_im/models/discoveries.cljs +++ b/src/syng_im/models/discoveries.cljs @@ -16,6 +16,17 @@ (defn discoveries-updated? [db] (get-in db db/updated-discoveries-signal-path)) +(defn current-tag-updated? [db] + (get-in db db/updated-current-tag-signal-path)) + + + +(defn current-tag [db] + (get-in db db/current-tag-path)) + +(defn set-current-tag [db tag] + (assoc-in db db/current-tag-path tag)) + (defn get-tag [tag] (log/debug "Getting tag: " tag) (-> (r/get-by-field :tag :name tag) @@ -100,10 +111,12 @@ (add-discoveries discoveries)) (defn discoveries-by-tag [tag limit] - (log/debug "Discoveries by tag: " tag) - (-> (r/get-by-filter :discoveries (str "tags.name = '" tag "'")) - (r/sorted :last-updated :desc) - (r/page 0 limit))) + (let [discoveries (-> (r/get-by-filter :discoveries (str "tags.name = '" tag "'")) + (r/sorted :last-updated :desc))] + (log/debug "Discoveries by tag: " tag) + (if (pos? limit) + (r/page discoveries 0 limit) + discoveries))) (defn get-tag-popular [limit] (-> (r/get-all :tag) diff --git a/src/syng_im/subscribers/discovery.cljs b/src/syng_im/subscribers/discovery.cljs index eeca5fe593..49375de678 100644 --- a/src/syng_im/subscribers/discovery.cljs +++ b/src/syng_im/subscribers/discovery.cljs @@ -4,8 +4,10 @@ [syng-im.db :as db] [syng-im.utils.logging :as log] [syng-im.models.discoveries :refer [discovery-list + current-tag get-tag-popular discoveries-by-tag + current-tag-updated? discoveries-updated?]])) @@ -34,4 +36,13 @@ (log/debug "Getting tags limited: " limit) (reaction (let [_ @discoveries-updated] - (get-tag-popular limit)))))) \ No newline at end of file + (get-tag-popular limit)))))) + +(register-sub :get-current-tag + (fn [db _] + (let [current-tag-updated (-> (current-tag-updated? @db) + (reaction))] + (reaction + (let [_ @current-tag-updated] + (current-tag @db)))))) +