defview suggestion
This commit is contained in:
parent
85e05a451d
commit
780b12049e
|
@ -1,4 +1,5 @@
|
|||
(ns syng-im.discovery.screen
|
||||
(:require-macros [syng-im.utils.views :refer [defview]])
|
||||
(:require
|
||||
[re-frame.core :refer [dispatch subscribe]]
|
||||
[syng-im.components.react :refer [view
|
||||
|
@ -29,10 +30,8 @@
|
|||
(defn toogle-search [current-value]
|
||||
(dispatch [:set ::show-search (not current-value)]))
|
||||
|
||||
(defn discovery []
|
||||
[]
|
||||
(let [show-search (subscribe [:get ::show-search])]
|
||||
(fn []
|
||||
(defview discovery []
|
||||
[show-search [:get ::show-search]]
|
||||
[view st/discovery-container
|
||||
[toolbar
|
||||
{:style st/discovery-toolbar
|
||||
|
@ -40,14 +39,14 @@
|
|||
:style st/hamburger-icon}
|
||||
:handler #(dispatch [:create-fake-discovery!])}
|
||||
:title "Add Participants"
|
||||
:content [title-content @show-search]
|
||||
:content [title-content show-search]
|
||||
:action {:image {:source {:uri :icon_search}
|
||||
:style st/search-icon}
|
||||
:handler #(toogle-search @show-search)}}]
|
||||
:handler #(toogle-search show-search)}}]
|
||||
[scroll-view {:style {}}
|
||||
[view st/section-spacing
|
||||
[text {:style st/discovery-subtitle} "Popular tags"]]
|
||||
[popular]
|
||||
[view st/section-spacing
|
||||
[text {:style st/discovery-subtitle} "Recent"]]
|
||||
[discovery-recent]]])))
|
||||
[discovery-recent]]])
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
(ns syng-im.discovery.views.popular
|
||||
(:require-macros [syng-im.utils.views :refer [defview]])
|
||||
(:require
|
||||
[re-frame.core :refer [subscribe]]
|
||||
[syng-im.utils.logging :as log]
|
||||
|
@ -11,12 +12,11 @@
|
|||
(defn page-width []
|
||||
(.-width (.get (.. js/React -Dimensions) "window")))
|
||||
|
||||
(defn popular []
|
||||
(let [popular-tags (subscribe [:get-popular-tags 3])]
|
||||
(log/debug "Got popular tags: " @popular-tags)
|
||||
(if (pos? (count @popular-tags))
|
||||
(defview popular []
|
||||
[popular-tags [:get-popular-tags 3]]
|
||||
(if (pos? (count popular-tags))
|
||||
[carousel {:pageStyle st/carousel-page-style
|
||||
:sneak 20}
|
||||
(for [{:keys [name count]} @popular-tags]
|
||||
(for [{:keys [name count]} popular-tags]
|
||||
[discovery-popular-list name count])]
|
||||
[text "None"])))
|
||||
[text "None"]))
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
(ns syng-im.discovery.views.popular-list
|
||||
(:require-macros [syng-im.utils.views :refer [defview]])
|
||||
(:require
|
||||
[re-frame.core :refer [subscribe dispatch]]
|
||||
[syng-im.components.react :refer [view
|
||||
|
@ -17,9 +18,8 @@
|
|||
(list-item [view {:style st/row-separator
|
||||
:key row-id}]))
|
||||
|
||||
(defn discovery-popular-list [tag count]
|
||||
(let [discoveries (subscribe [:get-discoveries-by-tag tag 3])]
|
||||
(fn [tag count]
|
||||
(defview discovery-popular-list [tag count]
|
||||
[discoveries [:get-discoveries-by-tag tag 3]]
|
||||
[view st/popular-list-container
|
||||
[view st/row
|
||||
[view st/tag-name-container
|
||||
|
@ -27,8 +27,8 @@
|
|||
[text {:style st/tag-name} (str " #" (name tag))]]]
|
||||
[view st/tag-count-container
|
||||
[text {:style st/tag-count} count]]]
|
||||
[list-view {:dataSource (to-datasource @discoveries)
|
||||
[list-view {:dataSource (to-datasource discoveries)
|
||||
:enableEmptySections true
|
||||
:renderRow render-row
|
||||
:renderSeparator render-separator
|
||||
:style st/popular-list}]])))
|
||||
:style st/popular-list}]])
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
(ns syng-im.discovery.views.popular-list-item
|
||||
;syng-im.discovery.views.popular-list-item
|
||||
(:require [syng-im.components.react :refer [view text image]]
|
||||
[syng-im.discovery.styles :as st]
|
||||
[reagent.core :as r]))
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
(ns syng-im.discovery.views.recent
|
||||
(:require-macros [syng-im.utils.views :refer [defview]])
|
||||
(:require
|
||||
[re-frame.core :refer [subscribe]]
|
||||
[syng-im.components.react :refer [view list-view list-item]]
|
||||
|
@ -14,11 +15,9 @@
|
|||
(list-item [view {:style st/row-separator
|
||||
:key row-id}]))
|
||||
|
||||
(defn discovery-recent []
|
||||
(let [discoveries (subscribe [:get :discoveries])]
|
||||
(fn []
|
||||
;; todo fetch more on :onEndReached
|
||||
[list-view {:dataSource (to-datasource @discoveries)
|
||||
(defview discovery-recent []
|
||||
[discoveries [:get :discoveries]]
|
||||
[list-view {:dataSource (to-datasource discoveries)
|
||||
:renderRow render-row
|
||||
:renderSeparator render-separator
|
||||
:style st/recent-list}])))
|
||||
:style st/recent-list}])
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
(ns syng-im.utils.views)
|
||||
|
||||
(defn prepare-subs [subs]
|
||||
(let [pairs (map (fn [[form sub]]
|
||||
{:form form
|
||||
:sub sub
|
||||
:sym (gensym)})
|
||||
(partition 2 subs))]
|
||||
[(mapcat (fn [{:keys [sym sub]}]
|
||||
[sym `(re-frame.core/subscribe ~sub)])
|
||||
pairs)
|
||||
(mapcat (fn [{:keys [sym form]}]
|
||||
[form `(deref ~sym)])
|
||||
pairs)]))
|
||||
|
||||
(defmacro defview
|
||||
[n params & rest]
|
||||
(let [[subs body] (if (= 1 (count rest))
|
||||
[nil (first rest)]
|
||||
rest)
|
||||
[subs-bindings vars-bindings] (prepare-subs subs)]
|
||||
`(defn ~n ~params
|
||||
(let [~@subs-bindings]
|
||||
(fn ~params
|
||||
(let [~@vars-bindings]
|
||||
~body))))))
|
||||
|
Loading…
Reference in New Issue