From 6062bb97bb1c0c78e9623d40c81dc5f13eaad59e Mon Sep 17 00:00:00 2001 From: Marwin Hochfelsner <50826859+hlfan@users.noreply.github.com> Date: Wed, 23 Jul 2025 07:53:13 +0200 Subject: [PATCH] Reuse search results fetcher --- app/assets/javascripts/index/search.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/index/search.js b/app/assets/javascripts/index/search.js index bc2007439..4f5bd8a64 100644 --- a/app/assets/javascripts/index/search.js +++ b/app/assets/javascripts/index/search.js @@ -48,12 +48,18 @@ OSM.Search = function (map) { $(this).hide(); div.find(".loader").prop("hidden", false); - fetch($(this).attr("href"), { + fetchReplace(this, div); + } + + function fetchReplace({ href }, $target) { + return fetch(href, { method: "POST", body: new URLSearchParams(OSM.csrf) }) .then(response => response.text()) - .then(data => div.replaceWith(data)); + .then(html => { + $target.replaceWith(html); + }); } function showSearchResult() { @@ -113,13 +119,8 @@ OSM.Search = function (map) { page.load = function () { $(".search_results_entry").each(function (index) { const entry = $(this); - fetch(entry.data("href"), { - method: "POST", - body: new URLSearchParams(OSM.csrf) - }) - .then(response => response.text()) - .then(function (html) { - entry.html(html); + fetchReplace(this.dataset, entry.children().first()) + .then(() => { // go to first result of first geocoder if (index === 0) { const firstResult = entry.find("*[data-lat][data-lon]:first").first(); -- 2.39.5