From 376241fe385e8133640d20be56a5e15974a51ac1 Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Fri, 8 Apr 2016 03:56:36 +0300 Subject: [PATCH 01/23] Added discover screen --- images/ic_menu_black_24dp_1x.png | Bin 0 -> 82 bytes images/ic_search_black_24dp_1x.png | Bin 0 -> 249 bytes src/syng_im/components/carousel.cljs | 15 ++ .../discovery-popular-list-item.cljs | 40 ++++ .../discovery/discovery-recent.cljs | 44 +++++ .../components/discovery/discovery.cljs | 106 ++++++++++ .../discovery/discovery_popular.cljs | 42 ++++ .../discovery/discovery_popular_list.cljs | 64 ++++++ src/syng_im/models/discoveries.cljs | 183 ++++++++++++++++++ 9 files changed, 494 insertions(+) create mode 100644 images/ic_menu_black_24dp_1x.png create mode 100644 images/ic_search_black_24dp_1x.png create mode 100644 src/syng_im/components/carousel.cljs create mode 100644 src/syng_im/components/discovery/discovery-popular-list-item.cljs create mode 100644 src/syng_im/components/discovery/discovery-recent.cljs create mode 100644 src/syng_im/components/discovery/discovery.cljs create mode 100644 src/syng_im/components/discovery/discovery_popular.cljs create mode 100644 src/syng_im/components/discovery/discovery_popular_list.cljs create mode 100644 src/syng_im/models/discoveries.cljs diff --git a/images/ic_menu_black_24dp_1x.png b/images/ic_menu_black_24dp_1x.png new file mode 100644 index 0000000000000000000000000000000000000000..ef2a48c7ab615434fd8b1014cbc63f93a30650cd GIT binary patch literal 82 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM0wlfaz7_*1NlzEYkP60R1;(DH|1F9$r34bL fTwXj+j+No7M)p*t{aYUZ6)||a`njxgN@xNA)tnXQ literal 0 HcmV?d00001 diff --git a/images/ic_search_black_24dp_1x.png b/images/ic_search_black_24dp_1x.png new file mode 100644 index 0000000000000000000000000000000000000000..6b16343235c2729720113158598c891fd041949f GIT binary patch literal 249 zcmV|r4fyyw@M>+ir$LGPVo;#@wk2g)LvA~nWu7_00000NkvXXu0mjfU?OPG literal 0 HcmV?d00001 diff --git a/src/syng_im/components/carousel.cljs b/src/syng_im/components/carousel.cljs new file mode 100644 index 0000000000..5a6eb07019 --- /dev/null +++ b/src/syng_im/components/carousel.cljs @@ -0,0 +1,15 @@ +(ns syng-im.components.carousel) + +(set! js/Carousel (.-default (js/require "react-native-carousel-control"))) + + +(defn carousel [opts & children] + (apply js/React.createElement js/Carousel (clj->js opts) children)) + + + +(comment + + + + ) \ No newline at end of file diff --git a/src/syng_im/components/discovery/discovery-popular-list-item.cljs b/src/syng_im/components/discovery/discovery-popular-list-item.cljs new file mode 100644 index 0000000000..da4fc87488 --- /dev/null +++ b/src/syng_im/components/discovery/discovery-popular-list-item.cljs @@ -0,0 +1,40 @@ +(ns syng-im.components.discovery.discovery-popular-list-item + (:require + [syng-im.components.react :refer [android? + view + scroll-view + list-view + text + image + navigator + toolbar-android]] + [syng-im.resources :as res] + [reagent.core :as r]) + ) + +(defn discovery-popular-list-item [discovery] + (r/as-element [view {:style {:flexDirection "row" + :paddingTop 10 + :paddingBottom 10}} + [view {:style {:flex 0.8 + :flexDirection "column"}} + [text {:style {:color "black" + :fontWeight "bold" + :fontSize 12}} (aget discovery "name")] + [text {:style {:color "black" + :fontWeight "normal" + :fontSize 12} + :numberOfLines 2} (aget discovery "status")] + ] + [view {:style {:flex 0.2 + :flexDirection "column" + :alignItems "center" + :paddingTop 5}} + [image {:style {:resizeMode "contain" + :borderRadius 150 + :width 30 + :height 30} + :source res/user-no-photo}] + ] + ]) + ) \ No newline at end of file diff --git a/src/syng_im/components/discovery/discovery-recent.cljs b/src/syng_im/components/discovery/discovery-recent.cljs new file mode 100644 index 0000000000..f1450fdc33 --- /dev/null +++ b/src/syng_im/components/discovery/discovery-recent.cljs @@ -0,0 +1,44 @@ +(ns syng-im.components.discovery.discovery-recent + (:require-macros + [natal-shell.data-source :refer [data-source clone-with-rows]] + + ) + (:require + [syng-im.components.react :refer [android? + view + scroll-view + list-view + text + image + navigator + toolbar-android]] + [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])) + + +(defn render-row [row section-id row-id] + (let [elem (discovery-popular-list-item row)] + elem) + ) + +(defn render-separator [sectionID, rowID, adjacentRowHighlighted] + (let [elem (r/as-element [view {:style {:borderBottomWidth 1 + :borderBottomColor "#eff2f3"} + :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 [recent-discoveries] + [list-view {:dataSource (get-data-source recent-discoveries) + :renderRow render-row + :renderSeparator render-separator + :style {:backgroundColor "white" + :paddingLeft 15}}] + ) \ No newline at end of file diff --git a/src/syng_im/components/discovery/discovery.cljs b/src/syng_im/components/discovery/discovery.cljs new file mode 100644 index 0000000000..01d9944009 --- /dev/null +++ b/src/syng_im/components/discovery/discovery.cljs @@ -0,0 +1,106 @@ +(ns syng-im.components.discovery.discovery + + (:require + [re-frame.core :refer [subscribe dispatch dispatch-sync]] + [syng-im.components.react :refer [android? + view + scroll-view + text + 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 + get-discovery-popular + get-discovery-recent]] + [syng-im.resources :as res])) + +(defn discovery [{:keys [navigator]}] + (let [discoveries (subscribe [:get-discoveries]) + pop-discoveries (get-discovery-popular 3)] + (fn [] + [view {:style {:flex 1 + :backgroundColor "#edf2f5"}} + [toolbar-android {:title "Discover" + :titleColor "#4A5258" + :navIcon res/menu + :actions [{:title "Search" + :icon res/search + :show "always"}] + :style {:backgroundColor "white" + :justifyContent "center" + :height 56 + :elevation 2} + :onIconClicked (fn [] + (.log console "testttt")) + :onActionSelected (fn [index] + (index))}] + + [scroll-view {:style {}} + [view {:style {:paddingTop 5}} + [text {:style {:color "#b2bdc5" + :fontSize 14 + :textAlign "center"}} "Discover popular contacts \n around the world"]] + [view {:style {:paddingLeft 30 + :paddingTop 15 + :paddingBottom 15}} + [text {:style {:color "#b2bdc5" + :fontSize 14 + :fontWeight "bold"}} "Popular Tags"]] + [discovery-popular pop-discoveries] + [view {:style {:paddingLeft 30 + :paddingTop 15 + :paddingBottom 15}} + [text {:style {:color "#b2bdc5" + :fontSize 14 + :fontWeight "bold"}} "Recent"]] + [discovery-recent (get-discovery-recent 10)] + ] + ] + ) + ) + ) + (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 new file mode 100644 index 0000000000..ef1863c4fa --- /dev/null +++ b/src/syng_im/components/discovery/discovery_popular.cljs @@ -0,0 +1,42 @@ +(ns syng-im.components.discovery.discovery-popular + + (:require + [syng-im.components.react :refer [android? + view + scroll-view + text + image + navigator + toolbar-android]] + [syng-im.components.carousel :refer [carousel]] + [syng-im.components.discovery.discovery-popular-list :refer [discovery-popular-list]] + [syng-im.models.discoveries :refer [generate-discoveries]] + [syng-im.resources :as res])) + +(defn page-width [] + (.-width (.get (.. js/React -Dimensions) "window"))) + + +(defn discovery-popular [popular-discoveries] + (let [popular-lists (mapv #(discovery-popular-list % (get popular-discoveries %)) (keys popular-discoveries))] + (if (> (count popular-lists) 0) + (apply carousel {:pageStyle {:borderRadius 1 + :shadowColor "black" + :shadowRadius 1 + :shadowOpacity 0.8 + :elevation 2 + :marginBottom 10} + :pageWidth (- (page-width) 60) + + } + popular-lists + ) + [text "None"] + ) + ) + ) + +(comment + (set! React (js/require "react-native")) + (.get (.Dimensions React) "window") + ) \ 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 new file mode 100644 index 0000000000..741bd3c12c --- /dev/null +++ b/src/syng_im/components/discovery/discovery_popular_list.cljs @@ -0,0 +1,64 @@ +(ns syng-im.components.discovery.discovery-popular-list + (:require-macros + [natal-shell.data-source :refer [data-source clone-with-rows]] + + ) + (:require + [syng-im.components.react :refer [android? + view + scroll-view + list-view + text + image + navigator + toolbar-android]] + [reagent.core :as r] + [syng-im.components.discovery.discovery-popular-list-item :refer [discovery-popular-list-item] ]) + ) + + +(defn render-row [row section-id row-id] + (let [elem (discovery-popular-list-item row)] + elem) +) + +(defn render-separator [sectionID, rowID, adjacentRowHighlighted] + (let [elem (r/as-element [view {:style {:borderBottomWidth 1 + :borderBottomColor "#eff2f3"} + :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 elements] + (r/as-element [view {:style {:flex 1 + :backgroundColor "white" + :paddingLeft 10 + :paddingTop 10}} + [view {:style {:flexDirection "row" + :backgroundColor "white" + :padding 0}} + [view {:style {:flexDirection "column" + :backgroundColor "#e9f7fe" + :borderRadius 5 + :padding 0}} + [text {:style {:color "#6092df" + :paddingRight 5 + :paddingBottom 2 + :alignItems "center" + :justifyContent "center"}} (str " #" (name tag))]]] + [list-view {:dataSource (get-data-source elements) + :renderRow render-row + :renderSeparator render-separator + :style {:backgroundColor "white"}}] + ]) + ) + +(comment + list-view {:dataSource elements + :renderRow (partial render-row list-element) + :style {:backgroundColor "white"}} + ) \ No newline at end of file diff --git a/src/syng_im/models/discoveries.cljs b/src/syng_im/models/discoveries.cljs new file mode 100644 index 0000000000..7d99315e73 --- /dev/null +++ b/src/syng_im/models/discoveries.cljs @@ -0,0 +1,183 @@ +(ns syng-im.models.discoveries + (:require [cljs.core.async :as async :refer [chan put! !]] + [re-frame.core :refer [subscribe dispatch dispatch-sync]] + [syng-im.utils.utils :refer [log toast]] + [syng-im.persistence.realm :as realm] + [syng-im.persistence.realm :as r] + [syng-im.resources :as res] + [syng-im.db :as db])) + +;; TODO see https://github.com/rt2zz/react-native-contacts/issues/45 +(def fake-discoveries? true) + + + +(defn signal-discovery-updated [db] + (update-in db db/updated-discovery-signal-path (fn [current] + (if current + (inc current) + 0)))) + +(defn discovery-updated? [db] + (get-in db db/updated-discovery-signal-path)) + +(defn- generate-discovery [n] + {:discovery-id n + :name (str "Contact " n) + :status (apply str (repeat (+ n 3) "Contact Status ")) + :whisper-id (str "id-" n) + :photo "" + :tags ["tag1" "tag2"] + :last-updated (js/Date. "10/01/2015") + }) + +(defn- generate-discoveries [n] + (map generate-discovery (range 1 (inc n)))) + +(def fake-discoveries (generate-discoveries 20)) + +(defn- get-discoveries [] + ( let [list (realm/get-list :discoveries)] + (if (> (.-length list) 0) (.slice list 0) []))) + +(defn load-syng-discoveries [db] + (let [discoveries (map (fn [discovery] + (merge discovery + {})) + (get-discoveries))] + (assoc db :discoveries discoveries))) + +(defn get-tag [tag] + (-> (r/get-by-field :tag :name tag) + (r/single-cljs))) + +(defn remove-tag [tag] + (let [tag-object (get-tag tag)] + (if tag-object + (realm/create :tag + {:name tag + :count (dec (:count tag-object)) + })))) + +(defn add-tag [tag] + (let [tag-object (get-tag tag) + counter (if tag-object (:count tag-object) 1)] + (realm/create :tag + {:name tag + :count (inc counter) + } + (if tag-object true false)))) + +(defn remove-tags [tags] + (doseq [tag tags] + (remove-tag tag))) + +(defn add-tags [tags] + (doseq [tag tags] + (add-tag tag))) + +(defn get-tags [whisper-id] + (:tags (-> (r/get-by-field :discoveries :whisper-id whisper-id) + (r/single-cljs)))) + +(defn- create-discovery [{:keys [name status whisper-id photo tags last-updated]}] + (do + ;(add-tags tags) + (realm/create :discoveries + {:name name + :status status + :whisper-id whisper-id + :photo photo + :tags (mapv (fn [tag] + {:name tag}) tags) + :last-updated last-updated} true) + ) + ) + + + +(defn- update-discovery [{:keys [name status whisper-id photo tags last-updated]}] + (let [old-tags (get-tags whisper-id)] + (do + ;;(remove-tags old-tags) + ;;(add-tags tags) + (realm/create :discoveries + {:name name + :status status + :whisper-id whisper-id + :photo photo + :tags (mapv (fn [tag] + {:name tag}) tags) + :last-updated last-updated} + true) + )) + ) + +(defn- discovery-exist? [discoveries discovery] + (some #(= (:whisper-id discovery) (:whisper-id %)) discoveries)) + +(defn- add-discoveries [discoveries] + (realm/write (fn [] + (let [db-discoveries (get-discoveries)] + (dorun (map (fn [discovery] + (if (not (discovery-exist? db-discoveries discovery)) + (create-discovery discovery) + (update-discovery discovery) + )) + discoveries)))))) + +(defn save-discoveries [discoveries] + (add-discoveries discoveries)) + +(defn discovery-list [] + (-> (r/get-all :discoveries) + (r/sorted :discovery-id :desc))) + +(defn get-discovery-recent [limit] + (if fake-discoveries? + (take limit fake-discoveries) + (-> (r/get-all :discoveries) + (r/sorted :last-updated :desc) + (r/page 0 limit))) + ) + +(defn get-tag-popular [limit] + (-> (r/get-all :tag) + (r/sorted :count :desc) + (r/page 0 limit))) + +(defn add-with-limit [data value limit] + (if (>= (count data) limit) + data + (conj data value)) + ) + +(defn group-by-tag [discoveries tag-limit] + (reduce (fn [result discovery] + (let [keys (:tags discovery)] + (reduce (fn [data key] + (assoc data (keyword key) (add-with-limit (get data (keyword key) []) discovery tag-limit))) + result + keys))) + {} + discoveries) + ) + +(defn get-discovery-popular [tag-limit] + (if fake-discoveries? + (group-by-tag fake-discoveries tag-limit) + (-> (r/get-all :discoveries) + (r/sorted :last-updated :desc) + (.slice 0) + (group-by-tag tag-limit)) + ) + ) + +(comment + (group-by-tag [{:tags ["a" "b" "c"] + :name "test1"} + {:tags ["a" "c"] + :name "test2"} + {:tags ["c"] + :name "test3"}]) + ) \ No newline at end of file From 14523c6e18de4ad7d8a7d8505e032d30de8160dc Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Fri, 8 Apr 2016 03:59:58 +0300 Subject: [PATCH 02/23] Added discover screen - part 2 --- .re-natal | 5 +- README.md | 19 +++++- env/dev/env/android/main.cljs | 2 +- figwheel-bridge.js | 95 ++++++++++++++---------------- package.json | 1 + src/syng_im/android/core.cljs | 5 +- src/syng_im/components/react.cljs | 1 + src/syng_im/db.cljs | 3 + src/syng_im/handlers.cljs | 7 +++ src/syng_im/persistence/realm.cljs | 21 ++++++- src/syng_im/resources.cljs | 2 + src/syng_im/subs.cljs | 12 ++++ 12 files changed, 114 insertions(+), 59 deletions(-) diff --git a/.re-natal b/.re-natal index 8fd652b4ea..38d8997409 100644 --- a/.re-natal +++ b/.re-natal @@ -1,7 +1,7 @@ { "name": "SyngIm", "interface": "reagent", - "androidHost": "10.0.3.2", + "androidHost": "10.0.2.2", "modules": [ "react-native-contacts", "react-native-invertible-scroll-view", @@ -13,7 +13,8 @@ "react-native-action-button", "react-native-vector-icons/Ionicons", "react-native-circle-checkbox", - "react-native-randombytes" + "react-native-randombytes", + "react-native-carousel-control" ], "imageDirs": [ "images" diff --git a/README.md b/README.md index 19e1fbc53f..65349be5fc 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,24 @@ A Clojure library designed to ... well, that part is up to you. ## Usage -FIXME +- install syng-lib/protocol in lein + +Linux: + +optional: $ npm upgrade -g re-natal +optional: $ re-natal upgrade +$ re-natal deps +$ re-natal use-android-device +$ re-natal use-figwheel +$ lein figwheel android + +- new terminal(only for linux) +$ react-native start + +- new terminal +$ adb reverse tcp:8081 tcp:8081 +$ adb reverse tcp:3449 tcp:3449 +$ react-native run-android ## License diff --git a/env/dev/env/android/main.cljs b/env/dev/env/android/main.cljs index 2348604c4a..5519aa004d 100644 --- a/env/dev/env/android/main.cljs +++ b/env/dev/env/android/main.cljs @@ -11,7 +11,7 @@ (def root-el (r/as-element [reloader])) (figwheel/watch-and-reload - :websocket-url "ws://10.0.3.2:3449/figwheel-ws" + :websocket-url "ws://10.0.2.2:3449/figwheel-ws" :heads-up-display true :jsload-callback #(swap! cnt inc)) diff --git a/figwheel-bridge.js b/figwheel-bridge.js index 2a7cb1cc2f..6df4702339 100644 --- a/figwheel-bridge.js +++ b/figwheel-bridge.js @@ -5,6 +5,7 @@ */ var CLOSURE_UNCOMPILED_DEFINES = null; +var debugEnabled = false; var config = { basePath: "target/", @@ -13,13 +14,24 @@ var config = { }; var React = require('react-native'); +var WebSocket = require('WebSocket'); var self; var scriptQueue = []; var serverHost = null; // will be set dynamically var fileBasePath = null; // will be set dynamically var evaluate = eval; // This is needed, direct calls to eval does not work (RN packager???) var externalModules = {}; -var evalListeners = []; // functions to be called when a script is evaluated +var evalListeners = [ // Functions to be called after each js file is loaded and evaluated + function (url) { + if (url.indexOf('jsloader') > -1) { + shimJsLoader(); + } + }, + function (url) { + if (url.indexOf('/figwheel/client/socket') > -1) { + setCorrectWebSocketImpl(); + } + }]; var figwheelApp = function (platform, devHost) { return React.createClass({ @@ -40,7 +52,7 @@ var figwheelApp = function (platform, devHost) { componentDidMount: function () { var app = this; if (typeof goog === "undefined") { - loadApp(platform, devHost, function(appRoot) { + loadApp(platform, devHost, function (appRoot) { app.setState({root: appRoot, loaded: true}) }); } @@ -48,13 +60,19 @@ var figwheelApp = function (platform, devHost) { }) }; +function logDebug(msg) { + if (debugEnabled) { + console.log(msg); + } +} + // evaluates js code ensuring proper ordering function customEval(url, javascript, success, error) { if (scriptQueue.length > 0) { if (scriptQueue[0] === url) { try { evaluate(javascript); - console.info('Evaluated: ' + url); + logDebug('Evaluated: ' + url); scriptQueue.shift(); evalListeners.forEach(function (listener) { listener(url) @@ -81,7 +99,7 @@ var isChrome = function () { }; function asyncImportScripts(url, success, error) { - console.info('(asyncImportScripts) Importing: ' + url); + logDebug('(asyncImportScripts) Importing: ' + url); scriptQueue.push(url); fetch(url) .then(function (response) { @@ -100,7 +118,7 @@ function asyncImportScripts(url, success, error) { function syncImportScripts(url, success, error) { try { importScripts(url); - console.info('Evaluated: ' + url); + logDebug('Evaluated: ' + url); evalListeners.forEach(function (listener) { listener(url) }); @@ -123,7 +141,7 @@ function importJs(src, success, error) { var file = fileBasePath + '/' + src; - console.info('(importJs) Importing: ' + file); + logDebug('(importJs) Importing: ' + file); if (isChrome()) { syncImportScripts(serverBaseUrl("localhost") + '/' + file, success, error); } else { @@ -143,43 +161,49 @@ function interceptRequire() { }; } -// do not show debug messages in yellow box -function debugToLog() { - console.debug = console.log; +function compileWarningsToYellowBox() { + var log = window.console.log; + var compileWarningRx = /Figwheel: Compile/; + window.console.log = function (msg) { + if (compileWarningRx.test(msg)) { + console.warn(msg); + } else { + log.call(window.console, msg); + } + }; } function serverBaseUrl(host) { return "http://" + host + ":" + config.serverPort } +function setCorrectWebSocketImpl() { + figwheel.client.socket.get_websocket_imp = function () { + return WebSocket; + }; +} + function loadApp(platform, devHost, onLoadCb) { serverHost = devHost; fileBasePath = config.basePath + platform; - evalListeners.push(function (url) { - if (url.indexOf('jsloader') > -1) { - shimJsLoader(); - } - }); - // callback when app is ready to get the reloadable component var mainJs = '/env/' + platform + '/main.js'; evalListeners.push(function (url) { if (url.indexOf(mainJs) > -1) { onLoadCb(env[platform].main.root_el); - console.log('Done loading Clojure app'); + console.info('Done loading Clojure app'); } }); if (typeof goog === "undefined") { - console.log('Loading Closure base.'); + console.info('Loading Closure base.'); interceptRequire(); + compileWarningsToYellowBox(); importJs('goog/base.js', function () { shimBaseGoog(); - fakeLocalStorageAndDocument(); importJs('cljs_deps.js'); importJs('goog/deps.js', function () { - debugToLog(); // This is needed because of RN packager // seriously React packager? why. var googreq = goog.require; @@ -209,39 +233,6 @@ function shimBaseGoog() { importJs(src); return true; }; - goog.inHtmlDocument_ = function () { - return true; - }; -} - -function fakeLocalStorageAndDocument() { - window.localStorage = {}; - window.localStorage.getItem = function () { - return 'true'; - }; - window.localStorage.setItem = function () { - }; - - window.document = {}; - window.document.body = {}; - window.document.body.dispatchEvent = function () { - }; - window.document.createElement = function () { - }; - - if (typeof window.location === 'undefined') { - window.location = {}; - } - console.debug = console.warn; - window.addEventListener = function () { - }; - // make figwheel think that heads-up-display divs are there - window.document.querySelector = function (selector) { - return {}; - }; - window.document.getElementById = function (id) { - return {style:{}}; - }; } // Figwheel fixes diff --git a/package.json b/package.json index f069c032a4..bb1a49ac6a 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "awesome-phonenumber": "^1.0.12", "react-native": "^0.22.0", "react-native-action-button": "^1.1.3", + "react-native-carousel-control": "^1.0.1", "react-native-circle-checkbox": "^0.1.3", "react-native-contacts": "^0.2.1", "react-native-i18n": "0.0.8", diff --git a/src/syng_im/android/core.cljs b/src/syng_im/android/core.cljs index 83fbd67e02..d4e74d348e 100644 --- a/src/syng_im/android/core.cljs +++ b/src/syng_im/android/core.cljs @@ -8,6 +8,7 @@ [syng-im.subs] [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.chat :refer [chat]] [syng-im.components.sign-up :refer [sign-up-view]] [syng-im.components.sign-up-confirm :refer [sign-up-confirm-view]] @@ -34,7 +35,7 @@ (add-event-listener "hardwareBackPress" new-listener))))) (defn app-root [] - [navigator {:initial-route (clj->js {:view-id :chat-list}) + [navigator {:initial-route (clj->js {:view-id :discovery}) :render-scene (fn [route nav] (log/debug "route" route) (when true ;; nav/*nav-render* @@ -42,6 +43,7 @@ view-id (keyword view-id)] (init-back-button-handler! nav) (case view-id + :discovery (r/as-element [discovery {:navigator nav}]) :chat-list (r/as-element [chats-list {:navigator nav}]) :new-group (r/as-element [new-group {:navigator nav}]) :contact-list (r/as-element [contact-list {:navigator nav}]) @@ -51,6 +53,7 @@ (defn init [] (dispatch-sync [:initialize-db]) + ;;(dispatch-sync [:generate-discoveries]) (dispatch [:initialize-crypt]) (dispatch [:initialize-protocol]) (dispatch [:load-user-phone-number]) diff --git a/src/syng_im/components/react.cljs b/src/syng_im/components/react.cljs index a9f31957b7..020f657e7a 100644 --- a/src/syng_im/components/react.cljs +++ b/src/syng_im/components/react.cljs @@ -12,6 +12,7 @@ (def toolbar-android (r/adapt-react-class (.-ToolbarAndroid js/React))) (def list-view (r/adapt-react-class (.-ListView js/React))) (def text-input (r/adapt-react-class (.-TextInput js/React))) +(def scroll-view (r/adapt-react-class (.-ScrollView js/React))) (def platform (.. js/React -Platform -OS)) diff --git a/src/syng_im/db.cljs b/src/syng_im/db.cljs index 3f404f3b33..20be9042e8 100644 --- a/src/syng_im/db.cljs +++ b/src/syng_im/db.cljs @@ -28,3 +28,6 @@ (defn chat-command-content-path [chat-id] [:chats chat-id :command-input :content]) (def new-group-path [:new-group]) +(def updated-discovery-signal-path [:discovery-updated-signal]) +(defn updated-discovery-signal-path [discovery-id] + [:discoveries discovery-id :discovery-updated-signal]) diff --git a/src/syng_im/handlers.cljs b/src/syng_im/handlers.cljs index fc462f3ea7..97087f6f5e 100644 --- a/src/syng_im/handlers.cljs +++ b/src/syng_im/handlers.cljs @@ -9,6 +9,7 @@ set-initialized]] [syng-im.models.user-data :as user-data] [syng-im.models.contacts :as contacts] + [syng-im.models.discoveries :as discoveries] [syng-im.models.messages :refer [save-message update-message! message-by-id]] @@ -274,6 +275,12 @@ (log/debug action from group-id identities) (create-chat db group-id identities true group-name))) +;; -- Discovery -------------------------------------------------------------- + +(register-handler :generate-discoveries + (fn [db _] + (discoveries/save-discoveries (discoveries/generate-discoveries 10)))) + (comment ) diff --git a/src/syng_im/persistence/realm.cljs b/src/syng_im/persistence/realm.cljs index 694ff7af16..3007a23a42 100644 --- a/src/syng_im/persistence/realm.cljs +++ b/src/syng_im/persistence/realm.cljs @@ -44,7 +44,24 @@ :group-chat "bool" :timestamp "int" :contacts {:type "list" - :objectType "chat-contact"}}}]}) + :objectType "chat-contact"}}} + {:name :tag + :primaryKey :name + :properties {:name "string" + :count {:type "int" + :optional true + :default 1}}} + {:name :discoveries + :primaryKey :whisper-id + :properties {:name "string" + :status "string" + :whisper-id "string" + :photo "string" + :tags {:type "list" + :objectType "tag"} + :last-updated "date"}} + + ]}) (def realm (js/Realm. (clj->js opts))) @@ -122,7 +139,7 @@ (.-length objs)) (defn get-list [schema-name] - (vals (js->clj (.objects realm (to-string schema-name)) :keywordize-keys true))) + (vals (js->clj (.slice (.objects realm (to-string schema-name)) 0) :keywordize-keys true))) (comment diff --git a/src/syng_im/resources.cljs b/src/syng_im/resources.cljs index 52a956d3f6..086e68d7da 100644 --- a/src/syng_im/resources.cljs +++ b/src/syng_im/resources.cljs @@ -13,3 +13,5 @@ (def smile (js/require "./images/smile.png")) (def att (js/require "./images/att.png")) (def v (js/require "./images/v.png")) +(def menu (js/require "./images/ic_menu_black_24dp_1x.png")) +(def search (js.require "./images/ic_search_black_24dp_1x.png")) \ No newline at end of file diff --git a/src/syng_im/subs.cljs b/src/syng_im/subs.cljs index 2b13739689..6f0bb82ebb 100644 --- a/src/syng_im/subs.cljs +++ b/src/syng_im/subs.cljs @@ -7,6 +7,8 @@ [syng-im.models.chats :refer [chats-list chats-updated? chat-by-id]] + [syng-im.models.discoveries :refer [discovery-list + discovery-updated?]] [syng-im.models.messages :refer [get-messages]] [syng-im.models.contacts :refer [contacts-list]] [syng-im.handlers.suggestions :refer [get-suggestions]])) @@ -63,6 +65,16 @@ (chat-by-id chat-id)) (reaction))))) +;; -- Discoveries list -------------------------------------------------------------- + +(register-sub :get-discoveries + (fn [db _] + (let [discovery-updated (-> (discovery-updated? @db) + (reaction))] + (reaction + (let [_ @discovery-updated] + (discovery-list)))))) + ;; -- User data -------------------------------------------------------------- (register-sub From 726ea23dd666475768d4ed1acb8f28be3fe06a92 Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Fri, 8 Apr 2016 04:42:59 +0300 Subject: [PATCH 03/23] Updated re-natal --- .re-natal | 3 ++- env/dev/env/android/main.cljs | 9 ++++----- env/dev/env/ios/main.cljs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.re-natal b/.re-natal index 38d8997409..f189f9162b 100644 --- a/.re-natal +++ b/.re-natal @@ -18,5 +18,6 @@ ], "imageDirs": [ "images" - ] + ], + "iosHost": "localhost" } \ No newline at end of file diff --git a/env/dev/env/android/main.cljs b/env/dev/env/android/main.cljs index 5519aa004d..54c052c041 100644 --- a/env/dev/env/android/main.cljs +++ b/env/dev/env/android/main.cljs @@ -1,13 +1,12 @@ (ns ^:figwheel-no-load env.android.main - (:require [reagent.core :as r] - [syng-im.android.core :refer [app-root]] - [figwheel.client :as figwheel :include-macros true] - [syng-im.android.core :as core])) + (:require [reagent.core :as r] + [syng-im.android.core :as core] + [figwheel.client :as figwheel :include-macros true])) (enable-console-print!) (def cnt (r/atom 0)) -(defn reloader [] @cnt [app-root]) +(defn reloader [] @cnt [core/app-root]) (def root-el (r/as-element [reloader])) (figwheel/watch-and-reload diff --git a/env/dev/env/ios/main.cljs b/env/dev/env/ios/main.cljs index 748936a414..f5c132e346 100644 --- a/env/dev/env/ios/main.cljs +++ b/env/dev/env/ios/main.cljs @@ -11,7 +11,7 @@ (figwheel/watch-and-reload :websocket-url "ws://localhost:3449/figwheel-ws" - :heads-up-display true + :heads-up-display false :jsload-callback #(swap! cnt inc)) (core/init) \ No newline at end of file From 8d0e3a906d519e9591cfe01207da071155e0820c Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Fri, 8 Apr 2016 04:50:25 +0300 Subject: [PATCH 04/23] fix readme layout --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 65349be5fc..828d1bf75a 100644 --- a/README.md +++ b/README.md @@ -6,21 +6,30 @@ A Clojure library designed to ... well, that part is up to you. - install syng-lib/protocol in lein -Linux: +#### Linux: optional: $ npm upgrade -g re-natal + optional: $ re-natal upgrade + $ re-natal deps + $ re-natal use-android-device + $ re-natal use-figwheel + $ lein figwheel android - new terminal(only for linux) + $ react-native start - new terminal + $ adb reverse tcp:8081 tcp:8081 + $ adb reverse tcp:3449 tcp:3449 + $ react-native run-android ## License From 9a4b8e8b94baf823861e71cae0c5994725b4b9ad Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Sun, 17 Apr 2016 16:49:35 +0300 Subject: [PATCH 05/23] fixed realm db usage in listview --- .re-natal | 2 +- src/syng_im/android/core.cljs | 1 - .../discovery-popular-list-item.cljs | 6 +- .../discovery/discovery-recent.cljs | 12 ++- .../components/discovery/discovery.cljs | 77 +++++++++++++++---- .../discovery/discovery_popular.cljs | 18 +++-- .../discovery/discovery_popular_list.cljs | 16 ++-- src/syng_im/db.cljs | 6 +- src/syng_im/handlers.cljs | 7 +- src/syng_im/handlers/discovery.cljs | 24 ++++++ src/syng_im/models/discoveries.cljs | 50 ++++++------ src/syng_im/persistence/realm.cljs | 8 +- src/syng_im/protocol/protocol_handler.cljs | 2 + src/syng_im/subs.cljs | 10 +-- src/syng_im/subscribers/discovery.cljs | 38 +++++++++ src/syng_im/utils/debug.cljs | 3 + 16 files changed, 202 insertions(+), 78 deletions(-) create mode 100644 src/syng_im/handlers/discovery.cljs create mode 100644 src/syng_im/subscribers/discovery.cljs create mode 100644 src/syng_im/utils/debug.cljs diff --git a/.re-natal b/.re-natal index f189f9162b..8a8e33774a 100644 --- a/.re-natal +++ b/.re-natal @@ -1,7 +1,7 @@ { "name": "SyngIm", "interface": "reagent", - "androidHost": "10.0.2.2", + "androidHost": "10.0.3.2", "modules": [ "react-native-contacts", "react-native-invertible-scroll-view", diff --git a/src/syng_im/android/core.cljs b/src/syng_im/android/core.cljs index d4e74d348e..d7f2bf13d7 100644 --- a/src/syng_im/android/core.cljs +++ b/src/syng_im/android/core.cljs @@ -53,7 +53,6 @@ (defn init [] (dispatch-sync [:initialize-db]) - ;;(dispatch-sync [:generate-discoveries]) (dispatch [:initialize-crypt]) (dispatch [:initialize-protocol]) (dispatch [:load-user-phone-number]) 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 da4fc87488..5e582f9aa8 100644 --- a/src/syng_im/components/discovery/discovery-popular-list-item.cljs +++ b/src/syng_im/components/discovery/discovery-popular-list-item.cljs @@ -1,5 +1,6 @@ (ns syng-im.components.discovery.discovery-popular-list-item (:require + [syng-im.utils.debug :refer [log]] [syng-im.components.react :refer [android? view scroll-view @@ -13,7 +14,8 @@ ) (defn discovery-popular-list-item [discovery] - (r/as-element [view {:style {:flexDirection "row" + (let [_ (log discovery)] + (r/as-element [view {:style {:flexDirection "row" :paddingTop 10 :paddingBottom 10}} [view {:style {:flex 0.8 @@ -37,4 +39,4 @@ :source res/user-no-photo}] ] ]) - ) \ No newline at end of file + )) \ No newline at end of file diff --git a/src/syng_im/components/discovery/discovery-recent.cljs b/src/syng_im/components/discovery/discovery-recent.cljs index f1450fdc33..1ee787e77a 100644 --- a/src/syng_im/components/discovery/discovery-recent.cljs +++ b/src/syng_im/components/discovery/discovery-recent.cljs @@ -4,14 +4,16 @@ ) (:require + [re-frame.core :refer [subscribe dispatch dispatch-sync]] [syng-im.components.react :refer [android? view scroll-view - list-view text image navigator toolbar-android]] + [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]] @@ -35,10 +37,12 @@ (not= (:discovery-id row1) (:discovery-id row2)))}) elements)) -(defn discovery-recent [recent-discoveries] - [list-view {:dataSource (get-data-source recent-discoveries) +(defn discovery-recent [] + (let [discoveries (subscribe [:get-discoveries]) + datasource (to-realm-datasource @discoveries)] + [list-view {:dataSource datasource :renderRow render-row :renderSeparator render-separator :style {:backgroundColor "white" :paddingLeft 15}}] - ) \ No newline at end of file + )) \ No newline at end of file diff --git a/src/syng_im/components/discovery/discovery.cljs b/src/syng_im/components/discovery/discovery.cljs index 01d9944009..7f543b6bbf 100644 --- a/src/syng_im/components/discovery/discovery.cljs +++ b/src/syng_im/components/discovery/discovery.cljs @@ -6,6 +6,7 @@ view scroll-view text + text-input image navigator toolbar-android]] @@ -13,30 +14,77 @@ [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 - get-discovery-popular - get-discovery-recent]] - [syng-im.resources :as res])) + 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 [discoveries (subscribe [:get-discoveries]) - pop-discoveries (get-discovery-popular 3)] (fn [] [view {:style {:flex 1 - :backgroundColor "#edf2f5"}} - [toolbar-android {:title "Discover" - :titleColor "#4A5258" + :backgroundColor "#eef2f5"}} + [toolbar-android {:titleColor "#4A5258" :navIcon res/menu :actions [{:title "Search" :icon res/search :show "always"}] - :style {:backgroundColor "white" - :justifyContent "center" + :style {:backgroundColor "#eef2f5" + :justifyContent "center" :height 56 :elevation 2} :onIconClicked (fn [] - (.log console "testttt")) + (realm/write (fn [] + (let [number (rand-int 30)] + (realm/create :discoveries + {:name (str "c" number) + :status (str "Status " number) + :whisper-id (str number) + :photo "" + :location "" + :tags [{:name "tag1"} {:name "tag2"}] + :last-updated (new js/Date)} true) + (dispatch [:updated-discoveries]))))) :onActionSelected (fn [index] - (index))}] + (toggle-search))} + @content] [scroll-view {:style {}} [view {:style {:paddingTop 5}} @@ -49,18 +97,17 @@ [text {:style {:color "#b2bdc5" :fontSize 14 :fontWeight "bold"}} "Popular Tags"]] - [discovery-popular pop-discoveries] + [discovery-popular] [view {:style {:paddingLeft 30 :paddingTop 15 :paddingBottom 15}} [text {:style {:color "#b2bdc5" :fontSize 14 :fontWeight "bold"}} "Recent"]] - [discovery-recent (get-discovery-recent 10)] + [discovery-recent] ] ] ) - ) ) (comment (def page-width (aget (natal-shell.dimensions/get "window") "width")) diff --git a/src/syng_im/components/discovery/discovery_popular.cljs b/src/syng_im/components/discovery/discovery_popular.cljs index ef1863c4fa..71841db1ee 100644 --- a/src/syng_im/components/discovery/discovery_popular.cljs +++ b/src/syng_im/components/discovery/discovery_popular.cljs @@ -1,6 +1,8 @@ (ns syng-im.components.discovery.discovery-popular - + (:require-macros [reagent.ratom :refer [reaction]]) (:require + [re-frame.core :refer [subscribe dispatch dispatch-sync]] + [syng-im.utils.debug :refer [log]] [syng-im.components.react :refer [android? view scroll-view @@ -10,15 +12,21 @@ toolbar-android]] [syng-im.components.carousel :refer [carousel]] [syng-im.components.discovery.discovery-popular-list :refer [discovery-popular-list]] - [syng-im.models.discoveries :refer [generate-discoveries]] + [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"))) - -(defn discovery-popular [popular-discoveries] - (let [popular-lists (mapv #(discovery-popular-list % (get popular-discoveries %)) (keys popular-discoveries))] +(defn discovery-popular [] + (let [popular-tags (subscribe [:get-popular-tags 3]) + _ (log "Got popular tags: ") + _ (log @popular-tags) + popular-lists (mapv #(discovery-popular-list (.-name %)) @popular-tags)] (if (> (count popular-lists) 0) (apply carousel {:pageStyle {:borderRadius 1 :shadowColor "black" diff --git a/src/syng_im/components/discovery/discovery_popular_list.cljs b/src/syng_im/components/discovery/discovery_popular_list.cljs index 741bd3c12c..191821a2b2 100644 --- a/src/syng_im/components/discovery/discovery_popular_list.cljs +++ b/src/syng_im/components/discovery/discovery_popular_list.cljs @@ -1,9 +1,10 @@ (ns syng-im.components.discovery.discovery-popular-list (:require-macros [natal-shell.data-source :refer [data-source clone-with-rows]] - ) (:require + [re-frame.core :refer [subscribe dispatch dispatch-sync]] + [syng-im.utils.debug :refer [log]] [syng-im.components.react :refer [android? view scroll-view @@ -13,6 +14,8 @@ navigator toolbar-android]] [reagent.core :as r] + [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] ]) ) @@ -33,8 +36,11 @@ (not= (:discovery-id row1) (:discovery-id row2)))}) elements)) -(defn discovery-popular-list [tag elements] - (r/as-element [view {:style {:flex 1 +(defn discovery-popular-list [tag] + (let [discoveries (subscribe [:get-discoveries-by-tag tag 3]) + _ (log (str "Got discoveries for tag (" tag "): ") @discoveries) + _ (log @discoveries)] + (r/as-element [view {:style {:flex 1 :backgroundColor "white" :paddingLeft 10 :paddingTop 10}} @@ -50,12 +56,12 @@ :paddingBottom 2 :alignItems "center" :justifyContent "center"}} (str " #" (name tag))]]] - [list-view {:dataSource (get-data-source elements) + [list-view {:dataSource (to-realm-datasource @discoveries) :renderRow render-row :renderSeparator render-separator :style {:backgroundColor "white"}}] ]) - ) + )) (comment list-view {:dataSource elements diff --git a/src/syng_im/db.cljs b/src/syng_im/db.cljs index 20be9042e8..741402a950 100644 --- a/src/syng_im/db.cljs +++ b/src/syng_im/db.cljs @@ -28,6 +28,6 @@ (defn chat-command-content-path [chat-id] [:chats chat-id :command-input :content]) (def new-group-path [:new-group]) -(def updated-discovery-signal-path [:discovery-updated-signal]) -(defn updated-discovery-signal-path [discovery-id] - [:discoveries discovery-id :discovery-updated-signal]) +(def updated-discoveries-signal-path [:discovery-updated-signal]) +(defn updated-discovery-signal-path [whisper-id] + [:discoveries whisper-id :discovery-updated-signal]) diff --git a/src/syng_im/handlers.cljs b/src/syng_im/handlers.cljs index 97087f6f5e..aefc61a686 100644 --- a/src/syng_im/handlers.cljs +++ b/src/syng_im/handlers.cljs @@ -9,7 +9,6 @@ set-initialized]] [syng-im.models.user-data :as user-data] [syng-im.models.contacts :as contacts] - [syng-im.models.discoveries :as discoveries] [syng-im.models.messages :refer [save-message update-message! message-by-id]] @@ -18,7 +17,7 @@ [syng-im.handlers.commands :refer [set-chat-command set-chat-command-content]] [syng-im.handlers.sign-up :as sign-up-service] - + [syng-im.handlers.discovery :as discovery] [syng-im.models.chats :refer [create-chat]] [syng-im.models.chat :refer [signal-chat-updated set-current-chat-id @@ -275,11 +274,7 @@ (log/debug action from group-id identities) (create-chat db group-id identities true group-name))) -;; -- Discovery -------------------------------------------------------------- -(register-handler :generate-discoveries - (fn [db _] - (discoveries/save-discoveries (discoveries/generate-discoveries 10)))) (comment diff --git a/src/syng_im/handlers/discovery.cljs b/src/syng_im/handlers/discovery.cljs new file mode 100644 index 0000000000..e405965e5a --- /dev/null +++ b/src/syng_im/handlers/discovery.cljs @@ -0,0 +1,24 @@ +(ns syng-im.handlers.discovery + (:require [syng-im.models.discoveries :refer [save-discoveries + discovery-list + signal-discovery-updated + discovery-updated?]])) + + +;; -- Discovery -------------------------------------------------------------- + +(register-handler :discovery-response-received + (fn [db [_ from payload]] + (let [{:keys [status hashtags location]} payload] + (save-discoveries [{:name from + :status status + :whisper-id from + :photo "" + :location location + :tags hashtags + :last-updated (js/Date.)}]) + ))) + +(register-handler :updated-discoveries + (fn [db _] + (signal-discovery-updated db))) \ No newline at end of file diff --git a/src/syng_im/models/discoveries.cljs b/src/syng_im/models/discoveries.cljs index 7d99315e73..6278f5e2e2 100644 --- a/src/syng_im/models/discoveries.cljs +++ b/src/syng_im/models/discoveries.cljs @@ -1,7 +1,7 @@ (ns syng-im.models.discoveries (:require [cljs.core.async :as async :refer [chan put! !]] [re-frame.core :refer [subscribe dispatch dispatch-sync]] - [syng-im.utils.utils :refer [log toast]] + [syng-im.utils.debug :refer [log]] [syng-im.persistence.realm :as realm] [syng-im.persistence.realm :as r] [syng-im.resources :as res] @@ -10,24 +10,22 @@ ;; TODO see https://github.com/rt2zz/react-native-contacts/issues/45 (def fake-discoveries? true) - - (defn signal-discovery-updated [db] - (update-in db db/updated-discovery-signal-path (fn [current] + (update-in db db/updated-discoveries-signal-path (fn [current] (if current (inc current) 0)))) (defn discovery-updated? [db] - (get-in db db/updated-discovery-signal-path)) + (get-in db db/updated-discoveries-signal-path)) -(defn- generate-discovery [n] - {:discovery-id n - :name (str "Contact " n) - :status (apply str (repeat (+ n 3) "Contact Status ")) - :whisper-id (str "id-" n) - :photo "" - :tags ["tag1" "tag2"] +(defn generate-discovery [n] + {:name (str "Contact " n) + :status (apply str (repeat (+ n 3) "Contact Status ")) + :whisper-id (str "id-" n) + :location "" + :photo "" + :tags ["tag1" "tag2"] :last-updated (js/Date. "10/01/2015") }) @@ -80,7 +78,7 @@ (:tags (-> (r/get-by-field :discoveries :whisper-id whisper-id) (r/single-cljs)))) -(defn- create-discovery [{:keys [name status whisper-id photo tags last-updated]}] +(defn- create-discovery [{:keys [name status whisper-id photo location tags last-updated]}] (do ;(add-tags tags) (realm/create :discoveries @@ -88,6 +86,7 @@ :status status :whisper-id whisper-id :photo photo + :location location :tags (mapv (fn [tag] {:name tag}) tags) :last-updated last-updated} true) @@ -96,7 +95,7 @@ -(defn- update-discovery [{:keys [name status whisper-id photo tags last-updated]}] +(defn- update-discovery [{:keys [name status whisper-id photo location tags last-updated]}] (let [old-tags (get-tags whisper-id)] (do ;;(remove-tags old-tags) @@ -106,6 +105,7 @@ :status status :whisper-id whisper-id :photo photo + :location location :tags (mapv (fn [tag] {:name tag}) tags) :last-updated last-updated} @@ -131,13 +131,18 @@ (defn discovery-list [] (-> (r/get-all :discoveries) - (r/sorted :discovery-id :desc))) + (r/sorted :last-updated :desc))) -(defn get-discovery-recent [limit] +(defn discoveries-by-tag [tag limit] + (let [_ (log (str "discoveries by tag: " tag))] + (-> (r/get-by-filter :discoveries (str "tags.name = '" tag "'")) + (r/sorted :last-updated :desc) + (r/page 0 limit)))) + +(defn get-discovery-recent [discoveries limit] (if fake-discoveries? (take limit fake-discoveries) - (-> (r/get-all :discoveries) - (r/sorted :last-updated :desc) + (-> (r/sorted discoveries :last-updated :desc) (r/page 0 limit))) ) @@ -163,15 +168,6 @@ discoveries) ) -(defn get-discovery-popular [tag-limit] - (if fake-discoveries? - (group-by-tag fake-discoveries tag-limit) - (-> (r/get-all :discoveries) - (r/sorted :last-updated :desc) - (.slice 0) - (group-by-tag tag-limit)) - ) - ) (comment (group-by-tag [{:tags ["a" "b" "c"] diff --git a/src/syng_im/persistence/realm.cljs b/src/syng_im/persistence/realm.cljs index 3007a23a42..6db98318e9 100644 --- a/src/syng_im/persistence/realm.cljs +++ b/src/syng_im/persistence/realm.cljs @@ -1,6 +1,6 @@ (ns syng-im.persistence.realm (:require [cljs.reader :refer [read-string]] - [syng-im.utils.logging :as log] + [syng-im.utils.debug :refer [log]] [syng-im.utils.types :refer [to-string]]) (:refer-clojure :exclude [exists?])) @@ -57,6 +57,7 @@ :status "string" :whisper-id "string" :photo "string" + :location "string" :tags {:type "list" :objectType "tag"} :last-updated "date"}} @@ -96,6 +97,11 @@ value))] query)) +(defn get-by-filter [schema-name filter] + (let [_ (log filter)] + (-> (.objects realm (name schema-name)) + (.filtered filter)))) + (defn get-by-field [schema-name field value] (let [q (to-query schema-name :eq field value)] (-> (.objects realm (name schema-name)) diff --git a/src/syng_im/protocol/protocol_handler.cljs b/src/syng_im/protocol/protocol_handler.cljs index 9b1ab11206..ac1eae6668 100644 --- a/src/syng_im/protocol/protocol_handler.cljs +++ b/src/syng_im/protocol/protocol_handler.cljs @@ -40,6 +40,8 @@ ; (add-to-chat "group-chat" ":" (str (shorten from) " removed you from group chat"))) ;:participant-left-group (let [{:keys [group-id from]} event] ; (add-to-chat "group-chat" ":" (str (shorten from) " left group chat"))) + :discover-response (let [{:keys [from payload]} event] + (dispatch [:discovery-response-received from payload])) ;(add-to-chat "chat" ":" (str "Don't know how to handle " event-type)) (log/info "Don't know how to handle" event-type) ))}) diff --git a/src/syng_im/subs.cljs b/src/syng_im/subs.cljs index 6f0bb82ebb..7e0f176880 100644 --- a/src/syng_im/subs.cljs +++ b/src/syng_im/subs.cljs @@ -2,12 +2,14 @@ (:require-macros [reagent.ratom :refer [reaction]]) (:require [re-frame.core :refer [register-sub]] [syng-im.db :as db] + [syng-im.subscriptions.discovery :as discovery] [syng-im.models.chat :refer [current-chat-id chat-updated?]] [syng-im.models.chats :refer [chats-list chats-updated? chat-by-id]] [syng-im.models.discoveries :refer [discovery-list + signal-discovery-updated discovery-updated?]] [syng-im.models.messages :refer [get-messages]] [syng-im.models.contacts :refer [contacts-list]] @@ -65,15 +67,7 @@ (chat-by-id chat-id)) (reaction))))) -;; -- Discoveries list -------------------------------------------------------------- -(register-sub :get-discoveries - (fn [db _] - (let [discovery-updated (-> (discovery-updated? @db) - (reaction))] - (reaction - (let [_ @discovery-updated] - (discovery-list)))))) ;; -- User data -------------------------------------------------------------- diff --git a/src/syng_im/subscribers/discovery.cljs b/src/syng_im/subscribers/discovery.cljs new file mode 100644 index 0000000000..d0dd2751d9 --- /dev/null +++ b/src/syng_im/subscribers/discovery.cljs @@ -0,0 +1,38 @@ +(ns syng-im.subscriptions.discovery + (:require-macros [reagent.ratom :refer [reaction]]) + (:require [re-frame.core :refer [register-sub]] + [syng-im.db :as db] + [syng-im.utils.debug :refer [log]] + [syng-im.models.discoveries :refer [discovery-list + get-tag-popular + discoveries-by-tag + signal-discovery-updated + discovery-updated?]])) + + + +(register-sub :get-discoveries + (fn [db _] + (let [discovery-updated (-> (discovery-updated? @db) + (reaction))] + (reaction + (let [_ @discovery-updated] + (discovery-list)))))) + +(register-sub :get-discoveries-by-tag + (fn [db [_ tag limit]] + (let [discovery-updated (-> (discovery-updated? @db) + (reaction)) + _ (log (str "getting discoveries for: " tag))] + (reaction + (let [_ @discovery-updated] + (discoveries-by-tag tag limit)))))) + +(register-sub :get-popular-tags + (fn [db [_ limit]] + (let [discovery-updated (-> (discovery-updated? @db) + (reaction)) + _ (log (str "getting tags limited: " limit))] + (reaction + (let [_ @discovery-updated] + (get-tag-popular limit)))))) \ No newline at end of file diff --git a/src/syng_im/utils/debug.cljs b/src/syng_im/utils/debug.cljs new file mode 100644 index 0000000000..aa5f7202ed --- /dev/null +++ b/src/syng_im/utils/debug.cljs @@ -0,0 +1,3 @@ +(ns syng-im.utils.debug) + +(def log (.-log js/console)) \ No newline at end of file From 78cd61041b9333645bf76d2c2a77955894a73e9a Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Sun, 17 Apr 2016 19:44:59 +0300 Subject: [PATCH 06/23] added missing require --- src/syng_im/handlers/discovery.cljs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/syng_im/handlers/discovery.cljs b/src/syng_im/handlers/discovery.cljs index e405965e5a..8820321a96 100644 --- a/src/syng_im/handlers/discovery.cljs +++ b/src/syng_im/handlers/discovery.cljs @@ -1,5 +1,6 @@ (ns syng-im.handlers.discovery - (:require [syng-im.models.discoveries :refer [save-discoveries + (:require [re-frame.core :refer [register-handler after dispatch]] + [syng-im.models.discoveries :refer [save-discoveries discovery-list signal-discovery-updated discovery-updated?]])) From f32fb04c1a1a05ac95ffae2b49df0ed172c918ef Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Tue, 19 Apr 2016 15:30:07 +0300 Subject: [PATCH 07/23] added geolocation permission --- android/app/src/main/AndroidManifest.xml | 1 + env/dev/env/android/main.cljs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index c56b2f64b8..47a4b13530 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -4,6 +4,7 @@ + Date: Fri, 22 Apr 2016 18:32:42 +0300 Subject: [PATCH 08/23] 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 From 71f686520435121ab0b1462f26862aa36671cff8 Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Fri, 22 Apr 2016 19:04:29 +0300 Subject: [PATCH 09/23] fix android-geth dependency --- android/app/build.gradle | 2 +- android/build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 9f152c2e9b..272a943769 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -128,7 +128,7 @@ dependencies { compile project(':react-native-contacts') compile project(':react-native-i18n') // compile(name:'geth', ext:'aar') - compile(group: 'syng-im', name: 'android-geth', version: '1.4.0-201603131817-92d65cf', ext: 'aar') + compile(group: 'status-im', name: 'android-geth', version: '1.4.0-201604110816-a97a114', ext: 'aar') compile fileTree(dir: "node_modules/realm/android/libs", include: ["*.jar"]) } diff --git a/android/build.gradle b/android/build.gradle index f05bf1a9b7..038456b6b5 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -25,7 +25,7 @@ allprojects { dirs 'libs' } maven { - url "http://85.90.244.96:8081/artifactory/libs-release-local" + url "http://185.90.37.89:8081/artifactory/libs-release-local" } } } From 0c88c0556ed207e2a636b6e3de0f58e38ed6b74a Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Sun, 24 Apr 2016 15:22:24 +0300 Subject: [PATCH 10/23] implemented carousel component --- .re-natal | 1 - package.json | 1 - src/syng_im/components/carousel.cljs | 143 +++++++++++++++++- .../components/discovery/discovery.cljs | 2 +- .../discovery/discovery_popular.cljs | 27 ++-- .../discovery/discovery_popular_list.cljs | 4 +- src/syng_im/components/react.cljs | 1 + 7 files changed, 154 insertions(+), 25 deletions(-) diff --git a/.re-natal b/.re-natal index 8a8e33774a..282fd17ebb 100644 --- a/.re-natal +++ b/.re-natal @@ -14,7 +14,6 @@ "react-native-vector-icons/Ionicons", "react-native-circle-checkbox", "react-native-randombytes", - "react-native-carousel-control" ], "imageDirs": [ "images" diff --git a/package.json b/package.json index bb1a49ac6a..f069c032a4 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,6 @@ "awesome-phonenumber": "^1.0.12", "react-native": "^0.22.0", "react-native-action-button": "^1.1.3", - "react-native-carousel-control": "^1.0.1", "react-native-circle-checkbox": "^0.1.3", "react-native-contacts": "^0.2.1", "react-native-i18n": "0.0.8", diff --git a/src/syng_im/components/carousel.cljs b/src/syng_im/components/carousel.cljs index 5a6eb07019..127c06048c 100644 --- a/src/syng_im/components/carousel.cljs +++ b/src/syng_im/components/carousel.cljs @@ -1,15 +1,146 @@ -(ns syng-im.components.carousel) - -(set! js/Carousel (.-default (js/require "react-native-carousel-control"))) +(ns syng-im.components.carousel + (:require [syng-im.components.react :refer [android? + view + scroll-view + touchable-without-feedback + text]] + [syng-im.utils.debug :refer [log]])) -(defn carousel [opts & children] - (apply js/React.createElement js/Carousel (clj->js opts) children)) +(defn page-width [] + (.-width (.get (.. js/React -Dimensions) "window"))) + +(def defaults {:gap 10 + :sneak 10 + :pageWidth (- (page-width) 50)}) +(defn get-gap [data] + (get data :gap (:gap defaults))) + +(defn get-sneak [data] + (get data :sneak (:sneak defaults))) + +(defn get-page-width [data] + (get data :pageWidth (:pageWidth defaults))) + + +(defn calculate-gap [component props] + (let [prop-page-width (:pageWidth props) + sneak (get-sneak props) + _ (log "calculate-gap") + _ (log component) + _ (log props) + _ (log prop-page-width) + _ (log sneak)] + (if (> prop-page-width (page-width)) + (println "Invalid pageWidth")) + (reagent.core/set-state component {:gap (/ (- (- (page-width) (* 2 sneak)) prop-page-width) 2)}) + )) + +(defn scroll-to [component x y] + (.scrollTo (.-scrollView component) (clj->js {:y y + :x x}))) + +(defn on-scroll-end [event component] + (let [_ (log "on-scroll-end") + _ (log event) + _ (log component) + props (reagent.core/props component) + _ (log props) + state (reagent.core/state component) + _ (log state) + prop-page-width (get-page-width props) + _ (log (str "prop-page-width: " prop-page-width)) + sneak (get-sneak props) + _ (log (str "sneak: " sneak)) + gap (get-gap state) + _ (log (str "gap: " gap)) + page-offset (+ prop-page-width gap) + _ (log (str "page-offset: " page-offset)) + current-position (+ (.-x (.-contentOffset (.-nativeEvent event))) (/ (page-width) 2)) + _ (log (str "current-position: " current-position)) + current-page (quot current-position page-offset) + _ (log (str "current-page: " current-page)) + ] + (scroll-to component (* current-page page-offset) 0) + (reagent.core/set-state component {:activePage current-page}) + (if (:onPageChange props) + ((:onPageChange props) current-page)))) + +(defn go-to-page [component position] + (let [_ (log "go-to-page") + props (reagent.core/props component) + state (reagent.core/state component) + props-page-width (get-page-width props) + _ (log (str "props page width: " props-page-width)) + gap (get-gap state) + _ (log (str "gap: " gap)) + page-position (* position (+ props-page-width gap)) + _ (log (str "page position: " page-position))] + (scroll-to component page-position 0))) + +(defn carousel [data children] + (let [_ (log "Creating carousel component: ") + _ (log data) + _ (log children)] + (reagent.core/create-class {:component-did-mount (fn [this] + (let [_ (log this)] + (if (> (.-initialPage (.-props this)) 0) + (go-to-page this (.-initialPage (.-props this)))))) + + :component-will-mount (fn [this] + (let [_ (log "component-will-mount") + _ (log this)] + (calculate-gap this (reagent.core/props this)))) + :component-will-receive-props (fn [this new-argv] + (let [_ (log "component-will-receive-props-mount") + _ (log this) + _ (log new-argv)] + (calculate-gap this new-argv))) + :display-name "carousel1" + :reagent-render (fn [data children] + (let [_ (log "reagent-render") + _ (log data) + _ (log children) + component (reagent.core/current-component) + props-page-width (get-page-width data) + sneak (get-sneak data) + gap (get-gap data) + page-style (get data :pageStyle {}) + pages (map-indexed (fn [index child] + (let [page-index index + _ (log (str "page index" index "-" page-index)) + _ (log child)] + [touchable-without-feedback {:key index + :onPress (fn [a b c] + (let [_ (log "touchable pressed") + _ (log (.-target a)) + _ (log component) + _ (log page-index)] + (go-to-page component page-index))) + } + [view {:style [{:width props-page-width + :justifyContent "center" + :marginLeft (/ gap 2) + :marginRight (/ gap 2)} + page-style]} + child]])) children)] + + [view {:style {:flex 1}} + [scroll-view {:contentContainerStyle {:paddingLeft (+ sneak (/ gap 2)) + :paddingRight (+ sneak (/ gap 2))} + :automaticallyAdjustContentInsets false + :bounces false + :decelerationRate 0.9 + :horizontal true + :onScrollEndDrag (fn [event] (on-scroll-end event component)) + :showsHorizontalScrollIndicator false + :ref (fn [c] (set! (.-scrollView component) c)) + } + pages]]))}))) (comment - ) \ No newline at end of file diff --git a/src/syng_im/components/discovery/discovery.cljs b/src/syng_im/components/discovery/discovery.cljs index bee5873a69..f3e464b840 100644 --- a/src/syng_im/components/discovery/discovery.cljs +++ b/src/syng_im/components/discovery/discovery.cljs @@ -30,7 +30,7 @@ :style {:backgroundColor "#eef2f5" :justifyContent "center" :height 56 - :elevation 2} + :elevation 0} :onIconClicked (fn [] (realm/write (fn [] (let [number (rand-int 30)] diff --git a/src/syng_im/components/discovery/discovery_popular.cljs b/src/syng_im/components/discovery/discovery_popular.cljs index b452cb9b18..418d60603c 100644 --- a/src/syng_im/components/discovery/discovery_popular.cljs +++ b/src/syng_im/components/discovery/discovery_popular.cljs @@ -14,20 +14,19 @@ (defn discovery-popular [] (let [popular-tags (subscribe [:get-popular-tags 3]) _ (log "Got popular tags: ") - _ (log @popular-tags) - popular-lists (mapv #(discovery-popular-list (.-name %)) @popular-tags)] - (if (> (count popular-lists) 0) - (apply carousel {:pageStyle {:borderRadius 1 - :shadowColor "black" - :shadowRadius 1 - :shadowOpacity 0.8 - :elevation 2 - :marginBottom 10} - :pageWidth (- (page-width) 60) - - } - popular-lists - ) + _ (log @popular-tags)] + (if (> (count @popular-tags) 0) + [carousel {:pageStyle {:borderRadius 1 + :shadowColor "black" + :shadowRadius 1 + :shadowOpacity 0.8 + :elevation 2 + :marginBottom 10} + :pageWidth (- (page-width) 60) + :sneak 20} + (for [tag @popular-tags] + (discovery-popular-list (.-name tag))) + ] [text "None"] ) ) diff --git a/src/syng_im/components/discovery/discovery_popular_list.cljs b/src/syng_im/components/discovery/discovery_popular_list.cljs index 0a1274eecc..fdb8199120 100644 --- a/src/syng_im/components/discovery/discovery_popular_list.cljs +++ b/src/syng_im/components/discovery/discovery_popular_list.cljs @@ -32,7 +32,7 @@ (let [discoveries (subscribe [:get-discoveries-by-tag tag 3]) _ (log (str "Got discoveries for tag (" tag "): ") @discoveries) _ (log @discoveries)] - (r/as-element [view {:style {:flex 1 + [view {:style {:flex 1 :backgroundColor "white" :paddingLeft 10 :paddingTop 10}} @@ -52,7 +52,7 @@ :renderRow render-row :renderSeparator render-separator :style {:backgroundColor "white"}}] - ]))) + ])) (comment list-view {:dataSource elements diff --git a/src/syng_im/components/react.cljs b/src/syng_im/components/react.cljs index 020f657e7a..ff84d907d8 100644 --- a/src/syng_im/components/react.cljs +++ b/src/syng_im/components/react.cljs @@ -13,6 +13,7 @@ (def list-view (r/adapt-react-class (.-ListView js/React))) (def text-input (r/adapt-react-class (.-TextInput js/React))) (def scroll-view (r/adapt-react-class (.-ScrollView js/React))) +(def touchable-without-feedback (r/adapt-react-class (.-TouchableWithoutFeedback js/React))) (def platform (.. js/React -Platform -OS)) From ca656906c17d8a7f56d8354b6f57255664dedee0 Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Thu, 28 Apr 2016 01:03:24 +0300 Subject: [PATCH 11/23] linked discovery search to status change for testing and updated react-native --- .re-natal | 8 ++++++-- env/dev/env/android/main.cljs | 2 +- figwheel-bridge.js | 2 +- package.json | 3 ++- .../components/discovery/discovery.cljs | 17 +++++++++++------ src/syng_im/db.cljs | 1 + src/syng_im/handlers/discovery.cljs | 19 ++++++++++++++++--- src/syng_im/models/discoveries.cljs | 7 +++++-- 8 files changed, 43 insertions(+), 16 deletions(-) diff --git a/.re-natal b/.re-natal index 282fd17ebb..feeb62e3c6 100644 --- a/.re-natal +++ b/.re-natal @@ -13,10 +13,14 @@ "react-native-action-button", "react-native-vector-icons/Ionicons", "react-native-circle-checkbox", - "react-native-randombytes", + "react-native-randombytes" ], "imageDirs": [ "images" ], - "iosHost": "localhost" + "iosHost": "localhost", + "envRoots": { + "dev": "env/dev", + "prod": "env/prod" + } } \ No newline at end of file diff --git a/env/dev/env/android/main.cljs b/env/dev/env/android/main.cljs index 0da80188c4..f80f25c166 100644 --- a/env/dev/env/android/main.cljs +++ b/env/dev/env/android/main.cljs @@ -11,7 +11,7 @@ (figwheel/watch-and-reload :websocket-url "ws://10.0.3.2:3449/figwheel-ws" - :heads-up-display true + :heads-up-display false :jsload-callback #(swap! cnt inc)) (core/init) \ No newline at end of file diff --git a/figwheel-bridge.js b/figwheel-bridge.js index 6df4702339..137673ca19 100644 --- a/figwheel-bridge.js +++ b/figwheel-bridge.js @@ -168,7 +168,7 @@ function compileWarningsToYellowBox() { if (compileWarningRx.test(msg)) { console.warn(msg); } else { - log.call(window.console, msg); + log.apply(window.console, arguments); } }; } diff --git a/package.json b/package.json index f069c032a4..602cacea56 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ }, "dependencies": { "awesome-phonenumber": "^1.0.12", - "react-native": "^0.22.0", + "react": "^0.14.5", + "react-native": "^0.24.1", "react-native-action-button": "^1.1.3", "react-native-circle-checkbox": "^0.1.3", "react-native-contacts": "^0.2.1", diff --git a/src/syng_im/components/discovery/discovery.cljs b/src/syng_im/components/discovery/discovery.cljs index f3e464b840..ab423de565 100644 --- a/src/syng_im/components/discovery/discovery.cljs +++ b/src/syng_im/components/discovery/discovery.cljs @@ -17,6 +17,12 @@ (def search-input (atom {:search "x"})) +(defn get-hashtags [status] + (let [hashtags (map #(subs % 1) (re-seq #"#[^ !?,;:.]+" status))] + (if hashtags + hashtags + []))) + (defn discovery [{:keys [navigator]}] (let [showSearch (r/atom false)] (fn [] @@ -50,7 +56,7 @@ (reset! showSearch true)))} (if @showSearch [text-input {:underlineColorAndroid "transparent" - :value (:search @search-input) + ;:value (:search @search-input) :style {:flex 1 :marginLeft 18 :lineHeight 42 @@ -61,12 +67,11 @@ :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)) - )) + (log (str new-text "-" old-text)))) :onSubmitEditing (fn [e] - (log (aget e "nativeEvent" "text")))}] + (let [search (aget e "nativeEvent" "text") + hashtags (get-hashtags search)] + (dispatch [:broadcast-status search hashtags])))}] [text "Discover"])] [scroll-view {:style {}} diff --git a/src/syng_im/db.cljs b/src/syng_im/db.cljs index 741402a950..6d1eba9c58 100644 --- a/src/syng_im/db.cljs +++ b/src/syng_im/db.cljs @@ -12,6 +12,7 @@ :command nil} :chats {} :chats-updated-signal 0 + :name "My Name" :new-group #{}}) diff --git a/src/syng_im/handlers/discovery.cljs b/src/syng_im/handlers/discovery.cljs index 8820321a96..ea70f55980 100644 --- a/src/syng_im/handlers/discovery.cljs +++ b/src/syng_im/handlers/discovery.cljs @@ -1,5 +1,7 @@ (ns syng-im.handlers.discovery (:require [re-frame.core :refer [register-handler after dispatch]] + [syng-im.utils.debug :refer [log]] + [syng-im.protocol.api :as api] [syng-im.models.discoveries :refer [save-discoveries discovery-list signal-discovery-updated @@ -10,7 +12,8 @@ (register-handler :discovery-response-received (fn [db [_ from payload]] - (let [{:keys [status hashtags location]} payload] + (let [{:keys [status hashtags location]} payload + location (if location location "")] (save-discoveries [{:name from :status status :whisper-id from @@ -18,8 +21,18 @@ :location location :tags hashtags :last-updated (js/Date.)}]) - ))) + (signal-discovery-updated db) + db))) (register-handler :updated-discoveries (fn [db _] - (signal-discovery-updated db))) \ No newline at end of file + (signal-discovery-updated db) + db)) + +(register-handler :broadcast-status + (fn [db [action status hashtags]] + (let [_ (log "Status: " status) + _ (log "Hashtags: " hashtags) + name (:name db)] + (api/broadcast-discover-status name status hashtags) + db))) \ No newline at end of file diff --git a/src/syng_im/models/discoveries.cljs b/src/syng_im/models/discoveries.cljs index 6278f5e2e2..57bfff0126 100644 --- a/src/syng_im/models/discoveries.cljs +++ b/src/syng_im/models/discoveries.cljs @@ -35,7 +35,8 @@ (def fake-discoveries (generate-discoveries 20)) (defn- get-discoveries [] - ( let [list (realm/get-list :discoveries)] + (let [list (realm/get-list :discoveries) + _ (log list)] (if (> (.-length list) 0) (.slice list 0) []))) (defn load-syng-discoveries [db] @@ -118,7 +119,9 @@ (defn- add-discoveries [discoveries] (realm/write (fn [] - (let [db-discoveries (get-discoveries)] + (let [db-discoveries (.slice (discovery-list) 0) + _ (log discoveries) + _ (log (.slice db-discoveries 0))] (dorun (map (fn [discovery] (if (not (discovery-exist? db-discoveries discovery)) (create-discovery discovery) From 71aef771d8f35965fe21303d9b48f53de8e51e58 Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Thu, 28 Apr 2016 03:33:58 +0300 Subject: [PATCH 12/23] code cleaning --- src/syng_im/components/carousel.cljs | 2 +- .../components/discovery/discovery.cljs | 23 ++- src/syng_im/handlers/discovery.cljs | 26 ++- src/syng_im/models/discoveries.cljs | 160 ++++++------------ src/syng_im/persistence/realm.cljs | 2 +- src/syng_im/subs.cljs | 3 - src/syng_im/subscribers/discovery.cljs | 15 +- 7 files changed, 79 insertions(+), 152 deletions(-) diff --git a/src/syng_im/components/carousel.cljs b/src/syng_im/components/carousel.cljs index 127c06048c..d20f514a37 100644 --- a/src/syng_im/components/carousel.cljs +++ b/src/syng_im/components/carousel.cljs @@ -12,7 +12,7 @@ (def defaults {:gap 10 :sneak 10 - :pageWidth (- (page-width) 50)}) + :pageWidth (- (page-width) 40)}) (defn get-gap [data] diff --git a/src/syng_im/components/discovery/discovery.cljs b/src/syng_im/components/discovery/discovery.cljs index ab423de565..f455bfc0a6 100644 --- a/src/syng_im/components/discovery/discovery.cljs +++ b/src/syng_im/components/discovery/discovery.cljs @@ -3,6 +3,7 @@ (:require [syng-im.utils.debug :refer [log]] [re-frame.core :refer [dispatch]] + [syng-im.models.discoveries :refer [save-discoveries]] [syng-im.components.react :refer [android? view scroll-view @@ -38,17 +39,16 @@ :height 56 :elevation 0} :onIconClicked (fn [] - (realm/write (fn [] - (let [number (rand-int 30)] - (realm/create :discoveries - {:name (str "c" number) - :status (str "Status " number) - :whisper-id (str number) - :photo "" - :location "" - :tags [{:name "tag1"} {:name "tag2"}] - :last-updated (new js/Date)} true) - (dispatch [:updated-discoveries]))))) + (let [number (rand-int 999)] + (do + (save-discoveries [{:name (str "Name " number) + :status (str "Status " number) + :whisper-id (str number) + :photo "" + :location "" + :tags ["tag1" "tag2" "tag3"] + :last-updated (new js/Date)}]) + (dispatch [:updated-discoveries])))) ;; temporary dispatch for testing :onActionSelected (fn [index] (if @showSearch @@ -100,5 +100,4 @@ (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/handlers/discovery.cljs b/src/syng_im/handlers/discovery.cljs index ea70f55980..f1d4661ff5 100644 --- a/src/syng_im/handlers/discovery.cljs +++ b/src/syng_im/handlers/discovery.cljs @@ -3,31 +3,27 @@ [syng-im.utils.debug :refer [log]] [syng-im.protocol.api :as api] [syng-im.models.discoveries :refer [save-discoveries - discovery-list - signal-discovery-updated - discovery-updated?]])) + signal-discoveries-updated]])) ;; -- Discovery -------------------------------------------------------------- (register-handler :discovery-response-received (fn [db [_ from payload]] - (let [{:keys [status hashtags location]} payload + (let [{:keys [name status hashtags location]} payload location (if location location "")] - (save-discoveries [{:name from - :status status - :whisper-id from - :photo "" - :location location - :tags hashtags - :last-updated (js/Date.)}]) - (signal-discovery-updated db) - db))) + (save-discoveries [{:name name + :status status + :whisper-id from + :photo "" + :location location + :tags hashtags + :last-updated (js/Date.)}]) + (signal-discoveries-updated db)))) (register-handler :updated-discoveries (fn [db _] - (signal-discovery-updated db) - db)) + (signal-discoveries-updated db))) (register-handler :broadcast-status (fn [db [action status hashtags]] diff --git a/src/syng_im/models/discoveries.cljs b/src/syng_im/models/discoveries.cljs index 57bfff0126..dad0be5f64 100644 --- a/src/syng_im/models/discoveries.cljs +++ b/src/syng_im/models/discoveries.cljs @@ -7,116 +7,89 @@ [syng-im.resources :as res] [syng-im.db :as db])) -;; TODO see https://github.com/rt2zz/react-native-contacts/issues/45 -(def fake-discoveries? true) - -(defn signal-discovery-updated [db] +(defn signal-discoveries-updated [db] (update-in db db/updated-discoveries-signal-path (fn [current] (if current (inc current) 0)))) -(defn discovery-updated? [db] +(defn discoveries-updated? [db] (get-in db db/updated-discoveries-signal-path)) -(defn generate-discovery [n] - {:name (str "Contact " n) - :status (apply str (repeat (+ n 3) "Contact Status ")) - :whisper-id (str "id-" n) - :location "" - :photo "" - :tags ["tag1" "tag2"] - :last-updated (js/Date. "10/01/2015") - }) - -(defn- generate-discoveries [n] - (map generate-discovery (range 1 (inc n)))) - -(def fake-discoveries (generate-discoveries 20)) - -(defn- get-discoveries [] - (let [list (realm/get-list :discoveries) - _ (log list)] - (if (> (.-length list) 0) (.slice list 0) []))) - -(defn load-syng-discoveries [db] - (let [discoveries (map (fn [discovery] - (merge discovery - {})) - (get-discoveries))] - (assoc db :discoveries discoveries))) - (defn get-tag [tag] + (let [_ (log (str "Getting tag: " tag))] (-> (r/get-by-field :tag :name tag) - (r/single-cljs))) + (r/single-cljs)))) -(defn remove-tag [tag] - (let [tag-object (get-tag tag)] +(defn decrease-tag-counter [tag] + (let [tag (:name tag) + tag-object (get-tag tag)] (if tag-object - (realm/create :tag - {:name tag - :count (dec (:count tag-object)) - })))) + (let [counter (dec (:count tag-object))] + (if (= counter 0) + (realm/delete tag-object) + (realm/create :tag {:name tag + :count counter} + true)))))) -(defn add-tag [tag] - (let [tag-object (get-tag tag) - counter (if tag-object (:count tag-object) 1)] - (realm/create :tag - {:name tag - :count (inc counter) - } - (if tag-object true false)))) +(defn increase-tag-counter [tag] + (let [tag (:name tag) + tag-object (get-tag tag)] + (if tag-object + (realm/create :tag {:name tag + :count (inc (:count tag-object))} + true)))) -(defn remove-tags [tags] +(defn decrease-tags-counter [tags] (doseq [tag tags] - (remove-tag tag))) + (decrease-tag-counter tag))) -(defn add-tags [tags] +(defn increase-tags-counter [tags] (doseq [tag tags] - (add-tag tag))) + (increase-tag-counter tag))) (defn get-tags [whisper-id] (:tags (-> (r/get-by-field :discoveries :whisper-id whisper-id) - (r/single-cljs)))) + (r/single-cljs)))) (defn- create-discovery [{:keys [name status whisper-id photo location tags last-updated]}] - (do - ;(add-tags tags) - (realm/create :discoveries - {:name name + (let [tags (mapv (fn [tag] {:name tag}) tags) + discovery {:name name :status status :whisper-id whisper-id :photo photo :location location - :tags (mapv (fn [tag] - {:name tag}) tags) - :last-updated last-updated} true) - ) - ) - - + :tags tags + :last-updated last-updated} + _ (log "Creating discovery") + _ (log discovery) + _ (log tags)] + (do + (realm/create :discoveries discovery true) + (increase-tags-counter tags)))) (defn- update-discovery [{:keys [name status whisper-id photo location tags last-updated]}] - (let [old-tags (get-tags whisper-id)] - (do - ;;(remove-tags old-tags) - ;;(add-tags tags) - (realm/create :discoveries - {:name name + (let [old-tags (get-tags whisper-id) + tags (mapv (fn [tag] {:name tag}) tags) + discovery {:name name :status status :whisper-id whisper-id :photo photo :location location - :tags (mapv (fn [tag] - {:name tag}) tags) - :last-updated last-updated} - true) - )) - ) + :tags tags + :last-updated last-updated}] + (do + (decrease-tags-counter old-tags) + (realm/create :discoveries discovery true) + (increase-tags-counter tags)))) (defn- discovery-exist? [discoveries discovery] (some #(= (:whisper-id discovery) (:whisper-id %)) discoveries)) +(defn discovery-list [] + (-> (r/get-all :discoveries) + (r/sorted :last-updated :desc))) + (defn- add-discoveries [discoveries] (realm/write (fn [] (let [db-discoveries (.slice (discovery-list) 0) @@ -132,51 +105,14 @@ (defn save-discoveries [discoveries] (add-discoveries discoveries)) -(defn discovery-list [] - (-> (r/get-all :discoveries) - (r/sorted :last-updated :desc))) - (defn discoveries-by-tag [tag limit] (let [_ (log (str "discoveries by tag: " tag))] (-> (r/get-by-filter :discoveries (str "tags.name = '" tag "'")) (r/sorted :last-updated :desc) (r/page 0 limit)))) -(defn get-discovery-recent [discoveries limit] - (if fake-discoveries? - (take limit fake-discoveries) - (-> (r/sorted discoveries :last-updated :desc) - (r/page 0 limit))) - ) - (defn get-tag-popular [limit] (-> (r/get-all :tag) (r/sorted :count :desc) (r/page 0 limit))) -(defn add-with-limit [data value limit] - (if (>= (count data) limit) - data - (conj data value)) - ) - -(defn group-by-tag [discoveries tag-limit] - (reduce (fn [result discovery] - (let [keys (:tags discovery)] - (reduce (fn [data key] - (assoc data (keyword key) (add-with-limit (get data (keyword key) []) discovery tag-limit))) - result - keys))) - {} - discoveries) - ) - - -(comment - (group-by-tag [{:tags ["a" "b" "c"] - :name "test1"} - {:tags ["a" "c"] - :name "test2"} - {:tags ["c"] - :name "test3"}]) - ) \ No newline at end of file diff --git a/src/syng_im/persistence/realm.cljs b/src/syng_im/persistence/realm.cljs index 6db98318e9..23dfec7c45 100644 --- a/src/syng_im/persistence/realm.cljs +++ b/src/syng_im/persistence/realm.cljs @@ -50,7 +50,7 @@ :properties {:name "string" :count {:type "int" :optional true - :default 1}}} + :default 0}}} {:name :discoveries :primaryKey :whisper-id :properties {:name "string" diff --git a/src/syng_im/subs.cljs b/src/syng_im/subs.cljs index 7e0f176880..b5611fc89a 100644 --- a/src/syng_im/subs.cljs +++ b/src/syng_im/subs.cljs @@ -8,9 +8,6 @@ [syng-im.models.chats :refer [chats-list chats-updated? chat-by-id]] - [syng-im.models.discoveries :refer [discovery-list - signal-discovery-updated - discovery-updated?]] [syng-im.models.messages :refer [get-messages]] [syng-im.models.contacts :refer [contacts-list]] [syng-im.handlers.suggestions :refer [get-suggestions]])) diff --git a/src/syng_im/subscribers/discovery.cljs b/src/syng_im/subscribers/discovery.cljs index d0dd2751d9..601e65b484 100644 --- a/src/syng_im/subscribers/discovery.cljs +++ b/src/syng_im/subscribers/discovery.cljs @@ -6,33 +6,32 @@ [syng-im.models.discoveries :refer [discovery-list get-tag-popular discoveries-by-tag - signal-discovery-updated - discovery-updated?]])) + discoveries-updated?]])) (register-sub :get-discoveries (fn [db _] - (let [discovery-updated (-> (discovery-updated? @db) + (let [discoveries-updated (-> (discoveries-updated? @db) (reaction))] (reaction - (let [_ @discovery-updated] + (let [_ @discoveries-updated] (discovery-list)))))) (register-sub :get-discoveries-by-tag (fn [db [_ tag limit]] - (let [discovery-updated (-> (discovery-updated? @db) + (let [discoveries-updated (-> (discoveries-updated? @db) (reaction)) _ (log (str "getting discoveries for: " tag))] (reaction - (let [_ @discovery-updated] + (let [_ @discoveries-updated] (discoveries-by-tag tag limit)))))) (register-sub :get-popular-tags (fn [db [_ limit]] - (let [discovery-updated (-> (discovery-updated? @db) + (let [discoveries-updated (-> (discoveries-updated? @db) (reaction)) _ (log (str "getting tags limited: " limit))] (reaction - (let [_ @discovery-updated] + (let [_ @discoveries-updated] (get-tag-popular limit)))))) \ No newline at end of file From 5aef032c599b73e31d1c7aa46f89f2b228a69477 Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Sat, 30 Apr 2016 22:48:30 +0300 Subject: [PATCH 13/23] cleaned logging and changed it to use utils.logging; splitted carousel to multiple functions --- src/syng_im/components/carousel.cljs | 178 ++++++++---------- .../discovery-popular-list-item.cljs | 9 +- .../discovery/discovery-recent.cljs | 10 +- .../components/discovery/discovery.cljs | 4 +- .../discovery/discovery_popular.cljs | 15 +- .../discovery/discovery_popular_list.cljs | 57 +++--- src/syng_im/handlers/discovery.cljs | 7 +- src/syng_im/models/discoveries.cljs | 28 ++- src/syng_im/persistence/realm.cljs | 4 +- src/syng_im/subscribers/discovery.cljs | 10 +- src/syng_im/utils/debug.cljs | 3 - 11 files changed, 142 insertions(+), 183 deletions(-) delete mode 100644 src/syng_im/utils/debug.cljs diff --git a/src/syng_im/components/carousel.cljs b/src/syng_im/components/carousel.cljs index f9ff306f0f..f032b4a1cc 100644 --- a/src/syng_im/components/carousel.cljs +++ b/src/syng_im/components/carousel.cljs @@ -4,7 +4,7 @@ scroll-view touchable-without-feedback text]] - [syng-im.utils.debug :refer [log]])) + [syng-im.utils.logging :as log])) (defn page-width [] @@ -24,21 +24,15 @@ (defn get-page-width [data] (get data :pageWidth (:pageWidth defaults))) - (defn calculate-gap [component props] (let [prop-page-width (get-page-width props) page-width (page-width) sneak (get-sneak props) - gap (quot (- (- page-width (* 2 sneak)) prop-page-width) 2) - _ (log "calculate-gap") - _ (log component) - _ (log props) - _ (log page-width) - _ (log prop-page-width) - _ (log sneak) - _ (log gap)] - (if (> prop-page-width page-width) - (println "Invalid pageWidth")) + gap (quot (- (- page-width (* 2 sneak)) prop-page-width) 2)] + (log/debug "calculate-gap: prop-page-width=" prop-page-width + "; page-width=" page-width"; sneak=" sneak "; gap=" gap) + (when (> prop-page-width page-width) + (log/warn "Invalid pageWidth")) (reagent.core/set-state component {:gap gap}) )) @@ -46,105 +40,99 @@ (.scrollTo (.-scrollView component) (clj->js {:y y :x x}))) +(defn get-current-position [event] + (+ (.-x (.-contentOffset (.-nativeEvent event))) (quot (page-width) 2))) + (defn on-scroll-end [event component] - (let [_ (log "on-scroll-end") - _ (log event) - _ (log component) - props (reagent.core/props component) - _ (log props) + (let [props (reagent.core/props component) state (reagent.core/state component) - _ (log state) prop-page-width (get-page-width props) - _ (log (str "prop-page-width: " prop-page-width)) sneak (get-sneak props) - _ (log (str "sneak: " sneak)) gap (get-gap state) - _ (log (str "gap: " gap)) page-offset (+ prop-page-width gap) - _ (log (str "page-offset: " page-offset)) - current-position (+ (.-x (.-contentOffset (.-nativeEvent event))) (quot (page-width) 2)) - _ (log (str "current-position: " current-position)) + current-position (get-current-position event) current-page (quot current-position page-offset) - _ (log (str "current-page: " current-page)) ] + (log/debug "on-scroll-end: prop-page-width=" prop-page-width + "; sneak=" sneak "; gap=" gap "; page-offset=" page-offset + "; current-position=" current-position + "; current-page=" current-page) (scroll-to component (* current-page page-offset) 0) (reagent.core/set-state component {:activePage current-page}) - (if (:onPageChange props) + (when (:onPageChange props) ((:onPageChange props) current-page)))) (defn go-to-page [component position] - (let [_ (log "go-to-page") - props (reagent.core/props component) + (let [props (reagent.core/props component) state (reagent.core/state component) props-page-width (get-page-width props) - _ (log (str "props page width: " props-page-width)) gap (get-gap state) - _ (log (str "gap: " gap)) - page-position (* position (+ props-page-width gap)) - _ (log (str "page position: " page-position))] + page-position (* position (+ props-page-width gap))] + (log/debug "go-to-page: props-page-width=" props-page-width "; gap=" gap + "; page-position=" page-position) (scroll-to component page-position 0))) +(defn component-will-mount [component new-args] + (let [props (reagent.core/props component)] + (log/debug "component-will-mount: component=" component "; new-args="new-args) + (calculate-gap component props))) + +(defn component-did-mount [component] + (let [props (reagent.core/props component) + initial-page (.-initialPage props)] + (log/debug "component-did-mount: initial-page="initial-page) + (when (pos? initial-page) + (go-to-page component initial-page)))) + +(defn component-will-receive-props [component new-argv] + (log/debug "component-will-receive-props: component=" component + "; new-argv=" new-argv) + (calculate-gap component new-argv)) + +(defn get-pages [component data children] + (let [props-page-width (get-page-width data) + page-style (get data :pageStyle {}) + gap (get-gap data) + margin (quot gap 2)] + (map-indexed (fn [index child] + (let [page-index index + touchable-data {:key index + :onPress (fn [event] + (go-to-page component page-index))}] + (log/debug "page " index " - " child) + [touchable-without-feedback touchable-data + [view {:style [{:width props-page-width + :justifyContent "center" + :marginLeft margin + :marginRight margin} + page-style]} + child]])) children))) + +(defn reagent-render [data children] + (let [component (reagent.core/current-component) + sneak (get-sneak data) + gap (get-gap data) + pages (get-pages component data children)] + (log/debug "reagent-render: ") + [view {:style {:flex 1}} + [scroll-view {:contentContainerStyle {:paddingLeft (+ sneak (quot gap 2)) + :paddingRight (+ sneak (quot gap 2))} + :automaticallyAdjustContentInsets false + :bounces false + :decelerationRate 0.9 + :horizontal true + :onScrollEndDrag (fn [event] (on-scroll-end event component)) + :showsHorizontalScrollIndicator false + :ref (fn [c] (set! (.-scrollView component) c)) + } + pages]] + )) + (defn carousel [data children] - (let [_ (log "Creating carousel component: ") - _ (log data) - _ (log children)] - (reagent.core/create-class {:component-did-mount (fn [this] - (let [_ (log this)] - (if (> (.-initialPage (.-props this)) 0) - (go-to-page this (.-initialPage (.-props this)))))) - - :component-will-mount (fn [this] - (let [_ (log "component-will-mount") - _ (log this)] - (calculate-gap this (reagent.core/props this)))) - :component-will-receive-props (fn [this new-argv] - (let [_ (log "component-will-receive-props-mount") - _ (log this) - _ (log new-argv)] - (calculate-gap this new-argv))) - :display-name "carousel1" - :reagent-render (fn [data children] - (let [_ (log "reagent-render") - _ (log data) - _ (log children) - component (reagent.core/current-component) - props-page-width (get-page-width data) - sneak (get-sneak data) - gap (get-gap data) - page-style (get data :pageStyle {}) - pages (map-indexed (fn [index child] - (let [page-index index - _ (log (str "page index" index "-" page-index)) - _ (log child)] - [touchable-without-feedback {:key index - :onPress (fn [a b c] - (let [_ (log "touchable pressed") - _ (log (.-target a)) - _ (log component) - _ (log page-index)] - (go-to-page component page-index))) - } - [view {:style [{:width props-page-width - :justifyContent "center" - :marginLeft (quot gap 2) - :marginRight (quot gap 2)} - page-style]} - child]])) children)] - - [view {:style {:flex 1}} - [scroll-view {:contentContainerStyle {:paddingLeft (+ sneak (quot gap 2)) - :paddingRight (+ sneak (quot gap 2))} - :automaticallyAdjustContentInsets false - :bounces false - :decelerationRate 0.9 - :horizontal true - :onScrollEndDrag (fn [event] (on-scroll-end event component)) - :showsHorizontalScrollIndicator false - :ref (fn [c] (set! (.-scrollView component) c)) - } - pages]]))}))) - -(comment - - - ) \ No newline at end of file + (let [component-data {:component-did-mount component-did-mount + :component-will-mount component-will-mount + :component-will-receive-props component-will-receive-props + :display-name "carousel" + :reagent-render reagent-render}] + (log/debug "Creating carousel component: " data children) + (reagent.core/create-class component-data))) 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 de3dcd457b..fd0c55a7b6 100644 --- a/src/syng_im/components/discovery/discovery-popular-list-item.cljs +++ b/src/syng_im/components/discovery/discovery-popular-list-item.cljs @@ -1,6 +1,6 @@ (ns syng-im.components.discovery.discovery-popular-list-item (:require - [syng-im.utils.debug :refer [log]] + [syng-im.utils.logging :as log] [syng-im.components.react :refer [android? view text @@ -10,8 +10,8 @@ ) (defn discovery-popular-list-item [discovery] - (let [_ (log discovery)] - (r/as-element [view {:style {:flexDirection "row" + (log/debug discovery) + (r/as-element [view {:style {:flexDirection "row" :paddingTop 10 :paddingBottom 10}} [view {:style {:flex 0.8 @@ -34,5 +34,4 @@ :height 30} :source res/user-no-photo}] ] - ]) - )) \ No newline at end of file + ])) \ No newline at end of file diff --git a/src/syng_im/components/discovery/discovery-recent.cljs b/src/syng_im/components/discovery/discovery-recent.cljs index ef4c93dfb9..a7b1fb0566 100644 --- a/src/syng_im/components/discovery/discovery-recent.cljs +++ b/src/syng_im/components/discovery/discovery-recent.cljs @@ -20,7 +20,7 @@ (defn render-separator [sectionID, rowID, adjacentRowHighlighted] (let [elem (r/as-element [view {:style {:borderBottomWidth 1 - :borderBottomColor "#eff2f3"} + :borderBottomColor "#eff2f3"} :key rowID}])] elem)) @@ -28,8 +28,8 @@ (let [discoveries (subscribe [:get-discoveries]) datasource (to-realm-datasource @discoveries)] [list-view {:dataSource datasource - :renderRow render-row - :renderSeparator render-separator - :style {:backgroundColor "white" - :paddingLeft 15}}] + :renderRow render-row + :renderSeparator render-separator + :style {:backgroundColor "white" + :paddingLeft 15}}] )) \ No newline at end of file diff --git a/src/syng_im/components/discovery/discovery.cljs b/src/syng_im/components/discovery/discovery.cljs index f455bfc0a6..c4ec3e989d 100644 --- a/src/syng_im/components/discovery/discovery.cljs +++ b/src/syng_im/components/discovery/discovery.cljs @@ -1,7 +1,7 @@ (ns syng-im.components.discovery.discovery (:require - [syng-im.utils.debug :refer [log]] + [syng-im.utils.logging :as log] [re-frame.core :refer [dispatch]] [syng-im.models.discoveries :refer [save-discoveries]] [syng-im.components.react :refer [android? @@ -67,7 +67,7 @@ :placeholder "Type your search tags here" :onChangeText (fn [new-text] (let [old-text (:search @search-input)] - (log (str new-text "-" old-text)))) + (log/debug (str new-text "-" old-text)))) :onSubmitEditing (fn [e] (let [search (aget e "nativeEvent" "text") hashtags (get-hashtags search)] diff --git a/src/syng_im/components/discovery/discovery_popular.cljs b/src/syng_im/components/discovery/discovery_popular.cljs index 418d60603c..1dae49a7f1 100644 --- a/src/syng_im/components/discovery/discovery_popular.cljs +++ b/src/syng_im/components/discovery/discovery_popular.cljs @@ -1,7 +1,7 @@ (ns syng-im.components.discovery.discovery-popular (:require [re-frame.core :refer [subscribe]] - [syng-im.utils.debug :refer [log]] + [syng-im.utils.logging :as log] [syng-im.components.react :refer [android? text]] [syng-im.components.carousel :refer [carousel]] @@ -12,9 +12,8 @@ (.-width (.get (.. js/React -Dimensions) "window"))) (defn discovery-popular [] - (let [popular-tags (subscribe [:get-popular-tags 3]) - _ (log "Got popular tags: ") - _ (log @popular-tags)] + (let [popular-tags (subscribe [:get-popular-tags 3])] + (log/debug "Got popular tags: " @popular-tags) (if (> (count @popular-tags) 0) [carousel {:pageStyle {:borderRadius 1 :shadowColor "black" @@ -25,14 +24,8 @@ :pageWidth (- (page-width) 60) :sneak 20} (for [tag @popular-tags] - (discovery-popular-list (.-name tag))) - ] + (discovery-popular-list (.-name tag)))] [text "None"] ) ) - ) - -(comment - (set! React (js/require "react-native")) - (.get (.Dimensions React) "window") ) \ 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 fdb8199120..5938e3e9af 100644 --- a/src/syng_im/components/discovery/discovery_popular_list.cljs +++ b/src/syng_im/components/discovery/discovery_popular_list.cljs @@ -1,10 +1,7 @@ (ns syng-im.components.discovery.discovery-popular-list - (:require-macros - [natal-shell.data-source :refer [data-source clone-with-rows]] - ) (:require [re-frame.core :refer [subscribe dispatch dispatch-sync]] - [syng-im.utils.debug :refer [log]] + [syng-im.utils.logging :as log] [syng-im.components.react :refer [android? view list-view @@ -29,33 +26,27 @@ elem)) (defn discovery-popular-list [tag] - (let [discoveries (subscribe [:get-discoveries-by-tag tag 3]) - _ (log (str "Got discoveries for tag (" tag "): ") @discoveries) - _ (log @discoveries)] + (let [discoveries (subscribe [:get-discoveries-by-tag tag 3])] + (log/debug "Got discoveries for tag (" tag "): " @discoveries) [view {:style {:flex 1 - :backgroundColor "white" - :paddingLeft 10 - :paddingTop 10}} - [view {:style {:flexDirection "row" - :backgroundColor "white" - :padding 0}} - [view {:style {:flexDirection "column" - :backgroundColor "#e9f7fe" - :borderRadius 5 - :padding 0}} - [text {:style {:color "#6092df" - :paddingRight 5 - :paddingBottom 2 - :alignItems "center" - :justifyContent "center"}} (str " #" (name tag))]]] - [list-view {:dataSource (to-realm-datasource @discoveries) - :renderRow render-row - :renderSeparator render-separator - :style {:backgroundColor "white"}}] - ])) - -(comment - list-view {:dataSource elements - :renderRow (partial render-row list-element) - :style {:backgroundColor "white"}} - ) \ No newline at end of file + :backgroundColor "white" + :paddingLeft 10 + :paddingTop 10}} + [view {:style {:flexDirection "row" + :backgroundColor "white" + :padding 0}} + [view {:style {:flexDirection "column" + :backgroundColor "#e9f7fe" + :borderRadius 5 + :padding 0}} + [text {:style {:color "#6092df" + :paddingRight 5 + :paddingBottom 2 + :alignItems "center" + :justifyContent "center"}} + (str " #" (name tag))]]] + [list-view {:dataSource (to-realm-datasource @discoveries) + :renderRow render-row + :renderSeparator render-separator + :style {:backgroundColor "white"}}] + ])) diff --git a/src/syng_im/handlers/discovery.cljs b/src/syng_im/handlers/discovery.cljs index f1d4661ff5..b1d81d472a 100644 --- a/src/syng_im/handlers/discovery.cljs +++ b/src/syng_im/handlers/discovery.cljs @@ -1,6 +1,6 @@ (ns syng-im.handlers.discovery (:require [re-frame.core :refer [register-handler after dispatch]] - [syng-im.utils.debug :refer [log]] + [syng-im.utils.logging :as log] [syng-im.protocol.api :as api] [syng-im.models.discoveries :refer [save-discoveries signal-discoveries-updated]])) @@ -27,8 +27,7 @@ (register-handler :broadcast-status (fn [db [action status hashtags]] - (let [_ (log "Status: " status) - _ (log "Hashtags: " hashtags) - name (:name db)] + (let [name (:name db)] + (log/debug "Status: " status ", Hashtags: " hashtags) (api/broadcast-discover-status name status hashtags) db))) \ No newline at end of file diff --git a/src/syng_im/models/discoveries.cljs b/src/syng_im/models/discoveries.cljs index dad0be5f64..91cc9d9030 100644 --- a/src/syng_im/models/discoveries.cljs +++ b/src/syng_im/models/discoveries.cljs @@ -1,7 +1,7 @@ (ns syng-im.models.discoveries (:require [cljs.core.async :as async :refer [chan put! !]] [re-frame.core :refer [subscribe dispatch dispatch-sync]] - [syng-im.utils.debug :refer [log]] + [syng-im.utils.logging :as log] [syng-im.persistence.realm :as realm] [syng-im.persistence.realm :as r] [syng-im.resources :as res] @@ -17,9 +17,9 @@ (get-in db db/updated-discoveries-signal-path)) (defn get-tag [tag] - (let [_ (log (str "Getting tag: " tag))] + (log/debug "Getting tag: " tag) (-> (r/get-by-field :tag :name tag) - (r/single-cljs)))) + (r/single-cljs))) (defn decrease-tag-counter [tag] (let [tag (:name tag) @@ -60,13 +60,10 @@ :photo photo :location location :tags tags - :last-updated last-updated} - _ (log "Creating discovery") - _ (log discovery) - _ (log tags)] - (do - (realm/create :discoveries discovery true) - (increase-tags-counter tags)))) + :last-updated last-updated}] + (log/debug "Creating discovery: " discovery tags) + (realm/create :discoveries discovery true) + (increase-tags-counter tags))) (defn- update-discovery [{:keys [name status whisper-id photo location tags last-updated]}] (let [old-tags (get-tags whisper-id) @@ -78,10 +75,9 @@ :location location :tags tags :last-updated last-updated}] - (do (decrease-tags-counter old-tags) (realm/create :discoveries discovery true) - (increase-tags-counter tags)))) + (increase-tags-counter tags))) (defn- discovery-exist? [discoveries discovery] (some #(= (:whisper-id discovery) (:whisper-id %)) discoveries)) @@ -92,9 +88,7 @@ (defn- add-discoveries [discoveries] (realm/write (fn [] - (let [db-discoveries (.slice (discovery-list) 0) - _ (log discoveries) - _ (log (.slice db-discoveries 0))] + (let [db-discoveries (.slice (discovery-list) 0)] (dorun (map (fn [discovery] (if (not (discovery-exist? db-discoveries discovery)) (create-discovery discovery) @@ -106,10 +100,10 @@ (add-discoveries discoveries)) (defn discoveries-by-tag [tag limit] - (let [_ (log (str "discoveries by tag: " tag))] + (log/debug "Discoveries by tag: " tag) (-> (r/get-by-filter :discoveries (str "tags.name = '" tag "'")) (r/sorted :last-updated :desc) - (r/page 0 limit)))) + (r/page 0 limit))) (defn get-tag-popular [limit] (-> (r/get-all :tag) diff --git a/src/syng_im/persistence/realm.cljs b/src/syng_im/persistence/realm.cljs index 27483c3c86..4af9552dc5 100644 --- a/src/syng_im/persistence/realm.cljs +++ b/src/syng_im/persistence/realm.cljs @@ -1,6 +1,5 @@ (ns syng-im.persistence.realm (:require [cljs.reader :refer [read-string]] - [syng-im.utils.debug :refer [log]] [syng-im.utils.types :refer [to-string]]) (:refer-clojure :exclude [exists?])) @@ -100,9 +99,8 @@ query)) (defn get-by-filter [schema-name filter] - (let [_ (log filter)] (-> (.objects realm (name schema-name)) - (.filtered filter)))) + (.filtered filter))) (defn get-by-field [schema-name field value] (let [q (to-query schema-name :eq field value)] diff --git a/src/syng_im/subscribers/discovery.cljs b/src/syng_im/subscribers/discovery.cljs index 601e65b484..eeca5fe593 100644 --- a/src/syng_im/subscribers/discovery.cljs +++ b/src/syng_im/subscribers/discovery.cljs @@ -2,7 +2,7 @@ (:require-macros [reagent.ratom :refer [reaction]]) (:require [re-frame.core :refer [register-sub]] [syng-im.db :as db] - [syng-im.utils.debug :refer [log]] + [syng-im.utils.logging :as log] [syng-im.models.discoveries :refer [discovery-list get-tag-popular discoveries-by-tag @@ -21,8 +21,8 @@ (register-sub :get-discoveries-by-tag (fn [db [_ tag limit]] (let [discoveries-updated (-> (discoveries-updated? @db) - (reaction)) - _ (log (str "getting discoveries for: " tag))] + (reaction))] + (log/debug "Getting discoveries for: " tag) (reaction (let [_ @discoveries-updated] (discoveries-by-tag tag limit)))))) @@ -30,8 +30,8 @@ (register-sub :get-popular-tags (fn [db [_ limit]] (let [discoveries-updated (-> (discoveries-updated? @db) - (reaction)) - _ (log (str "getting tags limited: " limit))] + (reaction))] + (log/debug "Getting tags limited: " limit) (reaction (let [_ @discoveries-updated] (get-tag-popular limit)))))) \ No newline at end of file diff --git a/src/syng_im/utils/debug.cljs b/src/syng_im/utils/debug.cljs deleted file mode 100644 index aa5f7202ed..0000000000 --- a/src/syng_im/utils/debug.cljs +++ /dev/null @@ -1,3 +0,0 @@ -(ns syng-im.utils.debug) - -(def log (.-log js/console)) \ No newline at end of file From f402fc9b6e8805c988821153d0b1d3181dc3452f Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Tue, 3 May 2016 16:00:44 +0300 Subject: [PATCH 14/23] fixed discovery screen design styles --- .../discovery-popular-list-item.cljs | 14 +++++---- .../components/discovery/discovery.cljs | 28 ++++++++++------- .../discovery/discovery_popular.cljs | 2 +- .../discovery/discovery_popular_list.cljs | 30 ++++++++++++++----- 4 files changed, 49 insertions(+), 25 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 fd0c55a7b6..86b11dc3d0 100644 --- a/src/syng_im/components/discovery/discovery-popular-list-item.cljs +++ b/src/syng_im/components/discovery/discovery-popular-list-item.cljs @@ -17,11 +17,13 @@ [view {:style {:flex 0.8 :flexDirection "column"}} [text {:style {:color "black" - :fontWeight "bold" - :fontSize 12}} (aget discovery "name")] + :fontFamily "sans-serif-medium" + :fontSize 14 + :lineHeight 24}} (aget discovery "name")] [text {:style {:color "black" - :fontWeight "normal" - :fontSize 12} + :fontFamily "sans-serif" + :lineHeight 22 + :fontSize 14} :numberOfLines 2} (aget discovery "status")] ] [view {:style {:flex 0.2 @@ -30,8 +32,8 @@ :paddingTop 5}} [image {:style {:resizeMode "contain" :borderRadius 150 - :width 30 - :height 30} + :width 40 + :height 40} :source res/user-no-photo}] ] ])) \ No newline at end of file diff --git a/src/syng_im/components/discovery/discovery.cljs b/src/syng_im/components/discovery/discovery.cljs index c4ec3e989d..d92b395eba 100644 --- a/src/syng_im/components/discovery/discovery.cljs +++ b/src/syng_im/components/discovery/discovery.cljs @@ -42,7 +42,7 @@ (let [number (rand-int 999)] (do (save-discoveries [{:name (str "Name " number) - :status (str "Status " number) + :status (str "Status This is some longer status to get the second line " number) :whisper-id (str number) :photo "" :location "" @@ -72,26 +72,32 @@ (let [search (aget e "nativeEvent" "text") hashtags (get-hashtags search)] (dispatch [:broadcast-status search hashtags])))}] - [text "Discover"])] + [view {:style {;:flex 1 + ;:flexDirection "row" + ;:justifyContent "center" + ;:alignSelf "stretch" + ;:alignItems "center" + }} + [text {:style {:color "#000000de" + :alignSelf "center" + :textAlign "center" + :fontFamily "sans-serif" + :fontSize 16}} "Discover"]])] [scroll-view {:style {}} - [view {:style {:paddingTop 5}} - [text {:style {:color "#b2bdc5" - :fontSize 14 - :textAlign "center"}} "Discover popular contacts \n around the world"]] [view {:style {:paddingLeft 30 :paddingTop 15 :paddingBottom 15}} - [text {:style {:color "#b2bdc5" - :fontSize 14 - :fontWeight "bold"}} "Popular Tags"]] + [text {:style {:color "#8f838c93" + :fontFamily "sans-serif-medium" + :fontSize 14}} "Popular tags"]] [discovery-popular] [view {:style {:paddingLeft 30 :paddingTop 15 :paddingBottom 15}} - [text {:style {:color "#b2bdc5" + [text {:style {:color "#8f838c93" :fontSize 14 - :fontWeight "bold"}} "Recent"]] + :fontFamily "sans-serif-medium"}} "Recent"]] [discovery-recent] ] ] diff --git a/src/syng_im/components/discovery/discovery_popular.cljs b/src/syng_im/components/discovery/discovery_popular.cljs index 1dae49a7f1..e7f03b0dfa 100644 --- a/src/syng_im/components/discovery/discovery_popular.cljs +++ b/src/syng_im/components/discovery/discovery_popular.cljs @@ -24,7 +24,7 @@ :pageWidth (- (page-width) 60) :sneak 20} (for [tag @popular-tags] - (discovery-popular-list (.-name tag)))] + (discovery-popular-list (.-name tag) (.-count tag)))] [text "None"] ) ) diff --git a/src/syng_im/components/discovery/discovery_popular_list.cljs b/src/syng_im/components/discovery/discovery_popular_list.cljs index 5938e3e9af..8ac9f0aeba 100644 --- a/src/syng_im/components/discovery/discovery_popular_list.cljs +++ b/src/syng_im/components/discovery/discovery_popular_list.cljs @@ -25,28 +25,44 @@ :key rowID}])] elem)) -(defn discovery-popular-list [tag] +(defn discovery-popular-list [tag count] (let [discoveries (subscribe [:get-discoveries-by-tag tag 3])] (log/debug "Got discoveries for tag (" tag "): " @discoveries) [view {:style {:flex 1 :backgroundColor "white" :paddingLeft 10 - :paddingTop 10}} + :paddingTop 16}} [view {:style {:flexDirection "row" :backgroundColor "white" :padding 0}} - [view {:style {:flexDirection "column" - :backgroundColor "#e9f7fe" + [view {:style { + :flexDirection "column"}} + [view {:style {:backgroundColor "#eef2f5" :borderRadius 5 - :padding 0}} - [text {:style {:color "#6092df" + :padding 4}} + [text {:style {:color "#7099e6" + :fontFamily "sans-serif-medium" + :fontSize 14 :paddingRight 5 :paddingBottom 2 :alignItems "center" :justifyContent "center"}} (str " #" (name tag))]]] + [view {:style {:flex 0.2 + :alignItems "flex-end" + :paddingTop 10 + :paddingRight 9}} + [text {:style {:color "#838c93" + :fontFamily "sans-serif" + :fontSize 12 + :paddingRight 5 + :paddingBottom 2 + :alignItems "center" + :justifyContent "center"}} + count]]] [list-view {:dataSource (to-realm-datasource @discoveries) :renderRow render-row :renderSeparator render-separator - :style {:backgroundColor "white"}}] + :style {:backgroundColor "white" + :paddingTop 13}}] ])) From 69df1ad3ef385923b31b016bcafdeb28f44f1f1c Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Thu, 5 May 2016 15:55:11 +0300 Subject: [PATCH 15/23] 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)))))) + From c11da58c50f0363be7c3200a76f12a44009a6f0a Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Thu, 5 May 2016 18:04:17 +0300 Subject: [PATCH 16/23] replaced android toolbar with new custom toolbar --- .../components/discovery/discovery.cljs | 115 +++++++++--------- .../discovery/discovery_recent.cljs | 1 + .../components/discovery/discovery_tag.cljs | 71 +++++++++++ src/syng_im/components/toolbar.cljs | 72 ++++++----- 4 files changed, 169 insertions(+), 90 deletions(-) create mode 100644 src/syng_im/components/discovery/discovery_tag.cljs diff --git a/src/syng_im/components/discovery/discovery.cljs b/src/syng_im/components/discovery/discovery.cljs index f9b9b1340e..7d57cb0a02 100644 --- a/src/syng_im/components/discovery/discovery.cljs +++ b/src/syng_im/components/discovery/discovery.cljs @@ -8,9 +8,9 @@ view scroll-view text - text-input - toolbar-android]] + text-input]] [reagent.core :as r] + [syng-im.components.toolbar :refer [toolbar]] [syng-im.components.discovery.discovery-popular :refer [discovery-popular]] [syng-im.components.discovery.discovery-recent :refer [discovery-recent]] [syng-im.resources :as res] @@ -24,66 +24,67 @@ hashtags []))) +(defn title-content [showSearch] + (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" + :onSubmitEditing (fn [e] + (let [search (aget e "nativeEvent" "text") + hashtags (get-hashtags search)] + (dispatch [:broadcast-status search hashtags])))}] + [view {:style {;:flex 1 + ;:flexDirection "row" + ;:justifyContent "center" + ;:alignSelf "stretch" + ;:alignItems "center" + }} + [text {:style {:color "#000000de" + :alignSelf "center" + :textAlign "center" + :fontFamily "sans-serif" + :fontSize 16}} "Discover"]])) + +(defn create-fake-discovery [] + (let [number (rand-int 999)] + (do + (save-discoveries [{:name (str "Name " number) + :status (str "Status This is some longer status to get the second line " number) + :whisper-id (str number) + :photo "" + :location "" + :tags ["tag1" "tag2" "tag3"] + :last-updated (new js/Date)}]) + (dispatch [:updated-discoveries])))) + (defn discovery [{:keys [navigator]}] (let [showSearch (r/atom false)] (fn [] [view {:style {:flex 1 :backgroundColor "#eef2f5"}} - [toolbar-android {:titleColor "#4A5258" - :navIcon res/menu - :actions [{:title "Search" - :icon res/search - :show "always"}] - :style {:backgroundColor "#eef2f5" - :justifyContent "center" - :height 56 - :elevation 0} - :onIconClicked (fn [] - (let [number (rand-int 999)] - (do - (save-discoveries [{:name (str "Name " number) - :status (str "Status This is some longer status to get the second line " number) - :whisper-id (str number) - :photo "" - :location "" - :tags ["tag1" "tag2" "tag3"] - :last-updated (new js/Date)}]) - (dispatch [:updated-discoveries])))) - ;; temporary dispatch for testing - :onActionSelected (fn [index] - (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/debug (str new-text "-" old-text)))) - :onSubmitEditing (fn [e] - (let [search (aget e "nativeEvent" "text") - hashtags (get-hashtags search)] - (dispatch [:broadcast-status search hashtags])))}] - [view {:style {;:flex 1 - ;:flexDirection "row" - ;:justifyContent "center" - ;:alignSelf "stretch" - ;:alignItems "center" - }} - [text {:style {:color "#000000de" - :alignSelf "center" - :textAlign "center" - :fontFamily "sans-serif" - :fontSize 16}} "Discover"]])] - + [toolbar {:style {:backgroundColor "#eef2f5" + :elevation 0} + :navigator navigator + :nav-action {:image {:source {:uri "icon_hamburger"} + :style {:width 16 + :height 12}} + :handler create-fake-discovery} + :title "Add Participants" + :content (title-content @showSearch) + :action {:image {:source {:uri "icon_search"} + :style {:width 17 + :height 17}} + :handler (fn [] + (if @showSearch + (reset! showSearch false) + (reset! showSearch true)))}}] [scroll-view {:style {}} [view {:style {:paddingLeft 30 :paddingTop 15 diff --git a/src/syng_im/components/discovery/discovery_recent.cljs b/src/syng_im/components/discovery/discovery_recent.cljs index a7b1fb0566..d9a48ebb56 100644 --- a/src/syng_im/components/discovery/discovery_recent.cljs +++ b/src/syng_im/components/discovery/discovery_recent.cljs @@ -28,6 +28,7 @@ (let [discoveries (subscribe [:get-discoveries]) datasource (to-realm-datasource @discoveries)] [list-view {:dataSource datasource + :enableEmptySections true :renderRow render-row :renderSeparator render-separator :style {:backgroundColor "white" diff --git a/src/syng_im/components/discovery/discovery_tag.cljs b/src/syng_im/components/discovery/discovery_tag.cljs new file mode 100644 index 0000000000..956a06cb6d --- /dev/null +++ b/src/syng_im/components/discovery/discovery_tag.cljs @@ -0,0 +1,71 @@ +(ns syng-im.components.discovery.discovery-tag + (:require + [re-frame.core :refer [subscribe]] + [syng-im.utils.logging :as log] + [syng-im.utils.listview :refer [to-realm-datasource + to-datasource]] + [syng-im.navigation :refer [nav-pop]] + [syng-im.components.react :refer [android? + view + text]] + [syng-im.components.realm :refer [list-view]] + [syng-im.components.toolbar :refer [toolbar]] + [reagent.core :as r] + [syng-im.components.discovery.discovery-popular-list-item :refer [discovery-popular-list-item]] + [syng-im.resources :as res])) + +(defn render-row [row section-id row-id] + (log/debug "discovery-tag-row: " row section-id row-id) + (if row + (let [elem (discovery-popular-list-item row)] + elem) + (r/as-element [text "null"]) + )) + +(defn render-separator [sectionID, rowID, adjacentRowHighlighted] + (let [elem (r/as-element [view {:style {:borderBottomWidth 1 + :borderBottomColor "#eff2f3"} + :key rowID}])] + elem)) + +(defn title-content [tag] + [view {:style {:backgroundColor "#eef2f5" + :flexWrap :wrap + :borderRadius 5 + :padding 4}} + [text {:style {:color "#7099e6" + :fontFamily "sans-serif-medium" + :fontSize 14 + :paddingRight 5 + :paddingBottom 2}} + (str " #" tag)]]) + +(defn discovery-tag [{:keys [tag navigator]}] + (let [tag (subscribe [:get-current-tag]) + discoveries (subscribe [:get-discoveries-by-tag @tag 0])] + (log/debug "Got discoveries: " @discoveries) + (fn [] + (let [items @discoveries + datasource (to-realm-datasource items)] + [view {:style {:flex 1 + :backgroundColor "#eef2f5"}} + [toolbar {:navigator navigator + :nav-action {:image {:source {:uri "icon_back"} + :style {:width 8 + :height 14}} + :handler (fn [] (nav-pop navigator))} + :title "Add Participants" + :content (title-content @tag) + :action {:image {:source {:uri "icon_search"} + :style {:width 17 + :height 17}} + :handler (fn [] + ())}}] + + [list-view {:dataSource datasource + :enableEmptySections true + :renderRow render-row + :renderSeparator render-separator + :style {:backgroundColor "white" + :paddingLeft 15}}] + ])))) \ No newline at end of file diff --git a/src/syng_im/components/toolbar.cljs b/src/syng_im/components/toolbar.cljs index 94155f8a6f..84768c5084 100644 --- a/src/syng_im/components/toolbar.cljs +++ b/src/syng_im/components/toolbar.cljs @@ -18,41 +18,47 @@ [reagent.core :as r] [syng-im.navigation :refer [nav-pop]])) -(defn toolbar [{:keys [navigator title nav-action action background-color]}] - [view {:style {:flexDirection "row" - :backgroundColor (or background-color toolbar-background1) - :height 56 - :elevation 2}} - (if nav-action - [touchable-highlight {:on-press (:handler nav-action) +(defn toolbar [{:keys [navigator title nav-action action background-color content style]}] + (let [style (merge {:flexDirection "row" + :backgroundColor (or background-color toolbar-background1) + :height 56 + :elevation 2} style)] + [view {:style style} + (if nav-action + [touchable-highlight {:on-press (:handler nav-action) + :underlay-color :transparent} + [view {:width 56 + :height 56 + :alignItems "center" + :justifyContent "center"} + [image (:image nav-action)]]] + [touchable-highlight {:on-press (fn [] + (nav-pop navigator)) + :underlay-color :transparent} + [view {:width 56 + :height 56} + [image {:source {:uri "icon_back"} + :style {:marginTop 21 + :marginLeft 23 + :width 8 + :height 14}}]]]) + (if content + [view {:style {:flex 1 + :alignItems "center" + :justifyContent "center"}} + content] + [view {:style {:flex 1 + :alignItems "center" + :justifyContent "center"}} + [text {:style {:marginTop -2.5 + :color text1-color + :fontSize 16 + :fontFamily font}} + title]]) + [touchable-highlight {:on-press (:handler action) :underlay-color :transparent} [view {:width 56 :height 56 :alignItems "center" :justifyContent "center"} - [image (:image nav-action)]]] - [touchable-highlight {:on-press (fn [] - (nav-pop navigator)) - :underlay-color :transparent} - [view {:width 56 - :height 56} - [image {:source {:uri "icon_back"} - :style {:marginTop 21 - :marginLeft 23 - :width 8 - :height 14}}]]]) - [view {:style {:flex 1 - :alignItems "center" - :justifyContent "center"}} - [text {:style {:marginTop -2.5 - :color text1-color - :fontSize 16 - :fontFamily font}} - title]] - [touchable-highlight {:on-press (:handler action) - :underlay-color :transparent} - [view {:width 56 - :height 56 - :alignItems "center" - :justifyContent "center"} - [image (:image action)]]]]) + [image (:image action)]]]])) From 4bc6b83c96d081c9274b02c9292fd5425a33fd09 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Sat, 7 May 2016 10:35:35 +0300 Subject: [PATCH 17/23] protocol's version --- project.clj | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/project.clj b/project.clj index 37ed02bf72..8e27322b77 100644 --- a/project.clj +++ b/project.clj @@ -8,7 +8,9 @@ [reagent "0.5.1" :exclusions [cljsjs/react]] [re-frame "0.6.0"] [prismatic/schema "1.0.4"] - [syng-im/protocol "0.1.1"] + ^{:voom {:repo "https://github.com/status-im/status-lib.git" + :branch "feature-discover"}} + [syng-im/protocol "0.1.1-20160506_171115-ge2c95c1"] [natal-shell "0.1.6"]] :plugins [[lein-cljsbuild "1.1.1"] [lein-figwheel "0.5.0-2"]] @@ -44,4 +46,4 @@ :main "env.android.main" :output-dir "target/android" :optimizations :simple}}}} - }}) \ No newline at end of file + }}) From 4b41ff8507fffd9685846fee7942875622f74905 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Sat, 7 May 2016 12:15:48 +0300 Subject: [PATCH 18/23] rename subscribers folder --- src/syng_im/{subscribers => subscriptions}/discovery.cljs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/syng_im/{subscribers => subscriptions}/discovery.cljs (100%) diff --git a/src/syng_im/subscribers/discovery.cljs b/src/syng_im/subscriptions/discovery.cljs similarity index 100% rename from src/syng_im/subscribers/discovery.cljs rename to src/syng_im/subscriptions/discovery.cljs From 4eaeb4c477fb6fb474011cf5053f59bba6c939ec Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Sat, 7 May 2016 12:58:06 +0300 Subject: [PATCH 19/23] add scroll threshold to carousel --- src/syng_im/components/carousel.cljs | 29 +++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/syng_im/components/carousel.cljs b/src/syng_im/components/carousel.cljs index f032b4a1cc..1c2c4e495d 100644 --- a/src/syng_im/components/carousel.cljs +++ b/src/syng_im/components/carousel.cljs @@ -12,7 +12,8 @@ (def defaults {:gap 10 :sneak 10 - :pageWidth (- (page-width) 40)}) + :pageWidth (- (page-width) 40) + :scrollThreshold 20}) (defn get-gap [data] @@ -24,6 +25,9 @@ (defn get-page-width [data] (get data :pageWidth (:pageWidth defaults))) +(defn get-scroll-threshold [data] + (get data :scrollThreshold (:scrollThreshold defaults))) + (defn calculate-gap [component props] (let [prop-page-width (get-page-width props) page-width (page-width) @@ -41,22 +45,29 @@ :x x}))) (defn get-current-position [event] - (+ (.-x (.-contentOffset (.-nativeEvent event))) (quot (page-width) 2))) + (.-x (.-contentOffset (.-nativeEvent event)))) -(defn on-scroll-end [event component] +(defn on-scroll-end [event component starting-position] (let [props (reagent.core/props component) state (reagent.core/state component) prop-page-width (get-page-width props) sneak (get-sneak props) + scroll-threshold (get-scroll-threshold props) gap (get-gap state) page-offset (+ prop-page-width gap) current-position (get-current-position event) - current-page (quot current-position page-offset) + direction (if (> current-position (+ starting-position scroll-threshold)) + 1 + (if (< current-position (- starting-position scroll-threshold)) + -1 + 0)) + current-page (+ (quot starting-position page-offset) direction) ] (log/debug "on-scroll-end: prop-page-width=" prop-page-width "; sneak=" sneak "; gap=" gap "; page-offset=" page-offset + "; starting position=" starting-position "; current-position=" current-position - "; current-page=" current-page) + "; direction=" direction "; current-page=" current-page) (scroll-to component (* current-page page-offset) 0) (reagent.core/set-state component {:activePage current-page}) (when (:onPageChange props) @@ -109,7 +120,8 @@ child]])) children))) (defn reagent-render [data children] - (let [component (reagent.core/current-component) + (let [starting-position (atom 0) + component (reagent.core/current-component) sneak (get-sneak data) gap (get-gap data) pages (get-pages component data children)] @@ -121,7 +133,10 @@ :bounces false :decelerationRate 0.9 :horizontal true - :onScrollEndDrag (fn [event] (on-scroll-end event component)) + :onScrollBeginDrag (fn [event] + (let [] + (reset! starting-position (get-current-position event)))) + :onScrollEndDrag (fn [event] (on-scroll-end event component @starting-position)) :showsHorizontalScrollIndicator false :ref (fn [c] (set! (.-scrollView component) c)) } From d009f038e5c78ade011b866c9fe075c413f3193e Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Sat, 7 May 2016 15:13:03 +0300 Subject: [PATCH 20/23] Revert figwheel-bridge.js. Applied suggestions. --- README.md | 1 - figwheel-bridge.js | 95 +++++++++++++++------------- src/syng_im/components/carousel.cljs | 15 ++--- src/syng_im/persistence/realm.cljs | 3 +- 4 files changed, 60 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index b4afb5a3d5..54b510765e 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,6 @@ A Clojure library designed to ... well, that part is up to you. adb reverse tcp:3449 tcp:3449 react-native run-android ->>>>>>> origin/develop ## License diff --git a/figwheel-bridge.js b/figwheel-bridge.js index 137673ca19..2a7cb1cc2f 100644 --- a/figwheel-bridge.js +++ b/figwheel-bridge.js @@ -5,7 +5,6 @@ */ var CLOSURE_UNCOMPILED_DEFINES = null; -var debugEnabled = false; var config = { basePath: "target/", @@ -14,24 +13,13 @@ var config = { }; var React = require('react-native'); -var WebSocket = require('WebSocket'); var self; var scriptQueue = []; var serverHost = null; // will be set dynamically var fileBasePath = null; // will be set dynamically var evaluate = eval; // This is needed, direct calls to eval does not work (RN packager???) var externalModules = {}; -var evalListeners = [ // Functions to be called after each js file is loaded and evaluated - function (url) { - if (url.indexOf('jsloader') > -1) { - shimJsLoader(); - } - }, - function (url) { - if (url.indexOf('/figwheel/client/socket') > -1) { - setCorrectWebSocketImpl(); - } - }]; +var evalListeners = []; // functions to be called when a script is evaluated var figwheelApp = function (platform, devHost) { return React.createClass({ @@ -52,7 +40,7 @@ var figwheelApp = function (platform, devHost) { componentDidMount: function () { var app = this; if (typeof goog === "undefined") { - loadApp(platform, devHost, function (appRoot) { + loadApp(platform, devHost, function(appRoot) { app.setState({root: appRoot, loaded: true}) }); } @@ -60,19 +48,13 @@ var figwheelApp = function (platform, devHost) { }) }; -function logDebug(msg) { - if (debugEnabled) { - console.log(msg); - } -} - // evaluates js code ensuring proper ordering function customEval(url, javascript, success, error) { if (scriptQueue.length > 0) { if (scriptQueue[0] === url) { try { evaluate(javascript); - logDebug('Evaluated: ' + url); + console.info('Evaluated: ' + url); scriptQueue.shift(); evalListeners.forEach(function (listener) { listener(url) @@ -99,7 +81,7 @@ var isChrome = function () { }; function asyncImportScripts(url, success, error) { - logDebug('(asyncImportScripts) Importing: ' + url); + console.info('(asyncImportScripts) Importing: ' + url); scriptQueue.push(url); fetch(url) .then(function (response) { @@ -118,7 +100,7 @@ function asyncImportScripts(url, success, error) { function syncImportScripts(url, success, error) { try { importScripts(url); - logDebug('Evaluated: ' + url); + console.info('Evaluated: ' + url); evalListeners.forEach(function (listener) { listener(url) }); @@ -141,7 +123,7 @@ function importJs(src, success, error) { var file = fileBasePath + '/' + src; - logDebug('(importJs) Importing: ' + file); + console.info('(importJs) Importing: ' + file); if (isChrome()) { syncImportScripts(serverBaseUrl("localhost") + '/' + file, success, error); } else { @@ -161,49 +143,43 @@ function interceptRequire() { }; } -function compileWarningsToYellowBox() { - var log = window.console.log; - var compileWarningRx = /Figwheel: Compile/; - window.console.log = function (msg) { - if (compileWarningRx.test(msg)) { - console.warn(msg); - } else { - log.apply(window.console, arguments); - } - }; +// do not show debug messages in yellow box +function debugToLog() { + console.debug = console.log; } function serverBaseUrl(host) { return "http://" + host + ":" + config.serverPort } -function setCorrectWebSocketImpl() { - figwheel.client.socket.get_websocket_imp = function () { - return WebSocket; - }; -} - function loadApp(platform, devHost, onLoadCb) { serverHost = devHost; fileBasePath = config.basePath + platform; + evalListeners.push(function (url) { + if (url.indexOf('jsloader') > -1) { + shimJsLoader(); + } + }); + // callback when app is ready to get the reloadable component var mainJs = '/env/' + platform + '/main.js'; evalListeners.push(function (url) { if (url.indexOf(mainJs) > -1) { onLoadCb(env[platform].main.root_el); - console.info('Done loading Clojure app'); + console.log('Done loading Clojure app'); } }); if (typeof goog === "undefined") { - console.info('Loading Closure base.'); + console.log('Loading Closure base.'); interceptRequire(); - compileWarningsToYellowBox(); importJs('goog/base.js', function () { shimBaseGoog(); + fakeLocalStorageAndDocument(); importJs('cljs_deps.js'); importJs('goog/deps.js', function () { + debugToLog(); // This is needed because of RN packager // seriously React packager? why. var googreq = goog.require; @@ -233,6 +209,39 @@ function shimBaseGoog() { importJs(src); return true; }; + goog.inHtmlDocument_ = function () { + return true; + }; +} + +function fakeLocalStorageAndDocument() { + window.localStorage = {}; + window.localStorage.getItem = function () { + return 'true'; + }; + window.localStorage.setItem = function () { + }; + + window.document = {}; + window.document.body = {}; + window.document.body.dispatchEvent = function () { + }; + window.document.createElement = function () { + }; + + if (typeof window.location === 'undefined') { + window.location = {}; + } + console.debug = console.warn; + window.addEventListener = function () { + }; + // make figwheel think that heads-up-display divs are there + window.document.querySelector = function (selector) { + return {}; + }; + window.document.getElementById = function (id) { + return {style:{}}; + }; } // Figwheel fixes diff --git a/src/syng_im/components/carousel.cljs b/src/syng_im/components/carousel.cljs index 1c2c4e495d..5c5904f0f0 100644 --- a/src/syng_im/components/carousel.cljs +++ b/src/syng_im/components/carousel.cljs @@ -56,11 +56,10 @@ gap (get-gap state) page-offset (+ prop-page-width gap) current-position (get-current-position event) - direction (if (> current-position (+ starting-position scroll-threshold)) - 1 - (if (< current-position (- starting-position scroll-threshold)) - -1 - 0)) + direction (cond + (> current-position (+ starting-position scroll-threshold)) 1 + (< current-position (- starting-position scroll-threshold)) -1 + :else 0) current-page (+ (quot starting-position page-offset) direction) ] (log/debug "on-scroll-end: prop-page-width=" prop-page-width @@ -133,10 +132,8 @@ :bounces false :decelerationRate 0.9 :horizontal true - :onScrollBeginDrag (fn [event] - (let [] - (reset! starting-position (get-current-position event)))) - :onScrollEndDrag (fn [event] (on-scroll-end event component @starting-position)) + :onScrollBeginDrag #(reset! starting-position (get-current-position %)) + :onScrollEndDrag #(on-scroll-end % component @starting-position) :showsHorizontalScrollIndicator false :ref (fn [c] (set! (.-scrollView component) c)) } diff --git a/src/syng_im/persistence/realm.cljs b/src/syng_im/persistence/realm.cljs index ad0f070b8b..0770a8f2e4 100644 --- a/src/syng_im/persistence/realm.cljs +++ b/src/syng_im/persistence/realm.cljs @@ -1,5 +1,6 @@ (ns syng-im.persistence.realm (:require [cljs.reader :refer [read-string]] + [syng-im.utils.logging :as log] [syng-im.utils.types :refer [to-string]]) (:refer-clojure :exclude [exists?])) @@ -147,7 +148,7 @@ (.-length objs)) (defn get-list [schema-name] - (vals (js->clj (.slice (.objects realm (to-string schema-name)) 0) :keywordize-keys true))) + (vals (js->clj (.objects realm (to-string schema-name)) :keywordize-keys true))) (comment From 3976ea6c70e4277359fc42d4f985b6e090853470 Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Sat, 7 May 2016 17:53:39 +0300 Subject: [PATCH 21/23] moved styles to separate file --- .../components/discovery/discovery.cljs | 41 +---- .../discovery/discovery_popular.cljs | 8 +- .../discovery/discovery_popular_list.cljs | 49 ++--- .../discovery_popular_list_item.cljs | 28 +-- .../discovery/discovery_recent.cljs | 7 +- .../components/discovery/discovery_tag.cljs | 29 +-- src/syng_im/components/discovery/styles.cljs | 173 ++++++++++++++++++ 7 files changed, 215 insertions(+), 120 deletions(-) create mode 100644 src/syng_im/components/discovery/styles.cljs diff --git a/src/syng_im/components/discovery/discovery.cljs b/src/syng_im/components/discovery/discovery.cljs index 7d57cb0a02..8536715102 100644 --- a/src/syng_im/components/discovery/discovery.cljs +++ b/src/syng_im/components/discovery/discovery.cljs @@ -14,6 +14,7 @@ [syng-im.components.discovery.discovery-popular :refer [discovery-popular]] [syng-im.components.discovery.discovery-recent :refer [discovery-recent]] [syng-im.resources :as res] + [syng-im.components.discovery.styles :as st] [syng-im.persistence.realm :as realm])) (def search-input (atom {:search "x"})) @@ -27,30 +28,15 @@ (defn title-content [showSearch] (if showSearch [text-input {:underlineColorAndroid "transparent" - ;:value (:search @search-input) - :style {:flex 1 - :marginLeft 18 - :lineHeight 42 - :fontSize 14 - :fontFamily "Avenir-Roman" - :color "#9CBFC0"} + :style st/discovery-search-input :autoFocus true :placeholder "Type your search tags here" :onSubmitEditing (fn [e] (let [search (aget e "nativeEvent" "text") hashtags (get-hashtags search)] (dispatch [:broadcast-status search hashtags])))}] - [view {:style {;:flex 1 - ;:flexDirection "row" - ;:justifyContent "center" - ;:alignSelf "stretch" - ;:alignItems "center" - }} - [text {:style {:color "#000000de" - :alignSelf "center" - :textAlign "center" - :fontFamily "sans-serif" - :fontSize 16}} "Discover"]])) + [view + [text {:style st/discovery-title} "Discover"]])) (defn create-fake-discovery [] (let [number (rand-int 999)] @@ -69,8 +55,7 @@ (fn [] [view {:style {:flex 1 :backgroundColor "#eef2f5"}} - [toolbar {:style {:backgroundColor "#eef2f5" - :elevation 0} + [toolbar {:style st/discovery-toolbar :navigator navigator :nav-action {:image {:source {:uri "icon_hamburger"} :style {:width 16 @@ -86,19 +71,11 @@ (reset! showSearch false) (reset! showSearch true)))}}] [scroll-view {:style {}} - [view {:style {:paddingLeft 30 - :paddingTop 15 - :paddingBottom 15}} - [text {:style {:color "#8f838c93" - :fontFamily "sans-serif-medium" - :fontSize 14}} "Popular tags"]] + [view {:style st/section-spacing} + [text {:style st/discovery-subtitle} "Popular tags"]] [discovery-popular navigator] - [view {:style {:paddingLeft 30 - :paddingTop 15 - :paddingBottom 15}} - [text {:style {:color "#8f838c93" - :fontSize 14 - :fontFamily "sans-serif-medium"}} "Recent"]] + [view {:style st/section-spacing} + [text {:style st/discovery-subtitle} "Recent"]] [discovery-recent]]]))) (comment (def page-width (aget (natal-shell.dimensions/get "window") "width")) diff --git a/src/syng_im/components/discovery/discovery_popular.cljs b/src/syng_im/components/discovery/discovery_popular.cljs index 7e2b144e19..21b4fdab0a 100644 --- a/src/syng_im/components/discovery/discovery_popular.cljs +++ b/src/syng_im/components/discovery/discovery_popular.cljs @@ -5,6 +5,7 @@ [syng-im.components.react :refer [android? text]] [syng-im.components.carousel :refer [carousel]] + [syng-im.components.discovery.styles :as st] [syng-im.components.discovery.discovery-popular-list :refer [discovery-popular-list]] )) @@ -15,12 +16,7 @@ (let [popular-tags (subscribe [:get-popular-tags 3])] (log/debug "Got popular tags: " @popular-tags) (if (> (count @popular-tags) 0) - [carousel {:pageStyle {:borderRadius 1 - :shadowColor "black" - :shadowRadius 1 - :shadowOpacity 0.8 - :elevation 2 - :marginBottom 10} + [carousel {:pageStyle st/carousel-page-style :pageWidth (- (page-width) 60) :sneak 20} (for [tag @popular-tags] diff --git a/src/syng_im/components/discovery/discovery_popular_list.cljs b/src/syng_im/components/discovery/discovery_popular_list.cljs index 32e88b536e..afdb5fd77c 100644 --- a/src/syng_im/components/discovery/discovery_popular_list.cljs +++ b/src/syng_im/components/discovery/discovery_popular_list.cljs @@ -10,6 +10,7 @@ image]] [reagent.core :as r] [syng-im.components.realm :refer [list-view]] + [syng-im.components.discovery.styles :as st] [syng-im.utils.listview :refer [to-realm-datasource]] [syng-im.components.discovery.discovery-popular-list-item :refer [discovery-popular-list-item] ]) ) @@ -21,52 +22,26 @@ ) (defn render-separator [sectionID, rowID, adjacentRowHighlighted] - (let [elem (r/as-element [view {:style {:borderBottomWidth 1 - :borderBottomColor "#eff2f3"} + (let [elem (r/as-element [view {:style st/row-separator :key rowID}])] elem)) (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 - :backgroundColor "white" - :paddingLeft 10 - :paddingTop 16}} - [view {:style {:flexDirection "row" - :backgroundColor "white" - :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}} - [text {:style {:color "#7099e6" - :fontFamily "sans-serif-medium" - :fontSize 14 - :paddingRight 5 - :paddingBottom 2 - :alignItems "center" - :justifyContent "center"}} + [view {:style st/popular-list-container} + [view {:style st/row} + [view {:style st/column} + [touchable-highlight {:onPress #(dispatch [:show-discovery-tag tag navigator :push])} + [view {:style st/tag-name-container} + [text {:style st/tag-name} (str " #" (name tag))]]]] - [view {:style {:flex 0.2 - :alignItems "flex-end" - :paddingTop 10 - :paddingRight 9}} - [text {:style {:color "#838c93" - :fontFamily "sans-serif" - :fontSize 12 - :paddingRight 5 - :paddingBottom 2 - :alignItems "center" - :justifyContent "center"}} + [view {:style st/tag-count-container} + [text {:style st/tag-count} count]]] [list-view {:dataSource (to-realm-datasource @discoveries) :enableEmptySections true - :renderRow render-row + :renderRow render-row :renderSeparator render-separator - :style {:backgroundColor "white" - :paddingTop 13}}] + :style st/popular-list}] ])) 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 86b11dc3d0..616fa9d7e2 100644 --- a/src/syng_im/components/discovery/discovery_popular_list_item.cljs +++ b/src/syng_im/components/discovery/discovery_popular_list_item.cljs @@ -6,34 +6,20 @@ text image]] [syng-im.resources :as res] + [syng-im.components.discovery.styles :as st] [reagent.core :as r]) ) (defn discovery-popular-list-item [discovery] (log/debug discovery) - (r/as-element [view {:style {:flexDirection "row" - :paddingTop 10 - :paddingBottom 10}} - [view {:style {:flex 0.8 - :flexDirection "column"}} - [text {:style {:color "black" - :fontFamily "sans-serif-medium" - :fontSize 14 - :lineHeight 24}} (aget discovery "name")] - [text {:style {:color "black" - :fontFamily "sans-serif" - :lineHeight 22 - :fontSize 14} + (r/as-element [view {:style st/popular-list-item} + [view {:style st/popular-list-item-name-container} + [text {:style st/popular-list-item-name} (aget discovery "name")] + [text {:style st/popular-list-item-status :numberOfLines 2} (aget discovery "status")] ] - [view {:style {:flex 0.2 - :flexDirection "column" - :alignItems "center" - :paddingTop 5}} - [image {:style {:resizeMode "contain" - :borderRadius 150 - :width 40 - :height 40} + [view {:style st/popular-list-item-avatar-container} + [image {:style st/popular-list-item-avatar :source res/user-no-photo}] ] ])) \ No newline at end of file diff --git a/src/syng_im/components/discovery/discovery_recent.cljs b/src/syng_im/components/discovery/discovery_recent.cljs index d9a48ebb56..4b1a650322 100644 --- a/src/syng_im/components/discovery/discovery_recent.cljs +++ b/src/syng_im/components/discovery/discovery_recent.cljs @@ -9,6 +9,7 @@ view]] [syng-im.components.realm :refer [list-view]] [syng-im.utils.listview :refer [to-realm-datasource]] + [syng-im.components.discovery.styles :as st] [syng-im.components.discovery.discovery-popular-list-item :refer [discovery-popular-list-item]] [reagent.core :as r])) @@ -19,8 +20,7 @@ ) (defn render-separator [sectionID, rowID, adjacentRowHighlighted] - (let [elem (r/as-element [view {:style {:borderBottomWidth 1 - :borderBottomColor "#eff2f3"} + (let [elem (r/as-element [view {:style st/row-separator :key rowID}])] elem)) @@ -31,6 +31,5 @@ :enableEmptySections true :renderRow render-row :renderSeparator render-separator - :style {:backgroundColor "white" - :paddingLeft 15}}] + :style st/recent-list}] )) \ No newline at end of file diff --git a/src/syng_im/components/discovery/discovery_tag.cljs b/src/syng_im/components/discovery/discovery_tag.cljs index 956a06cb6d..ba7b247fc4 100644 --- a/src/syng_im/components/discovery/discovery_tag.cljs +++ b/src/syng_im/components/discovery/discovery_tag.cljs @@ -12,7 +12,8 @@ [syng-im.components.toolbar :refer [toolbar]] [reagent.core :as r] [syng-im.components.discovery.discovery-popular-list-item :refer [discovery-popular-list-item]] - [syng-im.resources :as res])) + [syng-im.resources :as res] + [syng-im.components.discovery.styles :as st])) (defn render-row [row section-id row-id] (log/debug "discovery-tag-row: " row section-id row-id) @@ -23,21 +24,13 @@ )) (defn render-separator [sectionID, rowID, adjacentRowHighlighted] - (let [elem (r/as-element [view {:style {:borderBottomWidth 1 - :borderBottomColor "#eff2f3"} + (let [elem (r/as-element [view {:style st/row-separator :key rowID}])] elem)) (defn title-content [tag] - [view {:style {:backgroundColor "#eef2f5" - :flexWrap :wrap - :borderRadius 5 - :padding 4}} - [text {:style {:color "#7099e6" - :fontFamily "sans-serif-medium" - :fontSize 14 - :paddingRight 5 - :paddingBottom 2}} + [view {:style st/tag-title-container} + [text {:style st/tag-title} (str " #" tag)]]) (defn discovery-tag [{:keys [tag navigator]}] @@ -47,18 +40,15 @@ (fn [] (let [items @discoveries datasource (to-realm-datasource items)] - [view {:style {:flex 1 - :backgroundColor "#eef2f5"}} + [view {:style st/discovery-tag-container} [toolbar {:navigator navigator :nav-action {:image {:source {:uri "icon_back"} - :style {:width 8 - :height 14}} + :style st/icon-back} :handler (fn [] (nav-pop navigator))} :title "Add Participants" :content (title-content @tag) :action {:image {:source {:uri "icon_search"} - :style {:width 17 - :height 17}} + :style st/icon-search} :handler (fn [] ())}}] @@ -66,6 +56,5 @@ :enableEmptySections true :renderRow render-row :renderSeparator render-separator - :style {:backgroundColor "white" - :paddingLeft 15}}] + :style st/recent-list}] ])))) \ No newline at end of file diff --git a/src/syng_im/components/discovery/styles.cljs b/src/syng_im/components/discovery/styles.cljs new file mode 100644 index 0000000000..da85fb9732 --- /dev/null +++ b/src/syng_im/components/discovery/styles.cljs @@ -0,0 +1,173 @@ +(ns syng-im.components.discovery.styles + (:require [syng-im.components.styles :refer [font + title-font + color-white + chat-background + online-color + selected-message-color + separator-color + text1-color + text2-color + toolbar-background1]])) + +;; common + +(def row-separator + {:borderBottomWidth 1 + :borderBottomColor "#eff2f3"}) + +(def row + {:flexDirection "row"}) + +(def column + {:flexDirection "column"}) + +;; discovery.cljs + +(def discovery-search-input + {:flex 1 + :marginLeft 18 + :lineHeight 42 + :fontSize 14 + :fontFamily "Avenir-Roman" + :color "#9CBFC0"}) + +(def discovery-title + {:color "#000000de" + :alignSelf "center" + :textAlign "center" + :fontFamily "sans-serif" + :fontSize 16}) + +(def discovery-toolbar + {:backgroundColor "#eef2f5" + :elevation 0}) + +(def discovery-subtitle + {:color "#8f838c93" + :fontFamily "sans-serif-medium" + :fontSize 14}) + +(def section-spacing + {:paddingLeft 30 + :paddingTop 15 + :paddingBottom 15}) + +;; discovery_popular.cljs + +(def carousel-page-style + {:borderRadius 1 + :shadowColor "black" + :shadowRadius 1 + :shadowOpacity 0.8 + :elevation 2 + :marginBottom 10}) + +;; discovery_populat_list.cljs + +(def tag-name + {:color "#7099e6" + :fontFamily "sans-serif-medium" + :fontSize 14 + :paddingRight 5 + :paddingBottom 2 + :alignItems "center" + :justifyContent "center"}) + +(def tag-name-container + {:backgroundColor "#eef2f5" + :borderRadius 5 + :padding 4}) + +(def tag-count + {:color "#838c93" + :fontFamily "sans-serif" + :fontSize 12 + :paddingRight 5 + :paddingBottom 2 + :alignItems "center" + :justifyContent "center"}) + +(def tag-count-container + {:flex 0.2 + :alignItems "flex-end" + :paddingTop 10 + :paddingRight 9}) + +(def popular-list-container + {:flex 1 + :backgroundColor "white" + :paddingLeft 10 + :paddingTop 16}) + +(def popular-list + {:backgroundColor "white" + :paddingTop 13}) + +;; discover_popular_list_item.cjls + +(def popular-list-item + {:flexDirection "row" + :paddingTop 10 + :paddingBottom 10}) + +(def popular-list-item-status + {:color "black" + :fontFamily "sans-serif" + :lineHeight 22 + :fontSize 14}) + +(def popular-list-item-name + {:color "black" + :fontFamily "sans-serif-medium" + :fontSize 14 + :lineHeight 24}) + +(def popular-list-item-name-container + {:flex 0.8 + :flexDirection "column"}) + +(def popular-list-item-avatar-container + {:flex 0.2 + :flexDirection "column" + :alignItems "center" + :paddingTop 5}) + +(def popular-list-item-avatar + {:resizeMode "contain" + :borderRadius 150 + :width 40 + :height 40}) + +;; discovery_recent + +(def recent-list + {:backgroundColor "white" + :paddingLeft 15}) + +;; discovery_tag + +(def discovery-tag-container + {:flex 1 + :backgroundColor "#eef2f5"}) + +(def tag-title + {:color "#7099e6" + :fontFamily "sans-serif-medium" + :fontSize 14 + :paddingRight 5 + :paddingBottom 2}) + +(def tag-title-container + {:backgroundColor "#eef2f5" + :flexWrap :wrap + :borderRadius 5 + :padding 4}) + +(def icon-back + {:width 8 + :height 14}) + +(def icon-search + {:width 17 + :height 17}) \ No newline at end of file From 2f11811d55f07d1fc63e3d1f147d3148ba0d591a Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Sat, 7 May 2016 18:04:19 +0300 Subject: [PATCH 22/23] moved handlers and subs to component folder --- .../discovery.cljs => components/discovery/handlers.cljs} | 2 +- .../discovery.cljs => components/discovery/subs.cljs} | 8 ++++---- src/syng_im/handlers.cljs | 2 +- src/syng_im/subs.cljs | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) rename src/syng_im/{handlers/discovery.cljs => components/discovery/handlers.cljs} (96%) rename src/syng_im/{subscriptions/discovery.cljs => components/discovery/subs.cljs} (89%) diff --git a/src/syng_im/handlers/discovery.cljs b/src/syng_im/components/discovery/handlers.cljs similarity index 96% rename from src/syng_im/handlers/discovery.cljs rename to src/syng_im/components/discovery/handlers.cljs index 45e3b06a6f..44d24c99d9 100644 --- a/src/syng_im/handlers/discovery.cljs +++ b/src/syng_im/components/discovery/handlers.cljs @@ -1,4 +1,4 @@ -(ns syng-im.handlers.discovery +(ns syng-im.components.discovery.handlers (:require [re-frame.core :refer [register-handler after dispatch]] [syng-im.utils.logging :as log] [syng-im.protocol.api :as api] diff --git a/src/syng_im/subscriptions/discovery.cljs b/src/syng_im/components/discovery/subs.cljs similarity index 89% rename from src/syng_im/subscriptions/discovery.cljs rename to src/syng_im/components/discovery/subs.cljs index 49375de678..d1a8eb5399 100644 --- a/src/syng_im/subscriptions/discovery.cljs +++ b/src/syng_im/components/discovery/subs.cljs @@ -1,4 +1,4 @@ -(ns syng-im.subscriptions.discovery +(ns syng-im.components.discovery.subs (:require-macros [reagent.ratom :refer [reaction]]) (:require [re-frame.core :refer [register-sub]] [syng-im.db :as db] @@ -15,7 +15,7 @@ (register-sub :get-discoveries (fn [db _] (let [discoveries-updated (-> (discoveries-updated? @db) - (reaction))] + (reaction))] (reaction (let [_ @discoveries-updated] (discovery-list)))))) @@ -23,7 +23,7 @@ (register-sub :get-discoveries-by-tag (fn [db [_ tag limit]] (let [discoveries-updated (-> (discoveries-updated? @db) - (reaction))] + (reaction))] (log/debug "Getting discoveries for: " tag) (reaction (let [_ @discoveries-updated] @@ -32,7 +32,7 @@ (register-sub :get-popular-tags (fn [db [_ limit]] (let [discoveries-updated (-> (discoveries-updated? @db) - (reaction))] + (reaction))] (log/debug "Getting tags limited: " limit) (reaction (let [_ @discoveries-updated] diff --git a/src/syng_im/handlers.cljs b/src/syng_im/handlers.cljs index 309e89e7ef..fdef1faa8d 100644 --- a/src/syng_im/handlers.cljs +++ b/src/syng_im/handlers.cljs @@ -28,7 +28,7 @@ apply-staged-commands check-suggestion]] [syng-im.handlers.sign-up :as sign-up-service] - [syng-im.handlers.discovery :as discovery] + [syng-im.components.discovery.handlers :as discovery] [syng-im.models.chats :refer [chat-exists? create-chat chat-add-participants diff --git a/src/syng_im/subs.cljs b/src/syng_im/subs.cljs index b8dd5de64d..407676c2de 100644 --- a/src/syng_im/subs.cljs +++ b/src/syng_im/subs.cljs @@ -2,7 +2,7 @@ (:require-macros [reagent.ratom :refer [reaction]]) (:require [re-frame.core :refer [register-sub]] [syng-im.db :as db] - [syng-im.subscriptions.discovery :as discovery] + [syng-im.components.discovery.subs :as discovery] [syng-im.models.chat :refer [current-chat-id chat-updated?]] [syng-im.models.chats :refer [chats-list From d68e0781302955b605bdd1141e7f092038c0a92e Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Mon, 9 May 2016 21:22:02 +0300 Subject: [PATCH 23/23] refactored carousel component --- src/syng_im/components/carousel.cljs | 150 --------------- src/syng_im/components/carousel/carousel.cljs | 178 ++++++++++++++++++ src/syng_im/components/carousel/styles.cljs | 24 +++ .../discovery/discovery_popular.cljs | 3 +- .../discovery/discovery_popular_list.cljs | 13 +- .../discovery_popular_list_item.cljs | 1 - src/syng_im/components/discovery/styles.cljs | 4 +- 7 files changed, 211 insertions(+), 162 deletions(-) delete mode 100644 src/syng_im/components/carousel.cljs create mode 100644 src/syng_im/components/carousel/carousel.cljs create mode 100644 src/syng_im/components/carousel/styles.cljs diff --git a/src/syng_im/components/carousel.cljs b/src/syng_im/components/carousel.cljs deleted file mode 100644 index 5c5904f0f0..0000000000 --- a/src/syng_im/components/carousel.cljs +++ /dev/null @@ -1,150 +0,0 @@ -(ns syng-im.components.carousel - (:require [syng-im.components.react :refer [android? - view - scroll-view - touchable-without-feedback - text]] - [syng-im.utils.logging :as log])) - - -(defn page-width [] - (.-width (.get (.. js/React -Dimensions) "window"))) - -(def defaults {:gap 10 - :sneak 10 - :pageWidth (- (page-width) 40) - :scrollThreshold 20}) - - -(defn get-gap [data] - (get data :gap (:gap defaults))) - -(defn get-sneak [data] - (get data :sneak (:sneak defaults))) - -(defn get-page-width [data] - (get data :pageWidth (:pageWidth defaults))) - -(defn get-scroll-threshold [data] - (get data :scrollThreshold (:scrollThreshold defaults))) - -(defn calculate-gap [component props] - (let [prop-page-width (get-page-width props) - page-width (page-width) - sneak (get-sneak props) - gap (quot (- (- page-width (* 2 sneak)) prop-page-width) 2)] - (log/debug "calculate-gap: prop-page-width=" prop-page-width - "; page-width=" page-width"; sneak=" sneak "; gap=" gap) - (when (> prop-page-width page-width) - (log/warn "Invalid pageWidth")) - (reagent.core/set-state component {:gap gap}) - )) - -(defn scroll-to [component x y] - (.scrollTo (.-scrollView component) (clj->js {:y y - :x x}))) - -(defn get-current-position [event] - (.-x (.-contentOffset (.-nativeEvent event)))) - -(defn on-scroll-end [event component starting-position] - (let [props (reagent.core/props component) - state (reagent.core/state component) - prop-page-width (get-page-width props) - sneak (get-sneak props) - scroll-threshold (get-scroll-threshold props) - gap (get-gap state) - page-offset (+ prop-page-width gap) - current-position (get-current-position event) - direction (cond - (> current-position (+ starting-position scroll-threshold)) 1 - (< current-position (- starting-position scroll-threshold)) -1 - :else 0) - current-page (+ (quot starting-position page-offset) direction) - ] - (log/debug "on-scroll-end: prop-page-width=" prop-page-width - "; sneak=" sneak "; gap=" gap "; page-offset=" page-offset - "; starting position=" starting-position - "; current-position=" current-position - "; direction=" direction "; current-page=" current-page) - (scroll-to component (* current-page page-offset) 0) - (reagent.core/set-state component {:activePage current-page}) - (when (:onPageChange props) - ((:onPageChange props) current-page)))) - -(defn go-to-page [component position] - (let [props (reagent.core/props component) - state (reagent.core/state component) - props-page-width (get-page-width props) - gap (get-gap state) - page-position (* position (+ props-page-width gap))] - (log/debug "go-to-page: props-page-width=" props-page-width "; gap=" gap - "; page-position=" page-position) - (scroll-to component page-position 0))) - -(defn component-will-mount [component new-args] - (let [props (reagent.core/props component)] - (log/debug "component-will-mount: component=" component "; new-args="new-args) - (calculate-gap component props))) - -(defn component-did-mount [component] - (let [props (reagent.core/props component) - initial-page (.-initialPage props)] - (log/debug "component-did-mount: initial-page="initial-page) - (when (pos? initial-page) - (go-to-page component initial-page)))) - -(defn component-will-receive-props [component new-argv] - (log/debug "component-will-receive-props: component=" component - "; new-argv=" new-argv) - (calculate-gap component new-argv)) - -(defn get-pages [component data children] - (let [props-page-width (get-page-width data) - page-style (get data :pageStyle {}) - gap (get-gap data) - margin (quot gap 2)] - (map-indexed (fn [index child] - (let [page-index index - touchable-data {:key index - :onPress (fn [event] - (go-to-page component page-index))}] - (log/debug "page " index " - " child) - [touchable-without-feedback touchable-data - [view {:style [{:width props-page-width - :justifyContent "center" - :marginLeft margin - :marginRight margin} - page-style]} - child]])) children))) - -(defn reagent-render [data children] - (let [starting-position (atom 0) - component (reagent.core/current-component) - sneak (get-sneak data) - gap (get-gap data) - pages (get-pages component data children)] - (log/debug "reagent-render: ") - [view {:style {:flex 1}} - [scroll-view {:contentContainerStyle {:paddingLeft (+ sneak (quot gap 2)) - :paddingRight (+ sneak (quot gap 2))} - :automaticallyAdjustContentInsets false - :bounces false - :decelerationRate 0.9 - :horizontal true - :onScrollBeginDrag #(reset! starting-position (get-current-position %)) - :onScrollEndDrag #(on-scroll-end % component @starting-position) - :showsHorizontalScrollIndicator false - :ref (fn [c] (set! (.-scrollView component) c)) - } - pages]] - )) - -(defn carousel [data children] - (let [component-data {:component-did-mount component-did-mount - :component-will-mount component-will-mount - :component-will-receive-props component-will-receive-props - :display-name "carousel" - :reagent-render reagent-render}] - (log/debug "Creating carousel component: " data children) - (reagent.core/create-class component-data))) diff --git a/src/syng_im/components/carousel/carousel.cljs b/src/syng_im/components/carousel/carousel.cljs new file mode 100644 index 0000000000..b489482f5d --- /dev/null +++ b/src/syng_im/components/carousel/carousel.cljs @@ -0,0 +1,178 @@ +(ns syng-im.components.carousel + (:require [syng-im.components.react :refer [android? + view + scroll-view + touchable-without-feedback + text]] + [syng-im.components.carousel.styles :as st] + [syng-im.utils.logging :as log])) + + +(defn window-page-width [] + (.-width (.get (.. js/React -Dimensions) "window"))) + +(def defaults {:gap 10 + :sneak 10 + :pageStyle {} + :scrollThreshold 20}) + +(defn get-active-page [data] + (get data :activePage 0)) + +(defn get-sneak [data] + (get data :sneak (:sneak defaults))) + +(defn get-gap [data] + (get data :gap (:gap defaults))) + +(defn compute-page-width + ([gap sneak] + (compute-page-width (window-page-width) gap sneak)) + ([window-page-width gap sneak] + (- window-page-width (+ (* 2 gap) (* 2 sneak))))) + +(defn get-page-width [data] + (get data :pageWidth (compute-page-width (get-gap data) (get-sneak data)))) + +(defn get-page-style [data] + (let [data-style (get data :pageStyle {})] + (merge (:pageStyle defaults) data-style))) + +(defn get-scroll-threshold [data] + (get data :scrollThreshold (:scrollThreshold defaults))) + +(defn apply-props [component props] + (let [sneak (get-sneak props) + page-width (get-page-width props) + style (get-page-style props) + gap (quot (- (- (window-page-width) (* 2 sneak)) page-width) 2)] + (reagent.core/set-state component {:sneak sneak + :pageWidth page-width + :pageStyle style + :gap gap}))) + +(defn scroll-to [component x y] + (.scrollTo (.-scrollView component) (clj->js {:y y + :x x}))) + +(defn get-current-position [event] + (.-x (.-contentOffset (.-nativeEvent event)))) + +(defn go-to-page [component page] + (let [props (reagent.core/props component) + state (reagent.core/state component) + page-width (get-page-width state) + gap (get-gap state) + page-position (* page (+ page-width gap))] + (log/debug "go-to-page: props-page-width=" page-width "; gap=" gap + "; page-position=" page-position) + (scroll-to component page-position 0) + (reagent.core/set-state component {:activePage page}) + (when (:onPageChange props) + ((:onPageChange props) page)))) + +(defn on-scroll-end [event component starting-position] + (let [props (reagent.core/props component) + state (reagent.core/state component) + scroll-threshold (get-scroll-threshold props) + current-page (get-active-page state) + current-position (get-current-position event) + direction (cond + (> current-position (+ starting-position scroll-threshold)) 1 + (< current-position (- starting-position scroll-threshold)) -1 + :else 0) + new-page (+ current-page direction) + ] + (log/debug state "on-scroll-end: starting position=" starting-position + "; current-position=" current-position "; direction=" direction + "; current-page=" current-page "; new-page=" new-page) + (if (not= current-page new-page) + (go-to-page component new-page) + (scroll-to component starting-position 0)))) + +(defn component-will-mount [component new-args] + (let [props (reagent.core/props component)] + (log/debug "component-will-mount: new-args="new-args) + (apply-props component props))) + +(defn component-did-mount [component] + (let [props (reagent.core/props component) + initial-page (.-initialPage props)] + (log/debug "component-did-mount: initial-page="initial-page) + (when (pos? initial-page) + (go-to-page component initial-page)))) + +(defn component-will-update [component new-argv] + (log/debug "component-will-update: ")) + +(defn component-did-update [component old-argv] + (log/debug "component-did-update")) + +(defn component-will-receive-props [component new-argv] + (log/debug "component-will-receive-props: new-argv=" new-argv) + (apply-props component new-argv)) + +(defn get-event-width [event] + (.-width (.-layout (.-nativeEvent event)))) + +(defn on-layout-change [event component] + (let [state (reagent.core/state component) + page-width (compute-page-width (get-event-width event) (get-gap state) (get-sneak state)) + state-page-width (get-page-width state) + active-page (get-active-page state) + gap (get-gap state) + page-position (* active-page (+ page-width gap))] + (log/debug "Layout changed: " " page-width=" page-width "; state-page-width=" state-page-width) + (if (not= page-width state-page-width) + (do + (reagent.core/set-state component {:pageWidth page-width}) + (.setState component {:layout (.-layout (.-nativeEvent event))}) + ) + (scroll-to component page-position 0)))) + +(defn get-pages [component data children] + (let [page-width (get-page-width data) + page-style (get-page-style data) + gap (get-gap data) + margin (quot gap 2)] + (doall (map-indexed (fn [index child] + (let [page-index index + touchable-data {:key index + :onPress #(go-to-page component page-index)}] + [touchable-without-feedback touchable-data + [view {:style [(st/page page-width margin) + page-style] + :onLayout #(log/debug "view onLayout" %)} + + child]])) children)))) + +(defn reagent-render [data children] + (let [starting-position (atom 0) + component (reagent.core/current-component) + state (reagent.core/state component) + sneak (get-sneak state) + gap (get-gap state)] + (log/debug "reagent-render: " data state) + [view {:style st/scroll-view-container} + [scroll-view {:contentContainerStyle (st/content-container sneak gap) + :automaticallyAdjustContentInsets false + :bounces false + :decelerationRate 0.9 + :horizontal true + :onLayout #(on-layout-change % component) + :onScrollBeginDrag #(reset! starting-position (get-current-position %)) + :onScrollEndDrag #(on-scroll-end % component @starting-position) + :showsHorizontalScrollIndicator false + :ref #(set! (.-scrollView component) %)} + (get-pages component state children)]])) + +(defn carousel [data children] + (let [component-data {:component-did-mount component-did-mount + :component-will-mount component-will-mount + :component-will-receive-props component-will-receive-props + :component-will-update component-will-update + :component-did-update component-did-update + :display-name "carousel" + :reagent-render reagent-render}] + (log/debug "Creating carousel component: " data) + (reagent.core/create-class component-data))) diff --git a/src/syng_im/components/carousel/styles.cljs b/src/syng_im/components/carousel/styles.cljs new file mode 100644 index 0000000000..def9de8c10 --- /dev/null +++ b/src/syng_im/components/carousel/styles.cljs @@ -0,0 +1,24 @@ +(ns syng-im.components.carousel.styles + (:require [syng-im.components.styles :refer [font + title-font + color-white + chat-background + online-color + selected-message-color + separator-color + text1-color + text2-color + toolbar-background1]])) + +(def scroll-view-container + {:flex 1}) + +(defn content-container [sneak gap] + {:paddingLeft (+ sneak (quot gap 2)) + :paddingRight (+ sneak (quot gap 2))}) + +(defn page [page-width margin] + {:width page-width + :justifyContent "center" + :marginLeft margin + :marginRight margin}) \ No newline at end of file diff --git a/src/syng_im/components/discovery/discovery_popular.cljs b/src/syng_im/components/discovery/discovery_popular.cljs index 21b4fdab0a..df33467899 100644 --- a/src/syng_im/components/discovery/discovery_popular.cljs +++ b/src/syng_im/components/discovery/discovery_popular.cljs @@ -17,8 +17,7 @@ (log/debug "Got popular tags: " @popular-tags) (if (> (count @popular-tags) 0) [carousel {:pageStyle st/carousel-page-style - :pageWidth (- (page-width) 60) - :sneak 20} + :sneak 20} (for [tag @popular-tags] (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 afdb5fd77c..0291a1bb82 100644 --- a/src/syng_im/components/discovery/discovery_popular_list.cljs +++ b/src/syng_im/components/discovery/discovery_popular_list.cljs @@ -28,14 +28,12 @@ (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 st/popular-list-container} - [view {:style st/row} - [view {:style st/column} + [view st/row + [view st/tag-name-container [touchable-highlight {:onPress #(dispatch [:show-discovery-tag tag navigator :push])} - [view {:style st/tag-name-container} - [text {:style st/tag-name} - (str " #" (name tag))]]]] + [text {:style st/tag-name} + (str " #" (name tag))]]] [view {:style st/tag-count-container} [text {:style st/tag-count} count]]] @@ -43,5 +41,4 @@ :enableEmptySections true :renderRow render-row :renderSeparator render-separator - :style st/popular-list}] - ])) + :style st/popular-list}]])) 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 616fa9d7e2..49e08f2672 100644 --- a/src/syng_im/components/discovery/discovery_popular_list_item.cljs +++ b/src/syng_im/components/discovery/discovery_popular_list_item.cljs @@ -11,7 +11,6 @@ ) (defn discovery-popular-list-item [discovery] - (log/debug discovery) (r/as-element [view {:style st/popular-list-item} [view {:style st/popular-list-item-name-container} [text {:style st/popular-list-item-name} (aget discovery "name")] diff --git a/src/syng_im/components/discovery/styles.cljs b/src/syng_im/components/discovery/styles.cljs index da85fb9732..9c988558f9 100644 --- a/src/syng_im/components/discovery/styles.cljs +++ b/src/syng_im/components/discovery/styles.cljs @@ -75,7 +75,8 @@ :justifyContent "center"}) (def tag-name-container - {:backgroundColor "#eef2f5" + {:flexDirection "column" + :backgroundColor "#eef2f5" :borderRadius 5 :padding 4}) @@ -90,6 +91,7 @@ (def tag-count-container {:flex 0.2 + :flexDirection "column" :alignItems "flex-end" :paddingTop 10 :paddingRight 9})