Created
February 11, 2020 15:07
-
-
Save rlander/a02a2e417a4f81d482e43d12a663efdd to your computer and use it in GitHub Desktop.
Hoplon Forex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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