<commit_before>(ns pomodonut.core
  (:require [cljs.core.async :refer [chan close!]]
            [goog.dom :as gdom]
            [om.dom :as dom]
            [om.next :as om :refer-macros [defui]])
  (:require-macros [cljs.core.async.macros :refer [go-loop]]))

(enable-console-print!)

(def app-state (atom {}))
(defonce interval (atom nil))
(defonce timeout (atom nil))

(defonce ONE_MINUTE 60)
(defonce FIVE_MINUTES (* 5 ONE_MINUTE))
(defonce TEN_MINUTES (* 10 ONE_MINUTE))
(defonce TWENTY_FIVE_MINUTES (* 25 ONE_MINUTE))

(defonce ENTER_KEY 13)

(defonce chime-sound (js/Audio. "wav/chime.wav"))
(defonce tick-sound (js/Audio. "wav/watch-tick.wav"))

(declare reconciler)

(defn timer-class [break?]
  (str
    "bg-"
    (if break? "green" "red")
    " circle flex flex-center mx-auto shadow "
    (if-not (nil? @interval) " pointer")))

(defn format-time
  "Format time as mm:ss"
  [t]
  (let [minutes (js/parseInt (/ t ONE_MINUTE))
        seconds (.slice
                  (str "00" (js/parseInt (mod t ONE_MINUTE)))
                  -2)]
    (str minutes ":" seconds)))

;; https://gist.github.com/swannodette/5882703
(defn wait [ms]
  (let [c (chan)
        t (js/setTimeout (fn [] (close! c)) ms)]
    (reset! timeout t)
    c))

(defn clear-timeout []
  (js/clearTimeout @timeout)
  (close! @interval)
  (reset! interval nil)
  (reset! timeout nil))

(defn start-timer
  [duration s]
  (let [i (go-loop [t s]
            (om/transact! reconciler
              `[(timer/update ~{:duration duration
                                :elapsed t})])
            (if (< t duration)
              (do
                (.play tick-sound)
                (<! (wait 1000))
                (recur (inc t)))
              (do
                (clear-timeout)
                (if (get-in @app-state [:timer :break?])
                  (om/transact! reconciler
                    `[(timer/update ~{:break? false
                                     :duration TWENTY_FIVE_MINUTES
                                     :elapsed 0})])
                  (do
                    (.play chime-sound)
                    (om/transact! reconciler
                      `[(tasks/complete) :tasks])
                    (om/transact! reconciler
                      `[(timer/update
                          ~{:break? true
                            :duration
                            (if (== 0
                                  (rem
                                    (count
                                      (filter #(:done? %)
                                        (:tasks @app-state)))
                                    4))
                              TEN_MINUTES
                              FIVE_MINUTES)
                            :elapsed 0})]))))))]
    (reset! interval i)))

(defn stop-timer [c]
  (clear-timeout)
  (om/transact! c `[(timer/update ~{:break? false
                                    :duration TWENTY_FIVE_MINUTES
                                    :elapsed 0})]))

(defn button-class
  "Returns the class of a button based on its type.
  button-type should be in
  [\"default\", \"disabled\", \"primary\"]"
  [button-type]
  (str "btn btn-" button-type " shadow"))

(defn button
  [props & children]
  (let [{:keys [button-type on-click]} props]
    (dom/a #js {:className (button-class button-type)
                :onClick on-click}
      children)))

(defn task-class
  [{:keys [done?]}]
  (str "list-item px3 py1" (when done? " gray")))

(defui Task
  static om/IQuery
  (query [this]
    [:done? :title :ts])
  Object
  (render [this]
    (let [{:keys [title] :as props} (om/props this)]
      (dom/li #js {:className (task-class props)} title))))

(def task (om/factory Task {:keyfn :ts}))

(defn submit
  [c e]
  (do
    (om/transact! reconciler `[(tasks/create ~(om/props c)) :tasks])
    (om/transact! reconciler `[(tasks/update-temp ~nil) :tasks/temp])
    (start-timer TWENTY_FIVE_MINUTES 0)
    (doto e (.preventDefault) (.stopPropagation))))

(defn change-title
  [c e]
  (when-not (.-defaultPrevented e)
    (om/transact! c
      `[(tasks/update-temp ~{:title (-> e .-target .-value)})])))

(defn key-down
  [c e]
  (condp == (.-keyCode e)
    ENTER_KEY (submit c e)
    nil))

