mirror of
https://github.com/immich-app/immich
synced 2026-08-15 13:03:57 +00:00
refactor: reactive driftGetAllPeopleProvider
This commit is contained in:
parent
8ba4baccd8
commit
71562d7f74
6 changed files with 10 additions and 22 deletions
|
|
@ -18,8 +18,8 @@ class DriftPeopleService {
|
|||
return _repository.getAssetPeople(assetId);
|
||||
}
|
||||
|
||||
Future<List<Person>> getAllPeople({int minFaces = 3}) {
|
||||
return _repository.getAllPeople(minFaces: minFaces);
|
||||
Stream<List<Person>> watch({int minFaces = 3}) {
|
||||
return _repository.watch(minFaces: minFaces);
|
||||
}
|
||||
|
||||
Future<int> updateName(String personId, String name) async {
|
||||
|
|
@ -27,7 +27,7 @@ class DriftPeopleService {
|
|||
return _repository.updateName(personId, name);
|
||||
}
|
||||
|
||||
Future<int> updateBrithday(String personId, DateTime birthday) async {
|
||||
Future<int> updateBirthday(String personId, DateTime birthday) async {
|
||||
await _personApiRepository.update(personId, birthday: birthday);
|
||||
return _repository.updateBirthday(personId, birthday);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class DriftPeopleRepository extends DriftDatabaseRepository {
|
|||
return query.map((row) => row.toDto()).get();
|
||||
}
|
||||
|
||||
Future<List<Person>> getAllPeople({int minFaces = 3}) async {
|
||||
Stream<List<Person>> watch({int minFaces = 3}) {
|
||||
final people = _db.personEntity;
|
||||
final faces = _db.assetFaceEntity;
|
||||
final assets = _db.remoteAssetEntity;
|
||||
|
|
@ -59,7 +59,7 @@ class DriftPeopleRepository extends DriftDatabaseRepository {
|
|||
return query.map((row) {
|
||||
final person = row.readTable(people);
|
||||
return person.toDto();
|
||||
}).get();
|
||||
}).watch();
|
||||
}
|
||||
|
||||
Future<int> updateName(String personId, String name) {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import 'package:immich_mobile/presentation/pages/search/paginated_search.provide
|
|||
import 'package:immich_mobile/providers/haptic_feedback.provider.dart';
|
||||
import 'package:immich_mobile/providers/infrastructure/album.provider.dart';
|
||||
import 'package:immich_mobile/providers/infrastructure/memory.provider.dart';
|
||||
import 'package:immich_mobile/providers/infrastructure/people.provider.dart';
|
||||
import 'package:immich_mobile/providers/infrastructure/readonly_mode.provider.dart';
|
||||
import 'package:immich_mobile/providers/search/search_input_focus.provider.dart';
|
||||
import 'package:immich_mobile/providers/tab.provider.dart';
|
||||
|
|
@ -132,7 +131,6 @@ void _onNavigationSelected(TabsRouter router, int index, WidgetRef ref) {
|
|||
// Library page
|
||||
if (index == kLibraryTabIndex) {
|
||||
ref.invalidate(localAlbumProvider);
|
||||
ref.invalidate(driftGetAllPeopleProvider);
|
||||
}
|
||||
|
||||
ref.read(hapticFeedbackProvider.notifier).selectionClick();
|
||||
|
|
|
|||
|
|
@ -30,14 +30,9 @@ class _DriftPersonNameEditFormState extends ConsumerState<DriftPersonBirthdayEdi
|
|||
|
||||
Future<void> saveBirthday() async {
|
||||
try {
|
||||
final result = await ref.read(driftPeopleServiceProvider).updateBrithday(widget.person.id, _selectedDate);
|
||||
|
||||
if (result != 0) {
|
||||
ref.invalidate(driftGetAllPeopleProvider);
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
final result = await ref.read(driftPeopleServiceProvider).updateBirthday(widget.person.id, _selectedDate);
|
||||
|
||||
if (result != 0 && mounted) {
|
||||
context.pop<DateTime>(_selectedDate);
|
||||
}
|
||||
} catch (error) {
|
||||
|
|
|
|||
|
|
@ -29,12 +29,7 @@ class _DriftPersonNameEditFormState extends ConsumerState<DriftPersonNameEditFor
|
|||
Future<void> onEdit(String personId, String newName) async {
|
||||
try {
|
||||
final result = await ref.read(driftPeopleServiceProvider).updateName(personId, newName);
|
||||
if (result != 0) {
|
||||
ref.invalidate(driftGetAllPeopleProvider);
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (result != 0 && mounted) {
|
||||
context.pop<String>(newName);
|
||||
}
|
||||
} catch (error) {
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ final driftPeopleAssetProvider = FutureProvider.family<List<Person>, String>((re
|
|||
return service.getAssetPeople(assetId);
|
||||
});
|
||||
|
||||
final driftGetAllPeopleProvider = FutureProvider<List<Person>>((ref) async {
|
||||
final driftGetAllPeopleProvider = StreamProvider<List<Person>>((ref) async* {
|
||||
final service = ref.watch(driftPeopleServiceProvider);
|
||||
final prefs = await ref.watch(userMetadataPreferencesProvider.future);
|
||||
return service.getAllPeople(minFaces: prefs?.minimumFaces ?? 3);
|
||||
yield* service.watch(minFaces: prefs?.minimumFaces ?? 3);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue