<commit_before>(ns kata.pages.problem-editor
  (:require [reagent.core :as reagent :refer [atom]]
            [ajax.core :refer [GET POST]]
            [cljs.pprint :refer [pprint]]))

(defn render-code [this]
  (->> this reagent/dom-node (.highlightBlock js/hljs)))

(defn result-view [output]
  (reagent/create-class
    {:render (fn []
               [:pre>code.clj
                #_(with-out-str (pprint output))
                @output])
     :component-did-update render-code
     :component-did-mount render-code}))

(defn submit-code
  ""
  [input error result]
  (POST "/api/evaluate"
        {:params        {:code @input}
         :handler       #(reset! result %)
         :error-handler #(reset! error %)}))

(defn editor-did-mount [input]
  (fn [this]
    (let [cm (.fromTextArea  js/CodeMirror
                             (reagent/dom-node this)
                             #js {:mode "clojure"
                                  :lineNumbers true})]
      (.on cm "change" #(reset! input (.getValue %))))))

(defn editor [input]
  (reagent/create-class
    {:render (fn [] [:textarea
                     {:default-value ""
                      :auto-complete "off"}])
     :component-did-mount (editor-did-mount input)}))

(defn editor-page
  "fun stuff"
  []
  (let [input (atom nil)
        error (atom nil)
        result (atom {:foo :bar})]
    (fn []
      [:div
       [:div.row>div.col-md-12>button
        {:on-click #(submit-code input error result)} "PRESS ME"]
       [:div.row>div.col-md-12
        [editor input]
        [:div.row>div.col-md-12
         [result-view input]]]])))<commit_msg>working repl that calls server to eval<commit_after>(ns kata.pages.problem-editor
  (:require [reagent.core :as reagent :refer [atom]]
            [ajax.core :refer [GET POST]]
            [cljs.pprint :refer [pprint]]))

(defn render-code [this]
  (->> this reagent/dom-node (.highlightBlock js/hljs)))

(defn result-view [output]
  (reagent/create-class
    {:render (fn []
               [:pre>code.clj
                #_(with-out-str (pprint output))
                @output])
     :component-did-update render-code
     :component-did-mount render-code}))

(defn submit-code
  ""
  [input error result]
  (POST "/api/evaluate"
        {:params        {:expr @input}
         :handler       #(reset! result %)
         :error-handler #(reset! error %)}))

(defn editor-did-mount [input]
  (fn [this]
    (let [cm (.fromTextArea  js/CodeMirror
                             (reagent/dom-node this)
                             #js {:mode "clojure"
                                  :lineNumbers true})]
      (.on cm "change" #(reset! input (.getValue %))))))

(defn editor [input]
  (reagent/create-class
    {:render (fn [] [:textarea
                     {:default-value ""
                      :auto-complete "off"}])
     :component-did-mount (editor-did-mount input)}))

(defn editor-page
  "fun stuff"
  []
  (let [input (atom nil)
        error (atom nil)
        result (atom {:foo :bar})]
    (fn []
      [:div
       [:div.row>div.col-md-12>button
        {:on-click #(submit-code input error result)} "PRESS ME"]
       [:div.row>div.col-md-12
        [editor input]
        [:div.row>div.col-md-12
         [result-view result]]]])))
{'fraction_non_alphanumeric': 0.1594379963347587, 'fraction_numerical': 0.0036652412950519244, 'mean_word_length': 1.8652668416447944, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4318794', 'n_tokens_mistral': 1109, 'n_tokens_neox': 1052, 'n_words': 243}