content-suggestions

This commit is contained in:
Roman Volosovskyi 2016-05-16 14:05:43 +03:00
parent ac4548f63b
commit c833764e22
4 changed files with 39 additions and 52 deletions

View File

@ -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

View File

@ -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 []

View File

@ -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}]]]))

View File

@ -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}]]])))))