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