mirror of
https://github.com/immich-app/immich.git
synced 2024-11-17 19:08:49 -07:00
1633af7af6
* introduce Asset as composition of AssetResponseDTO and AssetEntity * filter out duplicate assets (that are both local and remote, take only remote for now) * only allow remote images to be added to albums * introduce ImmichImage to render Asset using local or remote data * optimized deletion of local assets * local video file playback * allow multiple methods to wait on background service finished * skip local assets when adding to album from home screen * fix and optimize delete * show gray box placeholder for local assets * add comments * fix bug: duplicate assets in state after onNewAssetUploaded
81 lines
2.4 KiB
Dart
81 lines
2.4 KiB
Dart
import 'package:collection/collection.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:immich_mobile/modules/home/ui/asset_grid/asset_grid_data_structure.dart';
|
|
import 'package:immich_mobile/modules/search/models/search_result_page_state.model.dart';
|
|
|
|
import 'package:immich_mobile/modules/search/services/search.service.dart';
|
|
import 'package:immich_mobile/modules/settings/providers/app_settings.provider.dart';
|
|
import 'package:immich_mobile/modules/settings/services/app_settings.service.dart';
|
|
import 'package:immich_mobile/shared/models/asset.dart';
|
|
import 'package:intl/intl.dart';
|
|
|
|
class SearchResultPageNotifier extends StateNotifier<SearchResultPageState> {
|
|
SearchResultPageNotifier(this._searchService)
|
|
: super(
|
|
SearchResultPageState(
|
|
searchResult: [],
|
|
isError: false,
|
|
isLoading: true,
|
|
isSuccess: false,
|
|
),
|
|
);
|
|
|
|
final SearchService _searchService;
|
|
|
|
void search(String searchTerm) async {
|
|
state = state.copyWith(
|
|
searchResult: [],
|
|
isError: false,
|
|
isLoading: true,
|
|
isSuccess: false,
|
|
);
|
|
|
|
List<Asset>? assets = (await _searchService.searchAsset(searchTerm))
|
|
?.map((e) => Asset.remote(e))
|
|
.toList();
|
|
|
|
if (assets != null) {
|
|
state = state.copyWith(
|
|
searchResult: assets,
|
|
isError: false,
|
|
isLoading: false,
|
|
isSuccess: true,
|
|
);
|
|
} else {
|
|
state = state.copyWith(
|
|
searchResult: [],
|
|
isError: true,
|
|
isLoading: false,
|
|
isSuccess: false,
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
final searchResultPageProvider =
|
|
StateNotifierProvider<SearchResultPageNotifier, SearchResultPageState>(
|
|
(ref) {
|
|
return SearchResultPageNotifier(ref.watch(searchServiceProvider));
|
|
});
|
|
|
|
final searchResultGroupByDateTimeProvider = StateProvider((ref) {
|
|
var assets = ref.watch(searchResultPageProvider).searchResult;
|
|
|
|
assets.sortByCompare<DateTime>(
|
|
(e) => e.createdAt,
|
|
(a, b) => b.compareTo(a),
|
|
);
|
|
return assets.groupListsBy(
|
|
(element) => DateFormat('y-MM-dd').format(element.createdAt.toLocal()),
|
|
);
|
|
});
|
|
|
|
final searchRenderListProvider = StateProvider((ref) {
|
|
var assetGroups = ref.watch(searchResultGroupByDateTimeProvider);
|
|
|
|
var settings = ref.watch(appSettingsServiceProvider);
|
|
final assetsPerRow = settings.getSetting(AppSettingsEnum.tilesPerRow);
|
|
|
|
return assetGroupsToRenderList(assetGroups, assetsPerRow);
|
|
});
|