1
0
mirror of https://github.com/immich-app/immich.git synced 2024-12-19 00:32:49 +02:00
immich/mobile/lib/providers/search/search_page_state.provider.dart
Alex c1253663b7
refactor(mobile): services and providers (#9232)
* refactor(mobile): services and provider

* providers
2024-05-02 15:59:14 -05:00

52 lines
1.3 KiB
Dart

import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/models/search/search_curated_content.model.dart';
import 'package:immich_mobile/services/search.service.dart';
final getPreviewPlacesProvider =
FutureProvider.autoDispose<List<SearchCuratedContent>>((ref) async {
final SearchService searchService = ref.watch(searchServiceProvider);
final exploreData = await searchService.getExploreData();
if (exploreData == null) {
return [];
}
final locations =
exploreData.firstWhere((data) => data.fieldName == "exifInfo.city").items;
final curatedContent = locations
.map(
(l) => SearchCuratedContent(
label: l.value,
id: l.data.id,
),
)
.toList();
return curatedContent;
});
final getAllPlacesProvider =
FutureProvider.autoDispose<List<SearchCuratedContent>>((ref) async {
final SearchService searchService = ref.watch(searchServiceProvider);
final assetPlaces = await searchService.getAllPlaces();
if (assetPlaces == null) {
return [];
}
final curatedContent = assetPlaces
.map(
(data) => SearchCuratedContent(
label: data.exifInfo!.city!,
id: data.id,
),
)
.toList();
return curatedContent;
});