Skip to content

Instantly share code, notes, and snippets.

@rlander
Created February 11, 2020 15:07
Show Gist options
  • Save rlander/a02a2e417a4f81d482e43d12a663efdd to your computer and use it in GitHub Desktop.
Save rlander/a02a2e417a4f81d482e43d12a663efdd to your computer and use it in GitHub Desktop.
Hoplon Forex
(page "index.html"
(:require [ajax.core :refer [GET POST]]))
(def url "http://127.0.0.1:4567/currencies")
(def currencies (cell []))
(def from (cell "USD"))
(def to (cell "USD"))
(def result (cell nil))
(GET url
{:keywords? true
:response-format :json
:handler (fn [res]
(->> res
:currencies
(swap! currencies concat)))})
(defn convert
[from to]
(GET (str "http://127.0.0.1:4567/" from "/to/" to)
{:keywords? true
:response-format :json
:handler #(reset! result %)}))
(defn get-options
[currencies]
(map #(option :value % %) currencies))
(html
(head
(link :href "app.css" :rel "stylesheet" :type "text/css"))
(body
(h1 "Hoplon Forex")
(div
(select
:change #(reset! from @%)
:style "margin: 20px"
(cell= (get-options currencies)))
(select
:change #(reset! to @%)
:style "margin: 20px"
(cell= (get-options currencies)))
(button "Convert"
:click #(convert @from @to))
(p "Result"
(cell= result)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment