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
;; instead
(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)))]
(log/debug "Using '" *app-context* "' as *app-context*")
(handler (assoc request :servlet-context *app-context*)))))

View file

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

View file

@ -140,20 +140,24 @@
(reg-event-fx
:fetch-locality
(fn [{db :db} _]
(js/console.log "Fetching locality data")
;; we return a map of (side) effects
{:http-xhrio {:method :get
:uri (str source-host
(let [uri (str source-host
"rest/get-local-data?latitude="
(:latitude db)
"&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)
:response-format (json-response-format {:keywords? true})
:on-success [:process-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
:get-current-location

View file

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