]> git.openstreetmap.org Git - rails.git/commitdiff
Remove params from url when viewing place history and map is moved
authorAnton Khorev <tony29@yandex.ru>
Mon, 17 Mar 2025 00:21:46 +0000 (03:21 +0300)
committerAnton Khorev <tony29@yandex.ru>
Sun, 23 Mar 2025 19:14:23 +0000 (22:14 +0300)
app/assets/javascripts/index/history.js
test/system/history_test.rb

index 235f11ba111985cdc72cfee89ad5a337f84a6128..9f883367a799393be5cc2d2b3a20dfbda48271e7 100644 (file)
@@ -189,6 +189,11 @@ OSM.History = function (map) {
     });
   }
 
+  function reloadChangesetsBecauseOfMapMovement() {
+    OSM.router.replace("/history" + window.location.hash);
+    loadFirstChangesets();
+  }
+
   let changesets = [];
 
   function updateBounds() {
@@ -250,7 +255,7 @@ OSM.History = function (map) {
     map.addLayer(group);
 
     if (location.pathname === "/history") {
-      map.on("moveend", loadFirstChangesets);
+      map.on("moveend", reloadChangesetsBecauseOfMapMovement);
     }
 
     map.on("zoomend", updateBounds);
@@ -260,7 +265,7 @@ OSM.History = function (map) {
 
   page.unload = function () {
     map.removeLayer(group);
-    map.off("moveend", loadFirstChangesets);
+    map.off("moveend", reloadChangesetsBecauseOfMapMovement);
     map.off("zoomend", updateBounds);
     disableChangesetIntersectionObserver();
   };
index 7d730355a083c9b327cd6452b3dd4aca96f216e8..be7700c3b893699f229feab865c56853f589eb84 100644 (file)
@@ -109,6 +109,30 @@ class HistoryTest < ApplicationSystemTestCase
     end
   end
 
+  test "update sidebar when before param is included and map is moved" do
+    changeset1 = create(:changeset, :num_changes => 1, :min_lat => 50000000, :max_lat => 50000001, :min_lon => 50000000, :max_lon => 50000001)
+    create(:changeset_tag, :changeset => changeset1, :k => "comment", :v => "changeset-at-fives")
+    changeset2 = create(:changeset, :num_changes => 1, :min_lat => 50100000, :max_lat => 50100001, :min_lon => 50100000, :max_lon => 50100001)
+    create(:changeset_tag, :changeset => changeset2, :k => "comment", :v => "changeset-close-to-fives")
+    changeset3 = create(:changeset)
+
+    visit "/history?before=#{changeset3.id}#map=17/5/5"
+
+    within_sidebar do
+      assert_link "changeset-at-fives"
+      assert_no_link "changeset-close-to-fives"
+    end
+
+    find("#map [aria-label='Zoom Out']").click(:shift)
+
+    within_sidebar do
+      assert_link "changeset-at-fives"
+      assert_link "changeset-close-to-fives"
+    end
+
+    assert_current_path history_path
+  end
+
   private
 
   def create_visible_changeset(user, comment)