From 1e179302950826a8925fb29c4477fe703c23999f Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Mon, 16 May 2016 14:05:43 +0300 Subject: [PATCH] content-suggestions Former-commit-id: c833764e224334f9212073265cb1dc3a25433492 --- .../styles/content_suggestions.cljs} | 2 +- src/syng_im/chat/views/command.cljs | 3 +- .../chat/views/content_suggestions.cljs | 36 +++++++++++++ .../components/chat/content_suggestions.cljs | 50 ------------------- 4 files changed, 39 insertions(+), 52 deletions(-) rename src/syng_im/{components/chat/content_suggestions_styles.cljs => chat/styles/content_suggestions.cljs} (96%) create mode 100644 src/syng_im/chat/views/content_suggestions.cljs delete mode 100644 src/syng_im/components/chat/content_suggestions.cljs diff --git a/src/syng_im/components/chat/content_suggestions_styles.cljs b/src/syng_im/chat/styles/content_suggestions.cljs similarity index 96% rename from src/syng_im/components/chat/content_suggestions_styles.cljs rename to src/syng_im/chat/styles/content_suggestions.cljs index c0169e8ea3..60c670fada 100644 --- a/src/syng_im/components/chat/content_suggestions_styles.cljs +++ b/src/syng_im/chat/styles/content_suggestions.cljs @@ -1,4 +1,4 @@ -(ns syng-im.components.chat.content-suggestions-styles +(ns syng-im.chat.styles.content-suggestions (:require [syng-im.components.styles :refer [font color-light-blue-transparent color-white diff --git a/src/syng_im/chat/views/command.cljs b/src/syng_im/chat/views/command.cljs index 0a2fd24210..688e3d0736 100644 --- a/src/syng_im/chat/views/command.cljs +++ b/src/syng_im/chat/views/command.cljs @@ -5,7 +5,8 @@ text text-input touchable-highlight]] - [syng-im.components.chat.content-suggestions :refer [content-suggestions-view]] + [syng-im.chat.views.content-suggestions :refer + [content-suggestions-view]] [syng-im.chat.styles.input :as st])) (defn cancel-command-input [] diff --git a/src/syng_im/chat/views/content_suggestions.cljs b/src/syng_im/chat/views/content_suggestions.cljs new file mode 100644 index 0000000000..a2e67c8cfc --- /dev/null +++ b/src/syng_im/chat/views/content_suggestions.cljs @@ -0,0 +1,36 @@ +(ns syng-im.chat.views.content-suggestions + (:require-macros [syng-im.utils.views :refer [defview]]) + (:require [re-frame.core :refer [subscribe dispatch]] + [syng-im.components.react :refer [view + icon + text + touchable-highlight + list-view + list-item]] + [syng-im.chat.styles.content-suggestions :as st] + [syng-im.utils.listview :refer [to-datasource]])) + +(defn set-command-content [content] + (dispatch [:set-chat-command-content content])) + +(defn suggestion-list-item [{:keys [value description]}] + [touchable-highlight {:onPress #(set-command-content value)} + [view st/suggestion-container + [view st/suggestion-sub-container + [text {:style st/value-text} value] + [text {:style st/description-text} description]]]]) + +(defn render-row [row _ _] + (list-item [suggestion-list-item row])) + +(defview content-suggestions-view [] + [suggestions [:get-content-suggestions]] + (when (seq suggestions) + [view + [touchable-highlight {:style st/drag-down-touchable + ;; TODO hide suggestions? + :onPress (fn [])} + [view [icon :drag_down st/drag-down-icon]]] + [view (st/suggestions-container (count suggestions)) + [list-view {:dataSource (to-datasource suggestions) + :renderRow render-row}]]])) diff --git a/src/syng_im/components/chat/content_suggestions.cljs b/src/syng_im/components/chat/content_suggestions.cljs deleted file mode 100644 index e79a88bc6f..0000000000 --- a/src/syng_im/components/chat/content_suggestions.cljs +++ /dev/null @@ -1,50 +0,0 @@ -(ns syng-im.components.chat.content-suggestions - (:require-macros - [natal-shell.core :refer [with-error-view]]) - (:require [clojure.string :as cstr] - [reagent.core :as r] - [re-frame.core :refer [subscribe dispatch dispatch-sync]] - [syng-im.components.react :refer [view - icon - text - touchable-highlight - list-view - list-item]] - [syng-im.components.chat.content-suggestions-styles :as st] - [syng-im.utils.listview :refer [to-datasource]] - [syng-im.utils.utils :refer [log toast http-post]] - [syng-im.utils.logging :as log])) - -(defn set-command-content [content] - (dispatch [:set-chat-command-content content])) - -(defn suggestion-list-item [suggestion] - [touchable-highlight {:onPress (fn [] - (set-command-content (:value suggestion))) - :underlay-color :transparent} - [view st/suggestion-container - [view st/suggestion-sub-container - [text {:style st/value-text} - (:value suggestion)] - [text {:style st/description-text} - (:description suggestion)]]]]) - -(defn render-row [row section-id row-id] - (list-item [suggestion-list-item (js->clj row :keywordize-keys true)])) - -(defn content-suggestions-view [] - (let [suggestions-atom (subscribe [:get-content-suggestions])] - (fn [] - (let [suggestions @suggestions-atom] - (when (seq suggestions) - [view nil - [touchable-highlight {:style st/drag-down-touchable - :onPress (fn [] - ;; TODO hide suggestions? - ) - :underlay-color :transparent} - [view nil - [icon :drag_down st/drag-down-icon]]] - [view (st/suggestions-container (count suggestions)) - [list-view {:dataSource (to-datasource suggestions) - :renderRow render-row}]]])))))