Skip to content

Commit

Permalink
add ability to filter the container list
Browse files Browse the repository at this point in the history
  • Loading branch information
dannycolin committed Jul 21, 2022
1 parent 7dee05e commit 47062d2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/css/popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -2374,3 +2374,13 @@ tr:hover > td > .trash-button {
.overflow .panel.onboarding {
margin-block: auto;
}

/* Searchbar */
.searchbar {
margin-block: 4px -4px;
padding-inline: 16px;
}

.searchbar input {
inline-size: 100%;
}
19 changes: 18 additions & 1 deletion src/js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ async function getExtensionInfo() {
return extensionInfo;
}


// This object controls all the panels, identities and many other things.
const Logic = {
_identities: [],
Expand Down Expand Up @@ -465,6 +464,23 @@ const Logic = {
default:
break;
}
},

filterContainerList() {
const pattern = /^\s+|\s+$/g;
const list = Array.from(document.querySelectorAll("#identities-list tr"));
const search = document.querySelector("#search-terms").value.replace(pattern, "").toLowerCase();

for (const i in list) {
const text = list[i].querySelector("td div span");

if (text.innerText.replace(pattern, "").toLowerCase().includes(search) ||
!search) {
list[i].style.display = "block";
} else {
list[i].style.display = "none";
}
}
}
};

Expand Down Expand Up @@ -847,6 +863,7 @@ Logic.registerPanel(P_CONTAINERS_LIST, {

document.addEventListener("keydown", Logic.keyboardNavListener);
document.addEventListener("keydown", Logic.shortcutListener);
document.addEventListener("input", Logic.filterContainerList);

MozillaVPN.handleContainerList(identities);

Expand Down
12 changes: 12 additions & 0 deletions src/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,18 @@ <h4 class="moz-vpn-logotype vpn-status-container-list display-none">Mozilla VPN
</h4>
</div>
<div class="scrollable identities-list">
<div class="searchbar">
<label for="search-terms"
class="hide-label"
data-i18n-message-id="filterInputLabel">
</label>
<input type="text"
id="search-terms"
name="search-terms"
placeholder="Search container name"
data-i18n-attribute="placeholder"
data-i18n-attribute-message-id="filterInputPlaceholder">
</div>
<table class="menu" id="identities-list">
<tr class="menu-item hover-highlight">
<td>
Expand Down

0 comments on commit 47062d2

Please sign in to comment.