M src/wikisophy/core.cljs => src/wikisophy/core.cljs +39 -8
@@ 1,21 1,52 @@
(ns wikisophy.core
- (:require
- [reagent.core :as r]))
+ (:require [reagent.core :as r]
+ [ajax.core :refer [GET POST]]))
+
+(def path (r/atom []))
;; -------------------------
;; Views
-(defn home-page []
- [:div [:h2 "Welcome to Reagent"]
- [:p "This was so fucking shitty, for real I hate this stuff."]
- [:p "Testing if figwheel still works..."]
- [:p "It does actually! Nice. Let's get to work then!"]])
+(defn header []
+ [:header
+ [:h1 "WIKISOPHY"]
+ [:h2 "Do all paths lead to "
+ [:a {:href "https://wikipedia.org/wiki/Philosophy"} "Philosophy"] "?"]])
+
+(defn get-query! [query]
+ (GET "http://localhost:4242/wikisophy"
+ {:content-type :json
+ :api (js/XMLHttpRequest.)
+ :url-params {:query query}
+ :handler #(reset! path %)}))
+
+(defn input []
+ (let [query (r/atom "Search wikipedia..")]
+ (fn []
+ [:div
+ [:p "The value is: " @query]
+ [:input {:type "text"
+ :value @query
+ :on-change #(reset! query (-> % .-target .-value))}]
+ [:input {:type "submit"
+ :on-click #(get-query! @query)}]])))
+
+(defn graph []
+ [:div
+ [:ol (for [node @path]
+ ^{:key node} [:li node])]])
+
+(defn front-page []
+ [:body [header]
+ [input]
+ [graph]])
;; -------------------------
;; Initialize app
(defn mount-root []
- (r/render [home-page] (.getElementById js/document "app")))
+ (r/render [front-page] (.getElementById js/document "app")))
(defn init! []
(mount-root))
+