Skip to content

Commit

Permalink
[auth] Prioritize issuer match in search result
Browse files Browse the repository at this point in the history
  • Loading branch information
ua741 committed Apr 8, 2024
1 parent 510a4a5 commit c728b3b
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions auth/lib/ui/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,22 @@ class _HomePageState extends State<HomePage> {
void _applyFilteringAndRefresh() {
if (_searchText.isNotEmpty && _showSearchBox) {
final String val = _searchText.toLowerCase();
_filteredCodes = _codes
.where(
(element) => (element.account.toLowerCase().contains(val) ||
element.issuer.toLowerCase().contains(val)),
)
.toList();
// Prioritize issuer match above account for better UX while searching
// for a specific TOTP for email providers. Searching for "emailProvider" like (gmail, proton) should
// show the email provider first instead of other accounts where protonmail
// is the account name.
final List<Code> issuerMatch = [];
final List<Code> accountMatch = [];

for (final Code code in _codes) {
if (code.issuer.toLowerCase().contains(val)) {
issuerMatch.add(code);
} else if (code.account.toLowerCase().contains(val)) {
accountMatch.add(code);
}
}
_filteredCodes = issuerMatch;
_filteredCodes.addAll(accountMatch);
} else {
_filteredCodes = _codes;
}
Expand Down

0 comments on commit c728b3b

Please sign in to comment.