add version field, installable app caching
This commit is contained in:
parent
4833b5c18c
commit
2141e144be
7 changed files with 79 additions and 9 deletions
|
|
@ -9,17 +9,47 @@ part 'scoop_search_event.dart';
|
|||
part 'scoop_search_state.dart';
|
||||
|
||||
class ScoopSearchBloc extends Bloc<ScoopSearchEvent, ScoopSearchState> {
|
||||
final Map<String, List<ScoopAppModel>> _cachedApps = {};
|
||||
|
||||
ScoopSearchBloc() : super(ScoopSearchInitial()) {
|
||||
on<ScoopSearchReload>(
|
||||
(event, emit) async {
|
||||
_cachedApps.clear();
|
||||
try {
|
||||
Map<String, List<ScoopAppModel>> data = await getAllInstallableApps();
|
||||
_cachedApps.addAll(data);
|
||||
emit(ScoopSearchLoaded(data));
|
||||
} catch (e) {
|
||||
emit(const ScoopSearchLoaded({}));
|
||||
}
|
||||
},
|
||||
transformer: droppable(),
|
||||
);
|
||||
on<ScoopSearchQueryChanged>(
|
||||
(event, emit) async {
|
||||
emit(ScoopSearchLoading());
|
||||
|
||||
try {
|
||||
Map<String, List<ScoopAppModel>> data = {};
|
||||
if (event.query.isEmpty) {
|
||||
data = await getAllInstallableApps();
|
||||
if (_cachedApps.isEmpty) {
|
||||
_cachedApps.addAll(await getAllInstallableApps());
|
||||
}
|
||||
|
||||
if (event.query.isNotEmpty) {
|
||||
for (final bucket in _cachedApps.keys) {
|
||||
data[bucket] = _cachedApps[bucket]
|
||||
?.where((app) =>
|
||||
app.name
|
||||
.toLowerCase()
|
||||
.contains(event.query.toLowerCase()) ||
|
||||
app.description
|
||||
.toLowerCase()
|
||||
.contains(event.query.toLowerCase()))
|
||||
.toList() ??
|
||||
[];
|
||||
}
|
||||
} else {
|
||||
data = await searchInstallableApps(event.query);
|
||||
data.addAll(_cachedApps);
|
||||
}
|
||||
emit(ScoopSearchLoaded(data));
|
||||
} catch (e) {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ abstract class ScoopSearchEvent extends Equatable {
|
|||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class ScoopSearchReload extends ScoopSearchEvent {}
|
||||
|
||||
class ScoopSearchQueryChanged extends ScoopSearchEvent {
|
||||
final String query;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue