 (ns chat.client.views
   (:require [om.core :as om]
             [om.dom :as dom]
+            [clojure.string :as string]
+            [cljs-uuid-utils.core :as uuid]
             [chat.client.dispatcher :refer [dispatch!]]
             [chat.client.store :as store]))
 

        (dom/div #js {:className "content"}
          (message :content))))))

(defn new-message-view [config owner]
  (reify
    om/IRender

                           :onKeyDown
                           (fn [e]
                             (when (and (= 13 e.keyCode) (= e.shiftKey false))
                               (let [text (.. e -target -value)
                                     tags (->> (re-seq tag-pattern text) (map second))
                                     tagless-text (string/replace text tag-pattern "")]
                                 (when (or (config :new-thread) (not (string/blank? tagless-text)))
                                   (dispatch! :new-message {:thread-id (config :thread-id)
                                                            :content tagless-text}))
                                 (when-not (empty? tags)
                                   (doseq [tag tags]
                                     (dispatch! :tag-thread {:thread-id (config :thread-id)
                                                             :tag-name tag}))))
                               (.preventDefault e)
                               (aset (.. e -target) "value" "")))})))))

