feat: server-side search with debounce for professionals list

- getProfessionals() now accepts optional search param sent to ?search=
- updateCity only triggers the initial load (city no longer used as filter)
- Search field debounces 450ms before firing API call
- TextEditingController added so clear button also resets the field
- Client-side filtering removed (API now handles it and returns top 7)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-07-12 20:18:25 -05:00
co-authored by Claude Sonnet 4.6
parent 9da159f287
commit e0982995e6
2 changed files with 32 additions and 16 deletions
+5 -7
View File
@@ -5,25 +5,23 @@ import 'package:prosapp_web_app/services/api_service.dart';
class ProfessionalsProvider extends ChangeNotifier {
List<UsuarioProfesional> professionals = [];
bool isLoading = true;
String? _city;
bool _initialized = false;
final _api = ApiService.instance;
void updateCity(String? city) {
// Always load on first auth event; afterwards only reload when city changes.
if (!_initialized || _city != city) {
// Only used to trigger the initial load when auth becomes available.
if (!_initialized) {
_initialized = true;
_city = city;
getProfessionals();
}
}
getProfessionals() async {
Future<void> getProfessionals({String? search}) async {
isLoading = true;
notifyListeners();
try {
final path = (_city != null && _city!.isNotEmpty)
? '/professionals?city=${Uri.encodeComponent(_city!)}'
final path = (search != null && search.trim().isNotEmpty)
? '/professionals?search=${Uri.encodeComponent(search.trim())}'
: '/professionals';
final res = await _api.get(path);
final list = (res is Map ? res['data'] : res) as List;