From e438e35ccdc74f7ef45228208b6fa7e61929ef2e Mon Sep 17 00:00:00 2001 From: ashilkn Date: Thu, 29 May 2025 18:29:08 +0530 Subject: [PATCH] Update contacts section on PeopleChangedEvent --- mobile/lib/models/search/search_types.dart | 2 ++ .../ui/viewer/search_tab/contacts_section.dart | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/mobile/lib/models/search/search_types.dart b/mobile/lib/models/search/search_types.dart index 28fdd7c9b5..0a6eb507ac 100644 --- a/mobile/lib/models/search/search_types.dart +++ b/mobile/lib/models/search/search_types.dart @@ -289,6 +289,8 @@ extension SectionTypeExtensions on SectionType { return [Bus.instance.on()]; case SectionType.magic: return [Bus.instance.on()]; + case SectionType.contacts: + return [Bus.instance.on()]; default: return []; } diff --git a/mobile/lib/ui/viewer/search_tab/contacts_section.dart b/mobile/lib/ui/viewer/search_tab/contacts_section.dart index bc751fbfa4..72610a1653 100644 --- a/mobile/lib/ui/viewer/search_tab/contacts_section.dart +++ b/mobile/lib/ui/viewer/search_tab/contacts_section.dart @@ -21,6 +21,7 @@ import "package:photos/ui/viewer/search/result/person_face_widget.dart"; import "package:photos/ui/viewer/search/search_section_cta.dart"; import "package:photos/ui/viewer/search_tab/section_header.dart"; import "package:photos/utils/navigation_util.dart"; +import "package:photos/utils/standalone/debouncer.dart"; class ContactsSection extends StatefulWidget { final List contactSearchResults; @@ -33,6 +34,9 @@ class ContactsSection extends StatefulWidget { class _ContactsSectionState extends State { late List _contactSearchResults; final streamSubscriptions = []; + final _debouncer = Debouncer( + const Duration(milliseconds: 1500), + ); @override void initState() { @@ -43,11 +47,13 @@ class _ContactsSectionState extends State { for (Stream stream in streamsToListenTo) { streamSubscriptions.add( stream.listen((event) async { - _contactSearchResults = (await SectionType.contacts.getData( - context, - limit: kSearchSectionLimit, - )) as List; - setState(() {}); + _debouncer.run(() async { + _contactSearchResults = (await SectionType.contacts.getData( + context, + limit: kSearchSectionLimit, + )) as List; + setState(() {}); + }); }), ); } @@ -58,6 +64,7 @@ class _ContactsSectionState extends State { for (var subscriptions in streamSubscriptions) { subscriptions.cancel(); } + _debouncer.cancelDebounceTimer(); super.dispose(); }