searchComponents method

Future<void> searchComponents(
  1. String query
)

Implementation

Future<void> searchComponents(String query) async {
  if (query.isEmpty) {
    emit(state.copyWith(
      filteredComponents: [],
      searchQuery: '',
      hasReachedMax: false,
    ));
    return loadAll();
  }

  emit(state.copyWith(
    isLoading: true,
    searchQuery: query,
    filteredComponents: [],
    hasReachedMax: false,
  ));

  final result = await repository.search(query, offset: 0, limit: _pageSize);

  result.fold(
    (error) => emit(state.copyWith(isLoading: false, error: error)),
    (components) => emit(state.copyWith(
      isLoading: false,
      filteredComponents: components,
      hasReachedMax: components.length < _pageSize,
    )),
  );
}