Now generating the right URI for fetch-local-data
This commit is contained in:
parent
90a8dd5d6a
commit
bccf53cedd
|
@ -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*)))))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -140,20 +140,24 @@
|
||||||
(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
|
|
||||||
{:http-xhrio {:method :get
|
|
||||||
:uri (str source-host
|
|
||||||
"rest/get-local-data?latitude="
|
"rest/get-local-data?latitude="
|
||||||
(:latitude db)
|
(:latitude db)
|
||||||
"&longitude="
|
"&longitude="
|
||||||
(:longitude db))
|
(or (:longitude db) -4))]
|
||||||
|
(js/console.log
|
||||||
|
(str
|
||||||
|
"Fetching locality data: " uri))
|
||||||
|
;; we return a map of (side) effects
|
||||||
|
{:http-xhrio {:method :get
|
||||||
|
:uri uri
|
||||||
:format (json-request-format)
|
:format (json-request-format)
|
||||||
:response-format (json-response-format {:keywords? true})
|
:response-format (json-response-format {:keywords? true})
|
||||||
:on-success [:process-locality]
|
:on-success [:process-locality]
|
||||||
:on-failure [:bad-locality]}
|
:on-failure [:bad-locality]}
|
||||||
:db (add-to-feedback db :fetch-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
|
||||||
|
|
|
@ -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))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue