···1212## Page-by-Page Plan
13131414### `internal/templates/home.html`
1515-- Current state: no custom interaction JS.
1616-- Plan: optional future HTMX ZIP lookup preview, otherwise keep as-is.
1717-- Priority: low.
1515+- Debated using htmx for location lookup of zip (see commit 8037997) but sicne it didn't do anything online and geolocation needs js anyways inline javascript was simpler.
18161917### `internal/templates/locations.html`
2018- Current state: migrated
+4-14
internal/locations/locations.go
···293293294294func (l *locationServer) Register(mux *http.ServeMux, authClient auth.AuthClient) {
295295 mux.HandleFunc("GET /locations/zip-from-coordinates", func(w http.ResponseWriter, r *http.Request) {
296296- isHXRequest := r.Header.Get("HX-Request") == "true"
297297- if !isHXRequest {
298298- http.Error(w, "htmx request required", http.StatusBadRequest)
299299- return
300300- }
301301-302296 lat, err := strconv.ParseFloat(r.URL.Query().Get("lat"), 64)
303297 if err != nil {
304304- w.Header().Set("Content-Type", "text/plain; charset=utf-8")
305305- _, _ = w.Write([]byte("Try again, chef. We could not read your location."))
298298+ http.Error(w, "invalid latitude", http.StatusBadRequest)
306299 return
307300 }
308301 lon, err := strconv.ParseFloat(r.URL.Query().Get("lon"), 64)
309302 if err != nil {
310310- w.Header().Set("Content-Type", "text/plain; charset=utf-8")
311311- _, _ = w.Write([]byte("Try again, chef. We could not read your location."))
303303+ http.Error(w, "invalid longitude", http.StatusBadRequest)
312304 return
313305 }
314306315307 zip, ok := l.zipFetcher.NearestZIPToCoordinates(lat, lon)
316308 if !ok {
317317- w.Header().Set("Content-Type", "text/plain; charset=utf-8")
318318- _, _ = w.Write([]byte("Try again, chef. We could not find your ZIP code."))
309309+ http.Error(w, "zip not found for coordinates", http.StatusNotFound)
319310 return
320311 }
321312322322- w.Header().Set("HX-Redirect", "/locations?zip="+url.QueryEscape(zip))
323323- w.WriteHeader(http.StatusNoContent)
313313+ http.Redirect(w, r, "/locations?zip="+url.QueryEscape(zip), http.StatusFound)
324314 })
325315326316 mux.HandleFunc("GET /locations", func(w http.ResponseWriter, r *http.Request) {