Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Share year search query helper

ashil-pilot45bd749b01fc
diff --git a/mobile/apps/photos/lib/ui/viewer/search/search_query_utils.dart b/mobile/apps/photos/lib/ui/viewer/search/search_query_utils.dart
new file mode 100644
index 0000000000..7e344f2f8b
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/viewer/search/search_query_utils.dart
@@ -0,0 +1,6 @@
+import "package:ente_pure_utils/ente_pure_utils.dart";
+
+bool isYearSearchQuery(String query) {
+ final yearAsInt = int.tryParse(query);
+ return yearAsInt != null && yearAsInt <= currentYear;
+}
diff --git a/mobile/apps/photos/lib/ui/viewer/search/search_suggestions.dart b/mobile/apps/photos/lib/ui/viewer/search/search_suggestions.dart
index 791d638e50..e3081fd525 100644
--- a/mobile/apps/photos/lib/ui/viewer/search/search_suggestions.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search/search_suggestions.dart
@@ -22,6 +22,7 @@ import "package:photos/ui/components/thumbnail_list_item.dart";
import "package:photos/ui/viewer/gallery/collection_page.dart";
import "package:photos/ui/viewer/gallery/device_folder_page.dart";
import "package:photos/ui/viewer/search/result/search_result_widget.dart";
+import "package:photos/ui/viewer/search/search_query_utils.dart";
import "package:photos/ui/viewer/search/search_widget.dart";
///Not using StreamBuilder in this widget for rebuilding on every new event as
@@ -429,16 +430,11 @@ bool _looksLikeMomentQuery(BuildContext context, String query) {
if (query.isEmpty) {
return false;
}
- return _isYearQuery(query) ||
+ return isYearSearchQuery(query) ||
_isParsedDateQuery(query) ||
_isLocalizedMonthQuery(context, query);
}
-bool _isYearQuery(String query) {
- final yearAsInt = int.tryParse(query);
- return yearAsInt != null && yearAsInt <= currentYear;
-}
-
bool _isParsedDateQuery(String query) {
final parsedDate = DateParseService.instance.parse(query);
if (parsedDate.isEmpty) {
diff --git a/mobile/apps/photos/lib/ui/viewer/search/search_widget.dart b/mobile/apps/photos/lib/ui/viewer/search/search_widget.dart
index 6d6e8f7659..4506ad6788 100644
--- a/mobile/apps/photos/lib/ui/viewer/search/search_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search/search_widget.dart
@@ -12,6 +12,7 @@ import "package:photos/models/search/generic_search_result.dart";
import "package:photos/models/search/index_of_indexed_stack.dart";
import "package:photos/models/search/search_result.dart";
import "package:photos/services/search_service.dart";
+import "package:photos/ui/viewer/search/search_query_utils.dart";
import "package:photos/ui/viewer/search/search_suffix_icon_widget.dart";
import "package:photos/utils/pending_translation.dart";
@@ -204,7 +205,7 @@ class SearchWidgetState extends State<SearchWidget> {
String query,
) {
int resultCount = 0;
- final maxResultCount = _isYearValid(query) ? 13 : 12;
+ final maxResultCount = isYearSearchQuery(query) ? 13 : 12;
final streamController = StreamController<List<SearchResult>>();
if (query.isEmpty) {
@@ -227,7 +228,7 @@ class SearchWidgetState extends State<SearchWidget> {
}
}
- if (_isYearValid(query)) {
+ if (isYearSearchQuery(query)) {
_searchService.getYearSearchResults(query).then((yearSearchResults) {
onResultsReceived(yearSearchResults);
});
@@ -297,9 +298,4 @@ class SearchWidgetState extends State<SearchWidget> {
return streamController.stream.asBroadcastStream();
}
-
- bool _isYearValid(String year) {
- final yearAsInt = int.tryParse(year); //returns null if cannot be parsed
- return yearAsInt != null && yearAsInt <= currentYear;
- }
}