Skip to content

Commit

Permalink
fixup move permalink update to history fn.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Jan 18, 2019
1 parent 9a79ba3 commit 99265ec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .cypress/cypress/integration/around_filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('Around page filtering and push state', function() {
cy.wait('@update-results');
cy.contains('1 to 6 of 6');
cy.contains('Street light not working');
cy.url().should('include', 'status=closed%2Cfixed');
cy.url().should('include', 'status=closed,fixed');
cy.get('#status_2').should('be.checked');
cy.go('back');
cy.wait('@update-results');
Expand Down
27 changes: 15 additions & 12 deletions web/js/map-OpenLayers.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,12 +428,6 @@ $.extend(fixmystreet.utils, {
function categories_or_status_changed() {
// If the category or status has changed we need to re-fetch map markers
fixmystreet.markers.refresh({force: true});

// Ensure the permalink control is updated when the filters change
var permalink_controls = fixmystreet.map.getControlsByClass(/Permalink/);
if (permalink_controls.length) {
permalink_controls[0].updateLink();
}
}

function replace_query_parameter(qs, id, key) {
Expand Down Expand Up @@ -472,6 +466,17 @@ $.extend(fixmystreet.utils, {
return new_url;
}

function update_history(qs, data) {
var new_url = update_url(qs);
history.pushState(data, null, new_url);

// Ensure the permalink control is updated when the filters change
var permalink_controls = fixmystreet.map.getControlsByClass(/Permalink/);
if (permalink_controls.length) {
permalink_controls[0].updateLink();
}
}

function page_changed_history() {
if (!('pushState' in history)) {
return;
Expand All @@ -486,10 +491,9 @@ $.extend(fixmystreet.utils, {
} else {
delete qs.p;
}
var new_url = update_url(qs);
history.pushState({
update_history(new_url, {
page_change: { 'page': page, 'show_old_reports': show_old_reports }
}, null, new_url);
});
}

function categories_or_status_changed_history() {
Expand All @@ -502,10 +506,9 @@ $.extend(fixmystreet.utils, {
var sort_key = replace_query_parameter(qs, 'sort', 'sort');
var show_old_reports = replace_query_parameter(qs, 'show_old_reports', 'show_old_reports');
delete qs.p;
var new_url = update_url(qs);
history.pushState({
update_history(qs, {
filter_change: { 'filter_categories': filter_categories, 'statuses': filter_statuses, 'sort': sort_key, 'show_old_reports': show_old_reports }
}, null, new_url);
});
}

function setup_inspector_marker_drag() {
Expand Down

0 comments on commit 99265ec

Please sign in to comment.