<commit_before>(ns om-chat.components.message-composer
  (:require [om.next :as om :refer-macros [defui]]
            [om.dom :as dom]
            ))

(def ESCAPE_KEY 27)
(def ENTER_KEY 13)

(defn change [c e]
  (om/update-state! c assoc
                    :edit-text (.. e -target -value)))

(defn key-down [c id e on-new-msg]
  (condp == (.-keyCode e)
    ENTER_KEY
    (let [msg-text (or (om/get-state c :edit-text) "")]
      (on-new-msg id msg-text)
      (doto e (.preventDefault) (.stopPropagation)))
    nil))

(defui MessageComposer
  ;; static om/IQuery
  ;; (query [this]
  ;;        :thread/id)
  Object
  (render [this]
          (let [{:keys [thread/id] :as props} (om/props this)
                {:keys [on-new-msg]} (om/get-computed props)]
;;            (println "RENDER composer: " props)
            (dom/textarea #js{:className "message-composer"
                              :name      "message"
                              :value     (om/get-state this :edit-text)
                              :onChange  #(change this %)
                              :onKeyDown #(key-down this id % on-new-msg)})
            )))

(def message-composer (om/factory MessageComposer))
<commit_msg>Reset textarea after message posted<commit_after>(ns om-chat.components.message-composer
  (:require [om.next :as om :refer-macros [defui]]
            [om.dom :as dom]
            ))

(def ESCAPE_KEY 27)
(def ENTER_KEY 13)

(defn change [c e]
  (om/update-state! c assoc
                    :edit-text (.. e -target -value)))

(defn key-down [c id e on-new-msg]
  (condp == (.-keyCode e)
    ENTER_KEY
    (let [msg-text (or (om/get-state c :edit-text) "")]
      (if-not (= msg-text "") (on-new-msg id msg-text))
      (om/update-state! c assoc :edit-text "")
      (doto e (.preventDefault) (.stopPropagation)))
    nil))

(defui MessageComposer
  ;; static om/IQuery
  ;; (query [this]
  ;;        :thread/id)
  Object
  (render [this]
          (let [{:keys [thread/id] :as props} (om/props this)
                {:keys [on-new-msg]} (om/get-computed props)]
;;            (println "RENDER composer: " props)
            (dom/textarea #js{:className "message-composer"
                              :name      "message"
                              :value     (om/get-state this :edit-text)
                              :onChange  #(change this %)
                              :onKeyDown #(key-down this id % on-new-msg)})
            )))

(def message-composer (om/factory MessageComposer))

{'fraction_non_alphanumeric': 0.14924181963288108, 'fraction_numerical': 0.0031923383878691143, 'mean_word_length': 1.7519209659714599, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5386154', 'n_tokens_mistral': 857, 'n_tokens_neox': 825, 'n_words': 206}