Skip to content

Commit

Permalink
Preserve integration category filter on noop keyup
Browse files Browse the repository at this point in the history
  • Loading branch information
bkrausz committed Jan 10, 2025
1 parent cb06f83 commit b3dfc05
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions source/integrations/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
{%- assign category_name = cat -%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- endif -%}
{%- assign components_count = components_count | plus: 1 -%}
{%- endif -%}
{%- endfor -%}
Expand Down Expand Up @@ -98,7 +98,7 @@
{%- assign category_name = cat -%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- endif -%}
{%- assign components_count = components_count | plus: 1 -%}
{%- endif -%}
{%- endfor -%}
Expand Down Expand Up @@ -208,7 +208,7 @@
if (hash.indexOf(SEARCH_PREFIX) === 0) {
// search through title and category
search = decodeURIComponent(hash).substring(SEARCH_PREFIX.length).toLowerCase();
filter = comp =>
filter = comp =>
comp.search.indexOf(search) !== -1 ||
comp.cat.find((c) => c.includes("#")) != undefined;

Expand Down Expand Up @@ -309,17 +309,19 @@
};

// update view by search text
let lastSearchText = '';
searchInputEl.addEventListener('keyup', debounce(() => {
const text = searchInputEl.value
// sanitize input
.replace(/[(\?|\&\{\}\(\))]/gi, '')
.trim();

let newHash = typeof text === "string" && text.length >= 1
? SEARCH_PREFIX + text
: '#all';
// Only apply filter if hash has changed
if (newHash !== window.location.hash) {

// Only apply filter if value has changed
if (lastSearchText !== text) {
lastSearchText = text;
const newHash = typeof text === "string" && text.length >= 1
? SEARCH_PREFIX + text
: '#all';
history.pushState('', '', newHash);
applyFilter();
}
Expand Down

0 comments on commit b3dfc05

Please sign in to comment.