From 78e01fb227423a44a0cce3f6ad88f9b08114ec52 Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Fri, 22 Apr 2016 18:32:42 +0300 Subject: [PATCH] code cleaning --- .../discovery-popular-list-item.cljs | 6 +- .../discovery/discovery-recent.cljs | 19 +-- .../components/discovery/discovery.cljs | 112 +++++------------- .../discovery/discovery_popular.cljs | 17 +-- .../discovery/discovery_popular_list.cljs | 13 +- 5 files changed, 38 insertions(+), 129 deletions(-) diff --git a/src/syng_im/components/discovery/discovery-popular-list-item.cljs b/src/syng_im/components/discovery/discovery-popular-list-item.cljs index 5e582f9aa8..de3dcd457b 100644 --- a/src/syng_im/components/discovery/discovery-popular-list-item.cljs +++ b/src/syng_im/components/discovery/discovery-popular-list-item.cljs @@ -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]) ) diff --git a/src/syng_im/components/discovery/discovery-recent.cljs b/src/syng_im/components/discovery/discovery-recent.cljs index 1ee787e77a..ef4c93dfb9 100644 --- a/src/syng_im/components/discovery/discovery-recent.cljs +++ b/src/syng_im/components/discovery/discovery-recent.cljs @@ -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)] diff --git a/src/syng_im/components/discovery/discovery.cljs b/src/syng_im/components/discovery/discovery.cljs index 7f543b6bbf..bee5873a69 100644 --- a/src/syng_im/components/discovery/discovery.cljs +++ b/src/syng_im/components/discovery/discovery.cljs @@ -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}}] - ]] + ) diff --git a/src/syng_im/components/discovery/discovery_popular.cljs b/src/syng_im/components/discovery/discovery_popular.cljs index 71841db1ee..b452cb9b18 100644 --- a/src/syng_im/components/discovery/discovery_popular.cljs +++ b/src/syng_im/components/discovery/discovery_popular.cljs @@ -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"))) diff --git a/src/syng_im/components/discovery/discovery_popular_list.cljs b/src/syng_im/components/discovery/discovery_popular_list.cljs index 191821a2b2..0a1274eecc 100644 --- a/src/syng_im/components/discovery/discovery_popular_list.cljs +++ b/src/syng_im/components/discovery/discovery_popular_list.cljs @@ -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