code cleaning

This commit is contained in:
Adrian Tiberius 2016-04-22 18:32:42 +03:00
parent f32fb04c1a
commit 78e01fb227
5 changed files with 38 additions and 129 deletions

View File

@ -3,12 +3,8 @@
[syng-im.utils.debug :refer [log]]
[syng-im.components.react :refer [android?
view
scroll-view
list-view
text
image
navigator
toolbar-android]]
image]]
[syng-im.resources :as res]
[reagent.core :as r])
)

View File

@ -4,21 +4,13 @@
)
(:require
[re-frame.core :refer [subscribe dispatch dispatch-sync]]
[re-frame.core :refer [subscribe]]
[syng-im.components.react :refer [android?
view
scroll-view
text
image
navigator
toolbar-android]]
view]]
[syng-im.components.realm :refer [list-view]]
[syng-im.utils.listview :refer [to-realm-datasource]]
[syng-im.components.carousel :refer [carousel]]
[syng-im.components.discovery.discovery-popular-list-item :refer [discovery-popular-list-item]]
[syng-im.models.discoveries :refer [generate-discoveries]]
[reagent.core :as r]
[syng-im.resources :as res]))
[reagent.core :as r]))
(defn render-row [row section-id row-id]
@ -32,11 +24,6 @@
:key rowID}])]
elem))
(defn get-data-source [elements]
(clone-with-rows (data-source {:rowHasChanged (fn [row1 row2]
(not= (:discovery-id row1) (:discovery-id row2)))})
elements))
(defn discovery-recent []
(let [discoveries (subscribe [:get-discoveries])
datasource (to-realm-datasource @discoveries)]

View File

@ -1,63 +1,24 @@
(ns syng-im.components.discovery.discovery
(:require
[re-frame.core :refer [subscribe dispatch dispatch-sync]]
[syng-im.utils.debug :refer [log]]
[re-frame.core :refer [dispatch]]
[syng-im.components.react :refer [android?
view
scroll-view
text
text-input
image
navigator
toolbar-android]]
[reagent.core :as r]
[syng-im.components.discovery.discovery-popular :refer [discovery-popular]]
[syng-im.components.discovery.discovery-recent :refer [discovery-recent]]
[syng-im.models.discoveries :refer [generate-discoveries
generate-discovery
save-discoveries]]
[syng-im.utils.listview :refer [to-realm-datasource]]
[syng-im.resources :as res]
[syng-im.persistence.realm :as realm]))
(def log (.-log js/console))
(def search-input (atom {:search "x"}))
(def toolbar-title [text "Discover"])
(def toolbar-search [text-input {:underlineColorAndroid "transparent"
:value (:search @search-input)
:style {:flex 1
:marginLeft 18
:lineHeight 42
:fontSize 14
:fontFamily "Avenir-Roman"
:color "#9CBFC0"}
:autoFocus true
:placeholder "Type your search tags here"
:onChangeText (fn [new-text]
(let [old-text (:search @search-input)]
(log (str new-text "-" old-text))
(if (not (= new-text old-text))
(swap! search-input assoc :search new-text))
))
:onSubmitEditing (fn [e]
(log (aget e "nativeEvent" "text")))}])
(def showSearch (r/atom false))
(def content (r/atom toolbar-title))
(defn toggle-search []
(if @showSearch
(do
(reset! showSearch false)
(reset! content toolbar-title))
(do
(reset! showSearch true)
(reset! content toolbar-search))))
(defn discovery [{:keys [navigator]}]
(let [showSearch (r/atom false)]
(fn []
[view {:style {:flex 1
:backgroundColor "#eef2f5"}}
@ -82,9 +43,31 @@
:tags [{:name "tag1"} {:name "tag2"}]
:last-updated (new js/Date)} true)
(dispatch [:updated-discoveries])))))
;; temporary dispatch for testing
:onActionSelected (fn [index]
(toggle-search))}
@content]
(if @showSearch
(reset! showSearch false)
(reset! showSearch true)))}
(if @showSearch
[text-input {:underlineColorAndroid "transparent"
:value (:search @search-input)
:style {:flex 1
:marginLeft 18
:lineHeight 42
:fontSize 14
:fontFamily "Avenir-Roman"
:color "#9CBFC0"}
:autoFocus true
:placeholder "Type your search tags here"
:onChangeText (fn [new-text]
(let [old-text (:search @search-input)]
(log (str new-text "-" old-text))
(if (not (= new-text old-text))
(swap! search-input assoc :search new-text))
))
:onSubmitEditing (fn [e]
(log (aget e "nativeEvent" "text")))}]
[text "Discover"])]
[scroll-view {:style {}}
[view {:style {:paddingTop 5}}
@ -108,46 +91,9 @@
]
]
)
)
))
(comment
(def page-width (aget (natal-shell.dimensions/get "window") "width"))
(def page-height (aget (natal-shell.dimensions/get "window") "height"))
[view {:style {:flex 1
:backgroundColor "white"}}
[toolbar-android {:title "Discover"
:titleColor "#4A5258"
:navIcon res/menu
:actions [{:title "Search"
:icon res/search
:show "always"}]
:style {:backgroundColor "white"
:height 56
:elevation 2}
:onIconClicked (fn []
(.log console "testttt"))
:onActionSelected (fn [index]
(index))}]
[scroll-view {:style { }}
[view {:style {:paddingLeft 30
:paddingTop 15
:paddingBottom 15}}
[text {:style {:color "#232323"
:fontSize 18
:fontWeight "bold"}} "Popular Tags"]]
[carousel {:pageStyle {:backgroundColor "white", :borderRadius 5}
:pageWidth (- page-width 60)}
[view {:style {:height (- page-height 100)}} [text {:style {:color "#232323"
:fontSize 18
:fontWeight "bold"}} "Popular Tags"]]
[view [text "Welcome to Syng"]]
[view [text "Welcome to Syng"]]
[view [text "Welcome to Syng"]]]
[view {:style {:paddingLeft 30
:paddingTop 15
:paddingBottom 15}}
[text {:style {:color "#232323"
:fontSize 18
:fontWeight "bold"}} "Recent"]]
[view {:style {:height 200}}]
]]
)

