pidgin/nest

Initialize search fields from URL correctly.

2020-04-17, Elliott Sales de Andrade
69baef583f63
Parents f755fe8abdd0
Children 4001a8922417
Initialize search fields from URL correctly.

The `searchState` was updated, but not propagated to the UI elements, so
once the DOM load ran an update, all state would be reset to defaults.

Fixes NEST-26.
--- a/hugo/static/js/plugin-table.js Fri Mar 20 02:26:33 2020 +0000
+++ b/hugo/static/js/plugin-table.js Fri Apr 17 06:15:45 2020 -0400
@@ -58,9 +58,20 @@
};
});
- // Add click handler to All|Trusted|Community selector
- $("#publisher-selector").click(updateFilters);
+ // Set up publisher selector interface
+ var publisherSelectors = $("#publisher-selector");
+ var publisherChecked = $('input[id="' + searchState.publisher + '"]', publisherSelectors);
+ if (publisherChecked) {
+ publisherChecked.prop('checked', true);
+ } else {
+ searchState.publisher = "all";
+ $('input[id="all"]', publisherSelectors).prop('checked', true);
+ }
+ publisherSelectors.click(updateFilters);
+
+ // Set up search box interface
searchTextBox = document.querySelector("#plugin-filter-search");
+ searchTextBox.value = searchState.query;
searchTextBox.addEventListener(
"input",
// Wait half a second
@@ -71,6 +82,9 @@
Array.from(
document.querySelectorAll("#plugin-selector>label>input")
).forEach(function(elem) {
+ if (searchState.type.has(elem.dataset.type)) {
+ elem.checked = true;
+ }
elem.addEventListener("click", pluginTypeSelectorClickEvent);
});