1import { Controller } from "@hotwired/stimulus" 2 3// Connects to data-controller="place-id-verify" 4export default class extends Controller { 5 static targets = ["input", "result"] 6 static values = { url: String } 7 8 get _placeIdField() { 9 return document.querySelector('input[name="club[google_place_id]"]') 10 } 11 12 async verify(event) { 13 event.preventDefault() 14 const url = this.inputTarget.value.trim() 15 if (!url) { 16 this._render("err", "Pegá primero una URL de Google Maps.") 17 return 18 } 19 20 this._render("loading", "Verificandoâ¦") 21 22 try { 23 const csrf = document.querySelector("meta[name=csrf-token]")?.content 24 const response = await fetch(this.urlValue, { 25 method: "POST", 26 headers: { 27 "Content-Type": "application/json", 28 "Accept": "application/json", 29 "X-CSRF-Token": csrf || "" 30 }, 31 body: JSON.stringify({ url }) 32 }) 33 const data = await response.json() 34 if (response.ok && data.ok) { 35 const field = this._placeIdField 36 if (field) field.value = data.place_id 37 this._render("ok", `Listing encontrado â se va a vincular al guardar: ${data.place_id}`) 38 } else { 39 this._render("err", data.error || "No pude resolver el link.") 40 } 41 } catch (e) { 42 this._render("err", "Error de red. Intentá de nuevo.") 43 } 44 } 45 46 _render(kind, message) { 47 const color = { ok: "text-emerald-600", err: "text-red-600", loading: "text-gray-500" }[kind] 48 const icon = { ok: "â", err: "â", loading: "â¦" }[kind] 49 this.resultTarget.innerHTML = `<p class="text-[11px] ${color} mt-1">${icon} ${message}</p>` 50 } 51}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.