Now generating the right URI for fetch-local-data

This commit is contained in:
Simon Brooke 2018-07-22 18:10:34 +01:00
parent 90a8dd5d6a
commit bccf53cedd
4 changed files with 25 additions and 20 deletions

View file

@ -27,9 +27,8 @@
;; we check if one has been specified in the environment ;; we check if one has been specified in the environment
;; instead ;; instead
(do (do
(log/info "Taking '" (:app-context env) "' as *app-context* from env") (log/debug "Taking '" (:app-context env) "' as *app-context* from env")
(:app-context env)))] (:app-context env)))]
(log/debug "Using '" *app-context* "' as *app-context*")
(handler (assoc request :servlet-context *app-context*))))) (handler (assoc request :servlet-context *app-context*)))))

View file

@ -2,6 +2,7 @@
:author "Simon Brooke"} youyesyet.routes.rest :author "Simon Brooke"} youyesyet.routes.rest
(:require [clojure.core.memoize :as memo] (:require [clojure.core.memoize :as memo]
[clojure.java.io :as io] [clojure.java.io :as io]
[clojure.tools.logging :as log]
[clojure.walk :refer [keywordize-keys]] [clojure.walk :refer [keywordize-keys]]
[compojure.core :refer [defroutes GET POST]] [compojure.core :refer [defroutes GET POST]]
[noir.response :as nresponse] [noir.response :as nresponse]
@ -43,6 +44,7 @@
work. So cache for only 90 seconds." work. So cache for only 90 seconds."
(memo/ttl (memo/ttl
(fn [here] (fn [here]
(log/debug "Fetching local data for " here)
(let [neighbourhood (l/neighbouring-localities here) (let [neighbourhood (l/neighbouring-localities here)
addresses (flatten addresses (flatten
(map (map

View file

@ -138,22 +138,26 @@
(reg-event-fx (reg-event-fx
:fetch-locality :fetch-locality
(fn [{db :db} _] (fn [{db :db} _]
(js/console.log "Fetching locality data") (let [uri (str source-host
;; we return a map of (side) effects "rest/get-local-data?latitude="
{:http-xhrio {:method :get (:latitude db)
:uri (str source-host "&longitude="
"rest/get-local-data?latitude=" (or (:longitude db) -4))]
(:latitude db) (js/console.log
"&longitude=" (str
(:longitude db)) "Fetching locality data: " uri))
:format (json-request-format) ;; we return a map of (side) effects
:response-format (json-response-format {:keywords? true}) {:http-xhrio {:method :get
:on-success [:process-locality] :uri uri
:on-failure [:bad-locality]} :format (json-request-format)
:db (add-to-feedback db :fetch-locality)})) :response-format (json-response-format {:keywords? true})
:on-success [:process-locality]
:on-failure [:bad-locality]}
:db (add-to-feedback db :fetch-locality)})))
;; http://localhost:3000/rest/get-local-data?latitude=54.85131525968606&longitude=
(reg-event-db (reg-event-db
:get-current-location :get-current-location

View file

@ -84,9 +84,9 @@
(.on view "moveend" (.on view "moveend"
(fn [_] (let [c (.getCenter view)] (fn [_] (let [c (.getCenter view)]
(js/console.log (str "Moving centre to " c)) (js/console.log (str "Moving centre to " c))
(dispatch :set-latitude (.-lat c)) (dispatch-sync [:set-latitude (.-lat c)])
(dispatch :set-longitude (.-lon c)) (dispatch-sync [:set-longitude (.-lng c)])
(dispatch :fetch-locality)))) (dispatch [:fetch-locality]))))
(refresh-map-pins) (refresh-map-pins)
view)) view))