Skip to content

armgit / ente

Public Imported from GitHub
0

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

Deduplicate search map navigation

ashilknaba7caaefef2
diff --git a/mobile/apps/photos/lib/ui/viewer/search/result/go_to_map_widget.dart b/mobile/apps/photos/lib/ui/viewer/search/result/go_to_map_widget.dart
index e41cdb1db9..75201b1592 100644
--- a/mobile/apps/photos/lib/ui/viewer/search/result/go_to_map_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search/result/go_to_map_widget.dart
@@ -1,10 +1,7 @@
import "package:flutter/material.dart";
import "package:photos/generated/l10n.dart";
-import "package:photos/service_locator.dart";
-import "package:photos/services/search_service.dart";
import "package:photos/theme/ente_theme.dart";
-import "package:photos/ui/map/map_screen.dart";
-import 'package:photos/ui/notification/toast.dart';
+import "package:photos/ui/viewer/search/search_map_navigation.dart";
//Used for empty state of location section
class GoToMap extends StatelessWidget {
@@ -16,33 +13,7 @@ class GoToMap extends StatelessWidget {
? "assets/search_map_tile_dark.png"
: "assets/search_map_tile_light.png";
return GestureDetector(
- onTap: () async {
- if (!mapEnabled) {
- try {
- await setMapEnabled(true);
- if (!context.mounted) {
- return;
- }
- } catch (e) {
- if (!context.mounted) {
- return;
- }
- showShortToast(
- context,
- AppLocalizations.of(context).somethingWentWrong,
- );
- return;
- }
- }
- // ignore: unawaited_futures
- Navigator.of(context).push(
- MaterialPageRoute(
- builder: (context) => MapScreen(
- filesFutureFn: SearchService.instance.getAllFilesForSearch,
- ),
- ),
- );
- },
+ onTap: () => openSearchMap(context),
child: Padding(
padding: const EdgeInsets.fromLTRB(8, 14, 8, 0),
child: Column(
diff --git a/mobile/apps/photos/lib/ui/viewer/search/search_map_navigation.dart b/mobile/apps/photos/lib/ui/viewer/search/search_map_navigation.dart
new file mode 100644
index 0000000000..1e135eca3e
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/viewer/search/search_map_navigation.dart
@@ -0,0 +1,35 @@
+import "dart:async";
+
+import "package:flutter/material.dart";
+import "package:photos/generated/l10n.dart";
+import "package:photos/service_locator.dart";
+import "package:photos/services/search_service.dart";
+import "package:photos/ui/map/map_screen.dart";
+import "package:photos/ui/notification/toast.dart";
+
+Future<void> openSearchMap(BuildContext context) async {
+ if (!mapEnabled) {
+ try {
+ await setMapEnabled(true);
+ if (!context.mounted) {
+ return;
+ }
+ } catch (e) {
+ if (!context.mounted) {
+ return;
+ }
+ showShortToast(context, AppLocalizations.of(context).somethingWentWrong);
+ return;
+ }
+ }
+
+ unawaited(
+ Navigator.of(context).push(
+ MaterialPageRoute(
+ builder: (context) => MapScreen(
+ filesFutureFn: SearchService.instance.getAllFilesForSearch,
+ ),
+ ),
+ ),
+ );
+}
diff --git a/mobile/apps/photos/lib/ui/viewer/search_tab/locations_section.dart b/mobile/apps/photos/lib/ui/viewer/search_tab/locations_section.dart
index 408d3c6953..6c30036ab6 100644
--- a/mobile/apps/photos/lib/ui/viewer/search_tab/locations_section.dart
+++ b/mobile/apps/photos/lib/ui/viewer/search_tab/locations_section.dart
@@ -10,16 +10,13 @@ import "package:photos/generated/l10n.dart";
import "package:photos/models/search/generic_search_result.dart";
import "package:photos/models/search/recent_searches.dart";
import "package:photos/models/search/search_types.dart";
-import "package:photos/service_locator.dart";
-import "package:photos/services/search_service.dart";
import "package:photos/theme/colors.dart";
import "package:photos/theme/ente_theme.dart";
-import "package:photos/ui/map/map_screen.dart";
-import 'package:photos/ui/notification/toast.dart';
import "package:photos/ui/viewer/file/no_thumbnail_widget.dart";
import "package:photos/ui/viewer/file/thumbnail_widget.dart";
import "package:photos/ui/viewer/search/result/go_to_map_widget.dart";
import "package:photos/ui/viewer/search/result/search_result_page.dart";
+import "package:photos/ui/viewer/search/search_map_navigation.dart";
import "package:photos/ui/viewer/search/search_section_cta.dart";
import "package:photos/ui/viewer/search_tab/search_tab_horizontal_scroll.dart";
import "package:photos/ui/viewer/search_tab/section_header.dart";
@@ -269,33 +266,7 @@ class GoToMapTile extends StatelessWidget {
? "assets/search_map_tile_dark.png"
: "assets/search_map_tile_light.png";
return GestureDetector(
- onTap: () async {
- if (!mapEnabled) {
- try {
- await setMapEnabled(true);
- if (!context.mounted) {
- return;
- }
- } catch (e) {
- if (!context.mounted) {
- return;
- }
- showShortToast(
- context,
- AppLocalizations.of(context).somethingWentWrong,
- );
- return;
- }
- }
- // ignore: unawaited_futures
- Navigator.of(context).push(
- MaterialPageRoute(
- builder: (context) => MapScreen(
- filesFutureFn: SearchService.instance.getAllFilesForSearch,
- ),
- ),
- );
- },
+ onTap: () => openSearchMap(context),
child: SizedBox(
width: LocationRecommendation.width,
child: Column(