View File

@ -1,23 +1,12 @@
(ns syng-im.components.discovery.discovery-popular
(:require-macros [reagent.ratom :refer [reaction]])
(:require
[re-frame.core :refer [subscribe dispatch dispatch-sync]]
[re-frame.core :refer [subscribe]]
[syng-im.utils.debug :refer [log]]
[syng-im.components.react :refer [android?
view
scroll-view
text
image
navigator
toolbar-android]]
text]]
[syng-im.components.carousel :refer [carousel]]
[syng-im.components.discovery.discovery-popular-list :refer [discovery-popular-list]]
[syng-im.models.discoveries :refer [generate-discoveries
generate-discovery
save-discoveries
group-by-tag
get-discovery-recent]]
[syng-im.resources :as res]))
))
(defn page-width []
(.-width (.get (.. js/React -Dimensions) "window")))

View File

@ -7,12 +7,9 @@
[syng-im.utils.debug :refer [log]]
[syng-im.components.react :refer [android?
view
scroll-view
list-view
text
image
navigator
toolbar-android]]
image]]
[reagent.core :as r]
[syng-im.components.realm :refer [list-view]]
[syng-im.utils.listview :refer [to-realm-datasource]]
@ -31,11 +28,6 @@
:key rowID}])]
elem))
(defn get-data-source [elements]
(clone-with-rows (data-source {:rowHasChanged (fn [row1 row2]
(not= (:discovery-id row1) (:discovery-id row2)))})
elements))
(defn discovery-popular-list [tag]
(let [discoveries (subscribe [:get-discoveries-by-tag tag 3])
_ (log (str "Got discoveries for tag (" tag "): ") @discoveries)
@ -60,8 +52,7 @@
:renderRow render-row
:renderSeparator render-separator
:style {:backgroundColor "white"}}]
])
))
])))
(comment
list-view {:dataSource elements