Skip to content

Instantly share code, notes, and snippets.

@colonelrascals
Created August 28, 2018 21:58
Show Gist options
  • Save colonelrascals/2b957bf1eeff0397e37ddb2b6eedafaa to your computer and use it in GitHub Desktop.
Save colonelrascals/2b957bf1eeff0397e37ddb2b6eedafaa to your computer and use it in GitHub Desktop.
(defn- pos-volume
[num]
(if (pos? num) num 0))
(defn- click-volume-down-btn
"Turn it down you kids!"
[js-evt]
(let [new-volume (- js-evt 1)]
(swap! *app-state assoc :volume (pos-volume new-volume))))
;; TODO: write me
(defn- change-volume [js-evt]
(let [new-volume (int (aget js-evt "currentTarget" "value"))]
(swap! *app-state assoc :volume new-volume)))
(rum/defc TunerAndVolumeControls < rum/static
[volume]
[:div.row
[:div.box
[:label "Source:"]
[:div
[:button {:on-click (partial click-source-btn "AM")} "AM"]
[:button {:on-click (partial click-source-btn "FM")} "FM"]]]
[:div.box
[:label "Tune:"]
[:div
[:button {:on-click click-tune-up-btn} "▲"]
[:button {:on-click click-tune-down-btn} "▼"]]]
[:div.box
[:label "Volume:"]
[:div
;; TOOD: maybe we want buttons instead?
; [:button {:on-click click-volume-up-btn} "▲"]
[:button {:on-click (partial click-volume-down-btn volume)}"▼"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment