2023-06-23 17:44:02 +02:00
|
|
|
import 'package:immich_mobile/modules/home/ui/asset_grid/asset_grid_data_structure.dart';
|
2023-11-19 18:04:44 +02:00
|
|
|
import 'package:immich_mobile/modules/search/models/curated_content.dart';
|
2023-06-23 17:44:02 +02:00
|
|
|
import 'package:immich_mobile/modules/search/services/person.service.dart';
|
2023-11-19 18:04:44 +02:00
|
|
|
import 'package:immich_mobile/modules/settings/providers/app_settings.provider.dart';
|
|
|
|
import 'package:immich_mobile/modules/settings/services/app_settings.service.dart';
|
|
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
2023-06-23 17:44:02 +02:00
|
|
|
|
2023-11-19 18:04:44 +02:00
|
|
|
part 'people.provider.g.dart';
|
2023-06-23 17:44:02 +02:00
|
|
|
|
2023-11-19 18:04:44 +02:00
|
|
|
@riverpod
|
|
|
|
Future<List<CuratedContent>> getCuratedPeople(
|
|
|
|
GetCuratedPeopleRef ref,
|
|
|
|
) async {
|
|
|
|
final PersonService personService = ref.read(personServiceProvider);
|
2023-06-23 17:44:02 +02:00
|
|
|
|
|
|
|
final curatedPeople = await personService.getCuratedPeople();
|
|
|
|
|
2023-11-19 18:04:44 +02:00
|
|
|
return curatedPeople
|
|
|
|
.map((p) => CuratedContent(id: p.id, label: p.name))
|
|
|
|
.toList();
|
|
|
|
}
|
2023-06-23 17:44:02 +02:00
|
|
|
|
2023-11-19 18:04:44 +02:00
|
|
|
@riverpod
|
|
|
|
Future<RenderList> personAssets(PersonAssetsRef ref, String personId) async {
|
|
|
|
final PersonService personService = ref.read(personServiceProvider);
|
|
|
|
final assets = await personService.getPersonAssets(personId);
|
|
|
|
if (assets == null) {
|
|
|
|
return RenderList.empty();
|
|
|
|
}
|
2023-06-23 17:44:02 +02:00
|
|
|
|
2023-11-19 18:04:44 +02:00
|
|
|
final settings = ref.read(appSettingsServiceProvider);
|
|
|
|
final groupBy =
|
|
|
|
GroupAssetsBy.values[settings.getSetting(AppSettingsEnum.groupAssetsBy)];
|
|
|
|
return await RenderList.fromAssets(assets, groupBy);
|
2023-06-23 17:44:02 +02:00
|
|
|
}
|
|
|
|
|
2023-11-19 18:04:44 +02:00
|
|
|
@riverpod
|
|
|
|
Future<bool> updatePersonName(
|
|
|
|
UpdatePersonNameRef ref,
|
|
|
|
String personId,
|
|
|
|
String updatedName,
|
|
|
|
) async {
|
|
|
|
final PersonService personService = ref.read(personServiceProvider);
|
|
|
|
final person = await personService.updateName(personId, updatedName);
|
2023-06-23 17:44:02 +02:00
|
|
|
|
2023-11-19 18:04:44 +02:00
|
|
|
if (person != null && person.name == updatedName) {
|
2023-06-23 17:44:02 +02:00
|
|
|
ref.invalidate(getCuratedPeopleProvider);
|
2023-11-19 18:04:44 +02:00
|
|
|
return true;
|
2023-06-23 17:44:02 +02:00
|
|
|
}
|
2023-11-19 18:04:44 +02:00
|
|
|
return false;
|
|
|
|
}
|