added discover tag screen

Former-commit-id: 69df1ad3ef
This commit is contained in:
Adrian Tiberius 2016-05-05 15:55:11 +03:00
parent ee3800897d
commit 997d0bd4d8
10 changed files with 64 additions and 26 deletions

View File

@ -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])

View File

@ -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"))

View File

@ -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"]
)
)
)
(discovery-popular-list (.-name tag) (.-count tag) navigator))]
[text "None"])))

View File

@ -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,6 +38,8 @@
:padding 0}}
[view {:style {
:flexDirection "column"}}
[touchable-highlight {:onPress (fn [event]
(dispatch [:show-discovery-tag tag navigator :push]))}
[view {:style {:backgroundColor "#eef2f5"
:borderRadius 5
:padding 4}}
@ -47,7 +50,7 @@
: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"

View File

@ -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?

View File

@ -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]))

View File

@ -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])

View File

@ -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]]))
@ -31,3 +35,10 @@
(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)))

View File

@ -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]
(let [discoveries (-> (r/get-by-filter :discoveries (str "tags.name = '" tag "'"))
(r/sorted :last-updated :desc))]
(log/debug "Discoveries by tag: " tag)
(-> (r/get-by-filter :discoveries (str "tags.name = '" tag "'"))
(r/sorted :last-updated :desc)
(r/page 0 limit)))
(if (pos? limit)
(r/page discoveries 0 limit)
discoveries)))
(defn get-tag-popular [limit]
(-> (r/get-all :tag)

View File

@ -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?]]))
@ -35,3 +37,12 @@
(reaction
(let [_ @discoveries-updated]
(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))))))