Skip to content

Commit

Permalink
Fix #1845 Search bar executes multiple API requests (#1846)
Browse files Browse the repository at this point in the history
* Fix #1845 Search bar executes multiple API requests

* fix catalog redirect
  • Loading branch information
allyoucanmap authored Sep 6, 2024
1 parent 1b10aaf commit ccf6811
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
3 changes: 3 additions & 0 deletions geonode_mapstore_client/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

{% block header %}
{% include './geonode-mapstore-client/snippets/header.html' %}
{% block gn_config %}
{% include './geonode-mapstore-client/_geonode_config.html' %}
{% endblock %}
{% endblock %}

{% block footer %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,39 @@
}

const newQueryHash = newParams.join('&');
const catalogPagePath = window.__GEONODE_CONFIG__.localConfig.geoNodeSettings.catalogPagePath;
const searchPath = '/catalogue/#/search';
const baseCatalogPath = catalogPagePath ? searchPath.replace('/catalogue/', catalogPagePath) : searchPath;

const pathname = splitHash[0].replace('#', '');
const gnCatalogueNode = document.getElementById('#gn-catalogue');
const catalogPagePath = window.__GEONODE_CONFIG__
&& window.__GEONODE_CONFIG__.localConfig
&& window.__GEONODE_CONFIG__.localConfig.geoNodeSettings
&& window.__GEONODE_CONFIG__.localConfig.geoNodeSettings.catalogPagePath;
const defaultCatalogPath = '/catalogue/';
const baseCatalogPath = catalogPagePath ? catalogPagePath : defaultCatalogPath;
const isCatalogPage = window.location.pathname === baseCatalogPath
{% block searchbar_search_href %}
location.href = baseCatalogPath + (newQueryHash ? '?' + newQueryHash : '');
if (queryHash !== newQueryHash) {
// if MapStoreAPI are available we are in the catalog
if (isCatalogPage && window.MapStoreAPI && window.MapStoreAPI.triggerAction) {
// the location change will modify the internal mapstore routing after the #
// without changing the browser path
window.MapStoreAPI.triggerAction({
type: '@@router/LOCATION_CHANGE',
payload: {
location: {
pathname: !!gnCatalogueNode ? pathname : '/',
search: '?' + newQueryHash,
hash: ''
},
action: 'PUSH',
isFirstRendering: false
}
})
} else {
// we need to redirect to catalog page
// if we are in a page different from catalog
location.href = baseCatalogPath + '#/' + (newQueryHash ? '?' + newQueryHash : '');
}
}
{% endblock %}

clearRequest();
Expand Down

0 comments on commit ccf6811

Please sign in to comment.