From 59dfc7067b772655e2c2aebe4a96b694ef1cd4da Mon Sep 17 00:00:00 2001 From: bendersteed Date: Thu, 13 Feb 2020 12:24:26 +0200 Subject: [PATCH] Add: skeleton of basic functionality --- src/wikisophy/core.cljs | 47 ++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/src/wikisophy/core.cljs b/src/wikisophy/core.cljs index 4266212..582fd8a 100644 --- a/src/wikisophy/core.cljs +++ b/src/wikisophy/core.cljs @@ -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)) + -- 2.45.2