π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
show recents in UI
ashilkn20e212bbedd5
diff --git a/lib/models/search/recent_searches.dart b/lib/models/search/recent_searches.dartindex b6d68f57bd..95aed2a797 100644--- a/lib/models/search/recent_searches.dart+++ b/lib/models/search/recent_searches.dart@@ -12,6 +12,10 @@ class RecentSearches with ChangeNotifier {void add(SearchResult result) {searches.add(result);- notifyListeners();+ //buffer for not surfacing a new recent search before going to the next+ //screen+ Future.delayed(const Duration(seconds: 1), () {+ notifyListeners();+ });}}diff --git a/lib/models/search/search_types.dart b/lib/models/search/search_types.dartindex 6d5d853be1..78caf736a9 100644--- a/lib/models/search/search_types.dart+++ b/lib/models/search/search_types.dart@@ -28,6 +28,7 @@ enum ResultType {}enum SectionType {+ recents,face,location,// Grouping based on ML or manual tagging@@ -45,6 +46,8 @@ extension SectionTypeExtensions on SectionType {// passing context for internalization in the futureString sectionTitle(BuildContext context) {switch (this) {+ case SectionType.recents:+ return "Recents";case SectionType.face:return "Faces";case SectionType.content:@@ -67,27 +70,31 @@ extension SectionTypeExtensions on SectionType {// get int id to each section for ordering themint get orderID {switch (this) {- case SectionType.face:+ case SectionType.recents:return 0;- case SectionType.content:+ case SectionType.face:return 1;- case SectionType.moment:+ case SectionType.content:return 2;- case SectionType.location:+ case SectionType.moment:return 3;- case SectionType.people:+ case SectionType.location:return 4;- case SectionType.album:+ case SectionType.people:return 5;- case SectionType.fileTypesAndExtension:+ case SectionType.album:return 6;- case SectionType.fileCaption:+ case SectionType.fileTypesAndExtension:return 7;+ case SectionType.fileCaption:+ return 8;}}String getEmptyStateText(BuildContext context) {switch (this) {+ case SectionType.recents:+ return "";case SectionType.face:return S.of(context).searchFaceEmptySection;case SectionType.content:@@ -111,6 +118,8 @@ extension SectionTypeExtensions on SectionType {// Disable the CTA for face, content, moment, fileTypesAndExtension, fileCaptionbool get isCTAVisible {switch (this) {+ case SectionType.recents:+ return false;case SectionType.face:return false;case SectionType.content:@@ -132,6 +141,8 @@ extension SectionTypeExtensions on SectionType {bool get isEmptyCTAVisible {switch (this) {+ case SectionType.recents:+ return false;case SectionType.face:return true;case SectionType.content:@@ -153,6 +164,8 @@ extension SectionTypeExtensions on SectionType {String getCTAText(BuildContext context) {switch (this) {+ case SectionType.recents:+ return "";case SectionType.face:return "Setup";case SectionType.content:@@ -174,6 +187,8 @@ extension SectionTypeExtensions on SectionType {IconData? getCTAIcon() {switch (this) {+ case SectionType.recents:+ return null;case SectionType.face:return Icons.adaptive.arrow_forward_outlined;case SectionType.content:@@ -253,6 +268,9 @@ extension SectionTypeExtensions on SectionType {AssertionError("context cannot be null for SectionType.moment");}switch (this) {+ //recents doesn't depend on this value.+ case SectionType.recents:+ return Future.value([]);case SectionType.face:return SearchService.instance.getAllLocationTags(limit);diff --git a/lib/ui/search_tab.dart b/lib/ui/search_tab.dartindex 959bd976ed..0d96691a15 100644--- a/lib/ui/search_tab.dart+++ b/lib/ui/search_tab.dart@@ -111,11 +111,13 @@ class _AllSearchSectionsState extends State<AllSearchSections> {physics: const BouncingScrollPhysics(),itemCount: searchTypes.length,itemBuilder: (context, index) {- return SearchSection(- sectionType: searchTypes[index],- examples: snapshot.data!.elementAt(index),- limit: _limit,- );+ return searchTypes[index] == SectionType.recents+ ? const RecentSection()+ : SearchSection(+ sectionType: searchTypes[index],+ examples: snapshot.data!.elementAt(index),+ limit: _limit,+ );},);} else if (snapshot.hasError) {diff --git a/lib/ui/viewer/search/search_section.dart b/lib/ui/viewer/search/search_section.dartindex 22c743979e..42dfbeb871 100644--- a/lib/ui/viewer/search/search_section.dart+++ b/lib/ui/viewer/search/search_section.dart@@ -104,6 +104,52 @@ class SearchSection extends StatelessWidget {}}+class RecentSection extends StatelessWidget {+ const RecentSection({+ Key? key,+ }) : super(key: key);++ @override+ Widget build(BuildContext context) {+ debugPrint("Building section for recents");+ final textTheme = getEnteTextTheme(context);+ return ListenableBuilder(+ listenable: RecentSearches(),+ builder: (context, _) {+ if (RecentSearches().searches.isNotEmpty) {+ return Padding(+ padding: const EdgeInsets.symmetric(vertical: 8),+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Row(+ mainAxisAlignment: MainAxisAlignment.spaceBetween,+ children: [+ Padding(+ padding: const EdgeInsets.all(12),+ child: Text(+ SectionType.recents.sectionTitle(context),+ style: textTheme.largeBold,+ ),+ ),+ ],+ ),+ const SizedBox(height: 2),+ SearchExampleRow(+ RecentSearches().searches.toList(),+ SectionType.recents,+ ),+ ],+ ),+ );+ } else {+ return const SizedBox.shrink();+ }+ },+ );+ }+}+class SearchExampleRow extends StatelessWidget {final SectionType sectionType;final List<SearchResult> reccomendations;