~bendersteed/wikisophy-fe

e0fb9690aef7b6d76b951e368de4e286af6b4ace — Dimakakos Dimos 3 years ago eec0c30
Clean: some structuring of core app
1 files changed, 20 insertions(+), 14 deletions(-)

M src/wikisophy/core.cljs
M src/wikisophy/core.cljs => src/wikisophy/core.cljs +20 -14
@@ 3,10 3,26 @@
              [ajax.core :refer [GET POST]]
              [oz.core :as oz]))

;; -------------------------
;; State and State updates

(defonce path (r/atom []))

(defn response-handler [response] ;; this functionality will be implemented to backend
  (map-indexed (fn [i v] {:id (inc i)
                          :value (clojure.string/replace v "_" " ")
                          :parent (if (= i 0) nil i)})
               response))

(defn get-query! [query]
  (GET "http://localhost:4242/wikisophy"
       {:content-type :json
        :api (js/XMLHttpRequest.)
        :url-params {:query query}
        :handler #(reset! path (response-handler %))}))

;; -------------------------
;; Views
;; Components

(defn navbar []
  [:nav


@@ 24,19 40,6 @@
   [:h3 "Do all paths lead to "
    [:a {:href "https://wikipedia.org/wiki/Philosophy"} "Philosophy"] "?"]])

(defn response-handler [response] ;; this functionality will be implemented to backend
  (map-indexed (fn [i v] {:id (inc i)
                          :value (clojure.string/replace v "_" " ")
                          :parent (if (= i 0) nil i)})
               response))

(defn get-query! [query]
  (GET "http://localhost:4242/wikisophy"
       {:content-type :json
        :api (js/XMLHttpRequest.)
        :url-params {:query query}
        :handler #(reset! path (response-handler %))}))

(defn input []
  (let [query (r/atom "")]
    (fn []


@@ 126,6 129,9 @@
      [:div
       [oz/vega (path-tree @path)]])))

;; -------------------------
;; Pages

(defn front-page []
  [:body [navbar]
   [header]