diff --git a/app/javascript/components/MapEditor/hooks.ts b/app/javascript/components/MapEditor/hooks.ts index d292d5e1b..a20391c96 100644 --- a/app/javascript/components/MapEditor/hooks.ts +++ b/app/javascript/components/MapEditor/hooks.ts @@ -38,7 +38,7 @@ export function useFeatureCollection( features: callback(features) })); httpRequest(url) - .js() + .turbo() .catch(() => null); }, [url, setFeatureCollection] diff --git a/app/views/champs/carte/index.js.erb b/app/views/champs/carte/index.js.erb deleted file mode 100644 index 1cd381cd7..000000000 --- a/app/views/champs/carte/index.js.erb +++ /dev/null @@ -1,9 +0,0 @@ -<%= render_flash(timeout: 5000, fixed: true) %> - -<%= render_to_element("##{@champ.input_group_id} .geo-areas", - partial: 'shared/champs/carte/geo_areas', - locals: { champ: @champ, editing: true }) %> - -<% if @focus %> - <%= fire_event('map:feature:focus', { bbox: @champ.bounding_box }.to_json) %> -<% end %> diff --git a/app/views/champs/carte/index.turbo_stream.haml b/app/views/champs/carte/index.turbo_stream.haml new file mode 100644 index 000000000..e5e4080a4 --- /dev/null +++ b/app/views/champs/carte/index.turbo_stream.haml @@ -0,0 +1,4 @@ += turbo_stream.update dom_id(@champ, :geo_areas), partial: 'shared/champs/carte/geo_areas', locals: { champ: @champ, editing: true } + +- if @focus + = turbo_stream.dispatch 'map:feature:focus', bbox: @champ.bounding_box diff --git a/app/views/shared/dossiers/editable_champs/_carte.html.haml b/app/views/shared/dossiers/editable_champs/_carte.html.haml index 41fa07ac7..6677e6dc4 100644 --- a/app/views/shared/dossiers/editable_champs/_carte.html.haml +++ b/app/views/shared/dossiers/editable_champs/_carte.html.haml @@ -1,4 +1,4 @@ = react_component("MapEditor", featureCollection: champ.to_feature_collection, url: champs_carte_features_path(champ), options: champ.render_options) -.geo-areas +.geo-areas{ id: dom_id(champ, :geo_areas) } = render partial: 'shared/champs/carte/geo_areas', locals: { champ: champ, editing: true } diff --git a/spec/controllers/champs/carte_controller_spec.rb b/spec/controllers/champs/carte_controller_spec.rb index 621f8f4f8..99bf6a74e 100644 --- a/spec/controllers/champs/carte_controller_spec.rb +++ b/spec/controllers/champs/carte_controller_spec.rb @@ -117,7 +117,7 @@ describe Champs::CarteController, type: :controller do render_views before do - get :index, params: params, format: :js, xhr: true + get :index, params: params, format: :turbo_stream end context 'without focus' do @@ -126,7 +126,7 @@ describe Champs::CarteController, type: :controller do end it 'updates the list' do - expect(response.body).not_to include("DS.fire('map:feature:focus'") + expect(response.body).not_to include("map:feature:focus") expect(response.status).to eq 200 end end @@ -140,7 +140,8 @@ describe Champs::CarteController, type: :controller do end it 'updates the list and focuses the map' do - expect(response.body).to include("DS.fire('map:feature:focus'") + expect(response.body).to include(ActionView::RecordIdentifier.dom_id(champ, :geo_areas)) + expect(response.body).to include("map:feature:focus") expect(response.status).to eq 200 end end