(defui TaskForm
  static om/IQuery
  (query [this]
    [:title])
  Object
  (render [this]
    (let [{:keys [title]} (om/props this)]
      (dom/div #js {:className "mx-auto"
                    :style #js {:width 400}}
        (dom/div #js {:className "full-width group"}<commit_msg>Make sure the form isn't too wide<commit_after>(ns pomodonut.core
  (:require [cljs.core.async :refer [chan close!]]
            [goog.dom :as gdom]
            [om.dom :as dom]
            [om.next :as om :refer-macros [defui]])
  (:require-macros [cljs.core.async.macros :refer [go-loop]]))

(enable-console-print!)

(def app-state (atom {}))
(defonce interval (atom nil))
(defonce timeout (atom nil))

(defonce ONE_MINUTE 60)
(defonce FIVE_MINUTES (* 5 ONE_MINUTE))
(defonce TEN_MINUTES (* 10 ONE_MINUTE))
(defonce TWENTY_FIVE_MINUTES (* 25 ONE_MINUTE))

(defonce ENTER_KEY 13)

(defonce chime-sound (js/Audio. "wav/chime.wav"))
(defonce tick-sound (js/Audio. "wav/watch-tick.wav"))

(declare reconciler)

(defn timer-class [break?]
  (str
    "bg-"
    (if break? "green" "red")
    " circle flex flex-center mx-auto shadow "
    (if-not (nil? @interval) " pointer")))

(defn format-time
  "Format time as mm:ss"
  [t]
  (let [minutes (js/parseInt (/ t ONE_MINUTE))
        seconds (.slice
                  (str "00" (js/parseInt (mod t ONE_MINUTE)))
                  -2)]
    (str minutes ":" seconds)))

;; https://gist.github.com/swannodette/5882703
(defn wait [ms]
  (let [c (chan)
        t (js/setTimeout (fn [] (close! c)) ms)]
    (reset! timeout t)
    c))

(defn clear-timeout []
  (js/clearTimeout @timeout)
  (close! @interval)
  (reset! interval nil)
  (reset! timeout nil))

(defn start-timer
  [duration s]
  (let [i (go-loop [t s]
            (om/transact! reconciler
              `[(timer/update ~{:duration duration
                                :elapsed t})])
            (if (< t duration)
              (do
                (.play tick-sound)
                (<! (wait 1000))
                (recur (inc t)))
              (do
                (clear-timeout)
                (if (get-in @app-state [:timer :break?])
                  (om/transact! reconciler
                    `[(timer/update ~{:break? false
                                     :duration TWENTY_FIVE_MINUTES
                                     :elapsed 0})])
                  (do
                    (.play chime-sound)
                    (om/transact! reconciler
                      `[(tasks/complete) :tasks])
                    (om/transact! reconciler
                      `[(timer/update
                          ~{:break? true
                            :duration
                            (if (== 0
                                  (rem
                                    (count
                                      (filter #(:done? %)
                                        (:tasks @app-state)))
                                    4))
                              TEN_MINUTES
                              FIVE_MINUTES)
                            :elapsed 0})]))))))]
    (reset! interval i)))

(defn stop-timer [c]
  (clear-timeout)
  (om/transact! c `[(timer/update ~{:break? false
                                    :duration TWENTY_FIVE_MINUTES
                                    :elapsed 0})]))

(defn button-class
  "Returns the class of a button based on its type.
  button-type should be in
  [\"default\", \"disabled\", \"primary\"]"
  [button-type]
  (str "btn btn-" button-type " shadow"))

(defn button
  [props & children]
  (let [{:keys [button-type on-click]} props]
    (dom/a #js {:className (button-class button-type)
                :onClick on-click}
      children)))

(defn task-class
  [{:keys [done?]}]
  (str "list-item px3 py1" (when done? " gray")))

(defui Task
  static om/IQuery
  (query [this]
    [:done? :title :ts])
  Object
  (render [this]
    (let [{:keys [title] :as props} (om/props this)]
      (dom/li #js {:className (task-class props)} title))))

(def task (om/factory Task {:keyfn :ts}))

(defn submit
  [c e]
  (do
    (om/transact! reconciler `[(tasks/create ~(om/props c)) :tasks])
    (om/transact! reconciler `[(tasks/update-temp ~nil) :tasks/temp])
    (start-timer TWENTY_FIVE_MINUTES 0)
    (doto e (.preventDefault) (.stopPropagation))))

(defn change-title
  [c e]
  (when-not (.-defaultPrevented e)
    (om/transact! c
      `[(tasks/update-temp ~{:title (-> e .-target .-value)})])))

(defn key-down
  [c e]
  (condp == (.-keyCode e)
    ENTER_KEY (submit c e)
    nil))

(defui TaskForm
  static om/IQuery
  (query [this]
    [:title])
  Object
  (render [this]
    (let [{:keys [title]} (om/props this)]
      (dom/div #js {:className "mx-auto"
                    :style #js {:width 340}}
        (dom/div #js {:className "full-width group"}
{'fraction_non_alphanumeric': 0.14888200132831525, 'fraction_numerical': 0.00752711976975869, 'mean_word_length': 1.6612665684830634, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4865217', 'n_tokens_mistral': 3083, 'n_tokens_neox': 2933, 'n_words': 763}