Commit a342a339 authored by Leon Tappe's avatar Leon Tappe 🔥
Browse files

improve user search

parent f060d6cd
...@@ -120,8 +120,12 @@ class UsersBloc extends Bloc<UsersEvent, UsersState> { ...@@ -120,8 +120,12 @@ class UsersBloc extends Bloc<UsersEvent, UsersState> {
}); });
on<FilterUsers>((FilterUsers event, Emitter<UsersState> emit) async { on<FilterUsers>((FilterUsers event, Emitter<UsersState> emit) async {
final f = event.username.toLowerCase(); final f = simple(event.query);
_filteredList = _users.where((User user) => user.name.contains(f)).toList(); _filteredList = _users
.where((User user) => simple(user.toMap.values.toString()).contains(f))
.toList()
..sort((User a, User b) => f == a.name ? -1 : 0);
emit(UsersState.result(_filteredList)); emit(UsersState.result(_filteredList));
}); });
...@@ -147,7 +151,7 @@ class UsersBloc extends Bloc<UsersEvent, UsersState> { ...@@ -147,7 +151,7 @@ class UsersBloc extends Bloc<UsersEvent, UsersState> {
void onFilter(String filter) => add(FilterAll(filter)); void onFilter(String filter) => add(FilterAll(filter));
void onFilterByUser(String username) => add(FilterUsers(username)); void onFilterByUser(String query) => add(FilterUsers(query));
void onGetCredit(int userId) => add(GetCredit(userId)); void onGetCredit(int userId) => add(GetCredit(userId));
......
...@@ -33,11 +33,11 @@ class FilterAll extends UsersEvent { ...@@ -33,11 +33,11 @@ class FilterAll extends UsersEvent {
} }
class FilterUsers extends UsersEvent { class FilterUsers extends UsersEvent {
final String username; final String query;
FilterUsers(this.username); FilterUsers(this.query);
Map<String, dynamic> get toMap => {'username': username}; Map<String, dynamic> get toMap => {'query': query};
@override @override
String toString() => '[FilterUsers $toMap]'; String toString() => '[FilterUsers $toMap]';
......
...@@ -8,3 +8,13 @@ String formatResponse(Response response) => ...@@ -8,3 +8,13 @@ String formatResponse(Response response) =>
Map<String, dynamic> removePassword(Map<String, dynamic> map) => Map<String, dynamic> removePassword(Map<String, dynamic> map) =>
map.map((key, value) => key != 'password' ? MapEntry(key, value) : MapEntry(key, 'password')); map.map((key, value) => key != 'password' ? MapEntry(key, value) : MapEntry(key, 'password'));
String simple(String input) => input
.toLowerCase()
.trim()
.replaceAll(' ', '')
.replaceAll(',', '.')
.replaceAll('ä', 'ae')
.replaceAll('ö', 'oe')
.replaceAll('ü', 'ue')
.replaceAll('ß', 'ss');
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment