first commit
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
import 'package:mobx/mobx.dart';
|
||||
import '../../data/models/patient_search_item_model.dart';
|
||||
import '../../data/services/patient_search_service.dart';
|
||||
|
||||
part 'patient_search_store.g.dart';
|
||||
|
||||
// ignore: library_private_types_in_public_api
|
||||
class PatientSearchStore = _PatientSearchStoreBase with _$PatientSearchStore;
|
||||
|
||||
abstract class _PatientSearchStoreBase with Store {
|
||||
final PatientSearchService service;
|
||||
|
||||
_PatientSearchStoreBase({PatientSearchService? searchService})
|
||||
: service = searchService ?? PatientSearchService();
|
||||
|
||||
@observable
|
||||
String query = '';
|
||||
|
||||
@observable
|
||||
bool isLoading = false;
|
||||
|
||||
@observable
|
||||
bool hasSearched = false;
|
||||
|
||||
@observable
|
||||
String? errorMessage;
|
||||
|
||||
@observable
|
||||
ObservableList<PatientSearchItemModel> results = ObservableList<PatientSearchItemModel>();
|
||||
|
||||
@computed
|
||||
int get resultsCount => results.length;
|
||||
|
||||
@action
|
||||
void setQuery(String value) {
|
||||
query = value;
|
||||
}
|
||||
|
||||
@action
|
||||
Future<void> search(String rawQuery) async {
|
||||
final clean = rawQuery.trim();
|
||||
if (clean.isEmpty) return;
|
||||
|
||||
query = clean;
|
||||
isLoading = true;
|
||||
errorMessage = null;
|
||||
|
||||
try {
|
||||
final items = await service.searchPatients(clean);
|
||||
runInAction(() {
|
||||
results = ObservableList.of(items);
|
||||
hasSearched = true;
|
||||
isLoading = false;
|
||||
});
|
||||
} catch (e) {
|
||||
runInAction(() {
|
||||
errorMessage = e.toString().replaceAll('Exception: ', '');
|
||||
hasSearched = true;
|
||||
isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
void clear() {
|
||||
query = '';
|
||||
hasSearched = false;
|
||||
errorMessage = null;
|
||||
results.clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'patient_search_store.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// StoreGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// ignore_for_file: non_constant_identifier_names, unnecessary_brace_in_string_interps, unnecessary_lambdas, prefer_expression_function_bodies, lines_longer_than_80_chars, avoid_as, avoid_annotating_with_dynamic, no_leading_underscores_for_local_identifiers
|
||||
|
||||
mixin _$PatientSearchStore on _PatientSearchStoreBase, Store {
|
||||
Computed<int>? _$resultsCountComputed;
|
||||
|
||||
@override
|
||||
int get resultsCount => (_$resultsCountComputed ??= Computed<int>(
|
||||
() => super.resultsCount,
|
||||
name: '_PatientSearchStoreBase.resultsCount',
|
||||
)).value;
|
||||
|
||||
late final _$queryAtom = Atom(
|
||||
name: '_PatientSearchStoreBase.query',
|
||||
context: context,
|
||||
);
|
||||
|
||||
@override
|
||||
String get query {
|
||||
_$queryAtom.reportRead();
|
||||
return super.query;
|
||||
}
|
||||
|
||||
@override
|
||||
set query(String value) {
|
||||
_$queryAtom.reportWrite(value, super.query, () {
|
||||
super.query = value;
|
||||
});
|
||||
}
|
||||
|
||||
late final _$isLoadingAtom = Atom(
|
||||
name: '_PatientSearchStoreBase.isLoading',
|
||||
context: context,
|
||||
);
|
||||
|
||||
@override
|
||||
bool get isLoading {
|
||||
_$isLoadingAtom.reportRead();
|
||||
return super.isLoading;
|
||||
}
|
||||
|
||||
@override
|
||||
set isLoading(bool value) {
|
||||
_$isLoadingAtom.reportWrite(value, super.isLoading, () {
|
||||
super.isLoading = value;
|
||||
});
|
||||
}
|
||||
|
||||
late final _$hasSearchedAtom = Atom(
|
||||
name: '_PatientSearchStoreBase.hasSearched',
|
||||
context: context,
|
||||
);
|
||||
|
||||
@override
|
||||
bool get hasSearched {
|
||||
_$hasSearchedAtom.reportRead();
|
||||
return super.hasSearched;
|
||||
}
|
||||
|
||||
@override
|
||||
set hasSearched(bool value) {
|
||||
_$hasSearchedAtom.reportWrite(value, super.hasSearched, () {
|
||||
super.hasSearched = value;
|
||||
});
|
||||
}
|
||||
|
||||
late final _$errorMessageAtom = Atom(
|
||||
name: '_PatientSearchStoreBase.errorMessage',
|
||||
context: context,
|
||||
);
|
||||
|
||||
@override
|
||||
String? get errorMessage {
|
||||
_$errorMessageAtom.reportRead();
|
||||
return super.errorMessage;
|
||||
}
|
||||
|
||||
@override
|
||||
set errorMessage(String? value) {
|
||||
_$errorMessageAtom.reportWrite(value, super.errorMessage, () {
|
||||
super.errorMessage = value;
|
||||
});
|
||||
}
|
||||
|
||||
late final _$resultsAtom = Atom(
|
||||
name: '_PatientSearchStoreBase.results',
|
||||
context: context,
|
||||
);
|
||||
|
||||
@override
|
||||
ObservableList<PatientSearchItemModel> get results {
|
||||
_$resultsAtom.reportRead();
|
||||
return super.results;
|
||||
}
|
||||
|
||||
@override
|
||||
set results(ObservableList<PatientSearchItemModel> value) {
|
||||
_$resultsAtom.reportWrite(value, super.results, () {
|
||||
super.results = value;
|
||||
});
|
||||
}
|
||||
|
||||
late final _$searchAsyncAction = AsyncAction(
|
||||
'_PatientSearchStoreBase.search',
|
||||
context: context,
|
||||
);
|
||||
|
||||
@override
|
||||
Future<void> search(String rawQuery) {
|
||||
return _$searchAsyncAction.run(() => super.search(rawQuery));
|
||||
}
|
||||
|
||||
late final _$_PatientSearchStoreBaseActionController = ActionController(
|
||||
name: '_PatientSearchStoreBase',
|
||||
context: context,
|
||||
);
|
||||
|
||||
@override
|
||||
void setQuery(String value) {
|
||||
final _$actionInfo = _$_PatientSearchStoreBaseActionController.startAction(
|
||||
name: '_PatientSearchStoreBase.setQuery',
|
||||
);
|
||||
try {
|
||||
return super.setQuery(value);
|
||||
} finally {
|
||||
_$_PatientSearchStoreBaseActionController.endAction(_$actionInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void clear() {
|
||||
final _$actionInfo = _$_PatientSearchStoreBaseActionController.startAction(
|
||||
name: '_PatientSearchStoreBase.clear',
|
||||
);
|
||||
try {
|
||||
return super.clear();
|
||||
} finally {
|
||||
_$_PatientSearchStoreBaseActionController.endAction(_$actionInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '''
|
||||
query: ${query},
|
||||
isLoading: ${isLoading},
|
||||
hasSearched: ${hasSearched},
|
||||
errorMessage: ${errorMessage},
|
||||
results: ${results},
|
||||
resultsCount: ${resultsCount}
|
||||
''';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user