π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Show first random month that has items in 'moments' search example section
ashilkn13ec5ab8c3d6
diff --git a/lib/models/search/search_types.dart b/lib/models/search/search_types.dartindex d6bf5ebe84..f4dc0cd908 100644--- a/lib/models/search/search_types.dart+++ b/lib/models/search/search_types.dart@@ -160,7 +160,10 @@ extension SectionTypeExtensions on SectionType {}}- Future<List<SearchResult>> getData({int? limit}) {+ Future<List<SearchResult>> getData({int? limit, BuildContext? context}) {+ if (this == SectionType.moment && context == null) {+ AssertionError("context cannot be null for SectionType.moment");+ }switch (this) {case SectionType.face:return SearchService.instance.getAllLocationTags(limit);@@ -169,7 +172,7 @@ extension SectionTypeExtensions on SectionType {return SearchService.instance.getAllLocationTags(limit);case SectionType.moment:- return SearchService.instance.getAllLocationTags(limit);+ return SearchService.instance.getRandomMonthSearchResults(context!);case SectionType.location:return SearchService.instance.getAllLocationTags(limit);diff --git a/lib/services/search_service.dart b/lib/services/search_service.dartindex 96b3b0015f..6090107097 100644--- a/lib/services/search_service.dart+++ b/lib/services/search_service.dart@@ -160,6 +160,33 @@ class SearchService {return searchResults;}+ Future<List<GenericSearchResult>> getRandomMonthSearchResults(+ BuildContext context,+ ) async {+ final List<GenericSearchResult> searchResults = [];++ final months = getMonthData(context)..shuffle();+ for (MonthData month in months) {+ final matchedFiles =+ await FilesDB.instance.getFilesCreatedWithinDurations(+ _getDurationsOfMonthInEveryYear(month.monthNumber),+ ignoreCollections(),+ order: 'DESC',+ );+ if (matchedFiles.isNotEmpty) {+ searchResults.add(+ GenericSearchResult(+ ResultType.month,+ month.name,+ matchedFiles,+ ),+ );+ break;+ }+ }+ return searchResults;+ }+Future<List<GenericSearchResult>> getHolidaySearchResults(BuildContext context,String query,diff --git a/lib/ui/search_tab.dart b/lib/ui/search_tab.dartindex 240ce8e4ef..a986d0d2ed 100644--- a/lib/ui/search_tab.dart+++ b/lib/ui/search_tab.dart@@ -49,19 +49,25 @@ class AllSearchSections extends StatefulWidget {class _AllSearchSectionsState extends State<AllSearchSections> {late Future<List<List<SearchResult>>> allSectionsExamples;+ late List<Future<List<SearchResult>>> sectionExamples;@overridevoid initState() {- final sectionExamples = <Future<List<SearchResult>>>[];+ super.initState();+ sectionExamples = <Future<List<SearchResult>>>[];+ }++ @override+ void didChangeDependencies() {+ super.didChangeDependencies();for (SectionType sectionType in SectionType.values) {if (sectionType == SectionType.face ||sectionType == SectionType.content) {continue;}- sectionExamples.add(sectionType.getData(limit: 7));+ sectionExamples.add(sectionType.getData(limit: 7, context: context));}allSectionsExamples = Future.wait<List<SearchResult>>(sectionExamples);- super.initState();}@override