a6d22b4424221dc09f30119b1e30d2a92e78a939 — Filip Miletic 11 months ago 1a582dd
Registering all the marks and inserting them in db.board
M resources/public/css/board.css => resources/public/css/board.css +5 -3
@@ 58,6 58,11 @@ td {
     background-color: #00F;
 }
 
+.mark {
+    background-color: #ffd6cc;
+}
+
+
 .mark .turn {
     font-size: 100%;
 }


@@ 71,6 76,3 @@ td {
     background-color: #fffcd6;
 }
 
-.mark {
-    background.color: #ffd6fc;
-}

M src/cljs/qttt/db.cljs => src/cljs/qttt/db.cljs +1 -1
@@ 5,7 5,7 @@
           :version "0.0.1"}
    
    :board {
-           
+
 
 
            }

A src/cljs/qttt/events/board.cljs => src/cljs/qttt/events/board.cljs +16 -0
@@ 0,0 1,16 @@
+(ns qttt.events.board
+  (:require [re-frame.core :as re-frame]))
+
+(defn- valid-cell? [db cell subcell]
+  (let [meta (get-in db [:board cell subcell])]
+    (if (:toggle meta)
+      false
+      true)))
+
+(re-frame/reg-event-db
+ :toggle-cell
+ (fn [db [_ cell subcell]]
+   (if (valid-cell? db cell subcell)
+     (assoc-in db [:board cell subcell] {:toggle true})
+     db)))
+

A src/cljs/qttt/subs/board.cljs => src/cljs/qttt/subs/board.cljs +8 -0
@@ 0,0 1,8 @@
+(ns qttt.subs.board
+  (:require [re-frame.core :as re-frame]))
+
+(re-frame/reg-sub
+ :cell-meta
+ (fn [db [_ cell subcell]]
+   (get-in db [:board cell subcell])))
+

M src/cljs/qttt/views/board.cljs => src/cljs/qttt/views/board.cljs +16 -15
@@ 1,9 1,11 @@
-(ns qttt.views.board)
+(ns qttt.views.board
+  (:require [qttt.events.board :as board]
+            [qttt.subs.board :as subs]
+            [re-frame.core :as re-frame]
+            ))
 ;; Much more elegant than creating multiple functions to work with every type
 ;; of fields and cells. Superposition are big ones, and subcells are classical.
 
-
-
 (defmulti create-cell :type)
 
 (defn create-cells [class parent cells]


@@ 12,13 14,13 @@
      ^{:key cell}
      [create-cell {:type class :parent parent :cell cell}])])
 
-(defmethod create-cell :classical [cell]
-  [:td [:span (cell :cell)]])
-
-(defn generate-cells [type index]
+(defn generate-cells [type parent]
   (for [cells (partition 3 (range 9))]
     ^{:key (str cells)}
-    [create-cells type index cells]))
+    [create-cells type parent cells]))
+
+(defmethod create-cell :classical [cell]
+  [:td [:span (cell :cell)]])
 
 (defmethod create-cell :superposition [{:keys [parent cell]}]
   [:td.superposition


@@ 27,14 29,13 @@
      (generate-cells :open cell)]]])
 
 (defmethod create-cell :open [{:keys [parent cell]}]
-  [:td.open {:on-click #(println "Main cell" parent ":: subcell" cell)}
-   [:span parent "-"cell]])
+  (let [data (re-frame/subscribe [:cell-meta parent cell])]
+    [:td {:on-click #(re-frame/dispatch [:toggle-cell parent cell])
+          :class (if (:toggle @data) "mark" "open")}
+     [:span]])
+  )
 
 (defn board []
   [:table.board
    [:tbody
-    (generate-cells :superposition nil)
-    ;; (for [cells (partition 3 (range 9))]
-    ;;   ^{:key (str cells)}
-    ;;   [create-cells :superposition nil cells])
-    ]])
+    (generate-cells :superposition nil)]])