Skip to content

Commit

Permalink
Merge branch '162-bug-scopes-are-not-displayed-on-load' into 'main'
Browse files Browse the repository at this point in the history
Bug: Scopes are not displayed on load

See merge request decidim/decidim-module-geo!162
  • Loading branch information
Hadrien Froger committed Nov 4, 2024
2 parents 7e64045 + f9ed340 commit 94bbf34
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 24 deletions.
9 changes: 0 additions & 9 deletions app/packs/src/decidim/geo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ async function displayMap() {

const { map, pointsLayer } = configStore.getState();
const { selectedPoint, selectedScope } = geoStore.getState();
const { savedCenter } = memoryStore.getState();
pointsLayer.clearLayers();
if (
fetchesRunning === 0 &&
Expand All @@ -97,8 +96,6 @@ async function displayMap() {
animation: true
});
}


const pointInMap = getFilteredPoints().filter(
(node) => typeof node.isGeoLocated !== "undefined" && node.isGeoLocated()
);
Expand All @@ -118,12 +115,6 @@ async function displayMap() {
if(map.getBounds().contains(boundingBox)){
return;
}
// map.fitBounds(
// boundingBox,
// {
// padding: configStore.getState().isFullScreen ? [8, 8] : [16, 16]
// }
// );
}
}
);
Expand Down
7 changes: 3 additions & 4 deletions app/packs/src/decidim/geo/models/GeoScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ export default class GeoScope {
}

isEmpty(points = undefined) {

if (!points) points = pointStore.getState().points;
if (this.data.geom === null) return true;
if (!points) points = pointStore.getState().points;
const currentScopeId = this.id;
return !points.find(({ geoScopeId }) => `${geoScopeId}` === `${currentScopeId}`);
}
Expand Down Expand Up @@ -100,7 +99,7 @@ export default class GeoScope {
if(this.layer)
map.removeLayer(this.layer);
}
init(mapLayer) {
init(scopeLayer) {
this.markers_group = this.markersForScope();
const [itm, repaintItm] = scopeDropdownItem({
scopeId: this.id,
Expand All @@ -122,7 +121,7 @@ export default class GeoScope {
onClick: this.scopeClickHandler.bind(this)
});
this.layer.bringToBack();
mapLayer.addLayer(this.layer);
scopeLayer.addLayer(this.layer);

// Add the layer only when we are sure there is some point
// in the layer.
Expand Down
25 changes: 15 additions & 10 deletions app/packs/src/decidim/geo/stores/pointStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,22 @@ const store = createStore(
const { selectedGeoScopeIds, fetchedGeoScopes, points, scopes } = get();
scopes.forEach((scope) => scope.remove());
scopeLayer.clearLayers();
const geoScopes = selectedGeoScopeIds
let geoScopes = [];

if(fetchedGeoScopes.length > 0 && selectedGeoScopeIds.length > 0) {
geoScopes = selectedGeoScopeIds
.map((scopeId) => {
const match = fetchedGeoScopes.find(({ id }) => `${id}` === `${scopeId}`);
if (!match) return null;

const geoScope = new GeoScope({
geoScope: match
});
geoScope.init(scopeLayer);
return geoScope;
})
.filter(Boolean);
if (!match) return null;
const geoScope = new GeoScope({
geoScope: match
});
geoScope.init(scopeLayer);
return geoScope;
})
.filter(Boolean);

}
const responsePoints = filteredPoints
.map(({ id: needleId }) => {
return points.find(({ id }) => `${needleId}` === `${id}`);
Expand Down Expand Up @@ -131,6 +135,7 @@ const store = createStore(
.filter(({ value }) => typeof value.geoScopes !== "undefined")
.map(({ value: { geoScopes } }) => geoScopes);
set(() => ({ fetchedGeoScopes }));
get()._updateCache()
});
},

Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/decidim_geo_assign_geo_scopes_tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace :decidim_geo do
raise "Decidim gem is not installed" if decidim_path.nil?
raise "Decidim-Geo is not installed" unless Gem.loaded_specs.has_key?(gem_name)


Decidim::Geo::AutomaticScopeJob.perform_now
end


Expand Down

0 comments on commit 94bbf34

Please sign in to comment.