<commit_before>(ns client.mc
	(:require-macros [hiccups.core :as hiccups])
  (:require
    [cljs.reader :refer [read-string]]
    [client.socket :refer [socket]]
		hiccups.runtime))

(def $ js/$)

;;------------------------------------------------------------
;; Stop Game page
;;------------------------------------------------------------

(hiccups/defhtml stop-html []
	[:div#inner-container.login
		[:div.login-container
      [:button#submit-stop-game.lg-btn "Stop"]]])

(declare init-start-page!)

(defn init-stop-page!
  "Initialize the start game page."
  []
  (.html ($ "#main-container") (stop-html))

  (.click ($ "#submit-stop-game")
          #(do (.emit @socket "stop-game")
               (init-start-page!))))

;;------------------------------------------------------------
;; Start Game page
;;------------------------------------------------------------

(hiccups/defhtml start-html []
	[:div#inner-container.login
		[:div.login-container
			[:button#submit-start-lines.lg-btn "Start - 40 lines"]
      [:button#submit-start-time.lg-btn "Start - 5 minutes"]]])

(defn init-start-page!
  "Initialize the start game page."
  []
  (.html ($ "#main-container") (start-html))

  (.click ($ "#submit-start-time")
          #(do (.emit @socket "start-time")
               (init-stop-page!))))

;;------------------------------------------------------------
;; Password page
;;------------------------------------------------------------

(hiccups/defhtml password-html []
	[:div#inner-container.login
		[:div.login-container
			[:label "MC password:"]
			[:input#password.login-name {:type "password"}]
			[:button#submit-pass.lg-btn "OK"]]])

(defn on-grant-mc
  "Callback for handling the MC access grant."
  [str-data]
  (if-let [game-running (read-string str-data)]
     (init-stop-page!)
     (init-start-page!)))

(defn init-password-page!
  "Initialize the password page."
  []
  (.html ($ "#main-container") (password-html))

  ; Request access as MC when user submits password.
  (.click ($ "#submit-pass")
          #(.emit @socket "request-mc"
                  (.val ($ "#password"))))

  ; Render either the stop page or the start page
  ; when access as MC is granted.
  (.on @socket "grant-mc" on-grant-mc))

;;------------------------------------------------------------
;; Main page intializer.
;;------------------------------------------------------------

(defn init
  []
  (init-password-page!)
  )

(defn cleanup
  []

  ; Leave the MC role.
  (.emit @socket "leave-mc")

  ; Destroy socket listeners.
  (.removeListener @socket "grant-mc" on-grant-mc)

  )<commit_msg>style MC page and allow pressing enter on password form<commit_after>(ns client.mc
	(:require-macros [hiccups.core :as hiccups])
  (:require
    [cljs.reader :refer [read-string]]
    [client.socket :refer [socket]]
		hiccups.runtime))

(def $ js/$)

;;------------------------------------------------------------
;; Stop Game page
;;------------------------------------------------------------

(hiccups/defhtml stop-html []
  [:div#inner-container
    [:div.login-5983e
      [:form
        [:button#submit.red-btn-2c9ab "STOP"]]]])

(declare init-start-page!)

(defn init-stop-page!
  "Initialize the start game page."
  []
  (.html ($ "#main-container") (stop-html))

  (.click ($ "#submit")
          #(do (.emit @socket "stop-game")
               (init-start-page!))))

;;------------------------------------------------------------
;; Start Game page
;;------------------------------------------------------------

(hiccups/defhtml start-html []
  [:div#inner-container
    [:div.login-5983e
      [:form
        [:button#submit.green-btn-f67eb "START"]]]])

(defn init-start-page!
  "Initialize the start game page."
  []
  (.html ($ "#main-container") (start-html))

  (.click ($ "#submit")
          #(do (.emit @socket "start-time")
               (init-stop-page!))))

;;------------------------------------------------------------
;; Password page
;;------------------------------------------------------------

(hiccups/defhtml password-html []
  [:div#inner-container
    [:div.login-5983e
      [:form
        [:div.input-4a3e3
          [:label.label-66a3b "MC password:"]
          [:input#password.input-48f1f {:type "password"}]]
        [:button#submit.red-btn-2c9ab "OK"]]]])

(defn on-grant-mc
  "Callback for handling the MC access grant."
  [str-data]
  (if-let [game-running (read-string str-data)]
     (init-stop-page!)
     (init-start-page!)))

(defn init-password-page!
  "Initialize the password page."
  []
  (.html ($ "#main-container") (password-html))

  ; Request access as MC when user submits password.
  (.click ($ "#submit")
          #(.emit @socket "request-mc"
                  (.val ($ "#password"))))

  ; Allow pressing enter to submit.
  (.keyup ($ "#password")
          #(if (= (.-keyCode %) 13)
             (.click ($ "submit"))))

  ; Render either the stop page or the start page
  ; when access as MC is granted.
  (.on @socket "grant-mc" on-grant-mc))

;;------------------------------------------------------------
;; Main page intializer.
;;------------------------------------------------------------

(defn init
  []
  (client.core/set-bw-background!)

  (init-password-page!)
  )

(defn cleanup
  []

  ; Leave the MC role.
  (.emit @socket "leave-mc")

  ; Destroy socket listeners.
  (.removeListener @socket "grant-mc" on-grant-mc)

  )
{'fraction_non_alphanumeric': 0.33135985198889917, 'fraction_numerical': 0.0059204440333024974, 'mean_word_length': 1.5368371656499296, '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': '1956187', 'n_tokens_mistral': 1673, 'n_tokens_neox': 1579, 'n_words': 362}