From 542c4c21c60907436654ce336c3f1ca8bdb344b5 Mon Sep 17 00:00:00 2001 From: monsieurtanuki Date: Tue, 12 Dec 2023 20:17:16 +0100 Subject: [PATCH] feat: 4836 - clickable link to "open new issue" when relevant (#4875) * feat: 4836 - clickable link to "open new issue" when relevant Impacted files: * `app_en.arb`: added an "open new issue if relevant" label. * `app_fr.arb`: added an "open new issue if relevant" label. * `loading_dialog.dart`: added an optional `shouldOpenNewIssue` parameter with appropriate display * `pubspec.lock`: wtf * `pubspec.yaml`: upgraded openfoodfacts to 3.2.1 * `sign_up_page.dart`: use the new `shouldOpenNewIssue` parameter when server error * lint fixes --- .../lib/generic_lib/loading_dialog.dart | 29 +++++++++++++++++-- packages/smooth_app/lib/l10n/app_en.arb | 1 + packages/smooth_app/lib/l10n/app_fr.arb | 1 + .../pages/user_management/sign_up_page.dart | 6 +++- .../paged_to_be_completed_product_query.dart | 2 +- .../lib/query/paged_user_product_query.dart | 2 +- packages/smooth_app/pubspec.lock | 4 +-- packages/smooth_app/pubspec.yaml | 2 +- 8 files changed, 39 insertions(+), 8 deletions(-) diff --git a/packages/smooth_app/lib/generic_lib/loading_dialog.dart b/packages/smooth_app/lib/generic_lib/loading_dialog.dart index 22db9053d5d..2b11b86c4fe 100644 --- a/packages/smooth_app/lib/generic_lib/loading_dialog.dart +++ b/packages/smooth_app/lib/generic_lib/loading_dialog.dart @@ -1,9 +1,12 @@ +import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_svg/flutter_svg.dart'; +import 'package:openfoodfacts/openfoodfacts.dart'; import 'package:smooth_app/generic_lib/design_constants.dart'; import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart'; import 'package:smooth_app/helpers/app_helper.dart'; +import 'package:smooth_app/helpers/launch_url_helper.dart'; /// Dialog with a stop button, while a future is running. /// @@ -36,6 +39,7 @@ class LoadingDialog { static Future error({ required final BuildContext context, final String? title, + final bool shouldOpenNewIssue = false, }) async => showDialog( context: context, @@ -53,11 +57,32 @@ class LoadingDialog { Padding( padding: const EdgeInsets.symmetric(vertical: MEDIUM_SPACE), child: Text( - title ?? - appLocalizations.loading_dialog_default_error_message, + shouldOpenNewIssue + ? appLocalizations.server_error_open_new_issue + : title ?? + appLocalizations + .loading_dialog_default_error_message, textAlign: TextAlign.center, ), ), + if (shouldOpenNewIssue) + Padding( + padding: const EdgeInsets.only(bottom: MEDIUM_SPACE), + child: RichText( + textAlign: TextAlign.center, + text: TextSpan( + style: Theme.of(context).textTheme.bodyMedium?.copyWith( + color: Colors.blue, + ), + text: Status.openNewIssueUrl, + recognizer: TapGestureRecognizer() + ..onTap = () => LaunchUrlHelper.launchURL( + Status.openNewIssueUrl, + false, + ), + ), + ), + ), ], ), positiveAction: SmoothActionButton( diff --git a/packages/smooth_app/lib/l10n/app_en.arb b/packages/smooth_app/lib/l10n/app_en.arb index 17c60d18d30..4c58015c8d0 100644 --- a/packages/smooth_app/lib/l10n/app_en.arb +++ b/packages/smooth_app/lib/l10n/app_en.arb @@ -145,6 +145,7 @@ "@ecoCardUtility": { "description": "Description of what a user can use the Eco data in a product for." }, + "server_error_open_new_issue": "No server response! You may open an issue with the following link.", "@user_management": {}, "sign_in_text": "Sign in to your Open Food Facts account to save your contributions", "incorrect_credentials": "Incorrect username or password.", diff --git a/packages/smooth_app/lib/l10n/app_fr.arb b/packages/smooth_app/lib/l10n/app_fr.arb index d157c13c6c2..1addaff9baf 100644 --- a/packages/smooth_app/lib/l10n/app_fr.arb +++ b/packages/smooth_app/lib/l10n/app_fr.arb @@ -145,6 +145,7 @@ "@ecoCardUtility": { "description": "Description of what a user can use the Eco data in a product for." }, + "server_error_open_new_issue": "Pas de réponse du serveur ! Vous pouvez ouvrir un incident avec le lien ci-dessous.", "@user_management": {}, "sign_in_text": "Connectez-vous à votre compte Open Food Facts pour enregistrer vos contributions", "incorrect_credentials": "Nom d'utilisateur ou mot de passe incorrect.", diff --git a/packages/smooth_app/lib/pages/user_management/sign_up_page.dart b/packages/smooth_app/lib/pages/user_management/sign_up_page.dart index 3d3a815928d..cb0772e29f6 100644 --- a/packages/smooth_app/lib/pages/user_management/sign_up_page.dart +++ b/packages/smooth_app/lib/pages/user_management/sign_up_page.dart @@ -395,7 +395,11 @@ class _SignUpPageState extends State with TraceableClientMixin { } if (context.mounted) { - await LoadingDialog.error(context: context, title: errorMessage); + await LoadingDialog.error( + context: context, + title: errorMessage, + shouldOpenNewIssue: status.shouldOpenNewIssue(), + ); } return; } diff --git a/packages/smooth_app/lib/query/paged_to_be_completed_product_query.dart b/packages/smooth_app/lib/query/paged_to_be_completed_product_query.dart index b0aed2e23a1..574b519abea 100644 --- a/packages/smooth_app/lib/query/paged_to_be_completed_product_query.dart +++ b/packages/smooth_app/lib/query/paged_to_be_completed_product_query.dart @@ -16,7 +16,7 @@ class PagedToBeCompletedProductQuery extends PagedProductQuery { parametersList: [ PageSize(size: pageSize), PageNumber(page: pageNumber), - StatesTagsParameter( + const StatesTagsParameter( map: { ProductState.CATEGORIES_COMPLETED: false, }, diff --git a/packages/smooth_app/lib/query/paged_user_product_query.dart b/packages/smooth_app/lib/query/paged_user_product_query.dart index 8eef0be1643..fe9e22b0bf0 100644 --- a/packages/smooth_app/lib/query/paged_user_product_query.dart +++ b/packages/smooth_app/lib/query/paged_user_product_query.dart @@ -38,7 +38,7 @@ enum UserSearchType { PageSize(size: pageSize), PageNumber(page: pageNumber), if (toBeCompleted) - StatesTagsParameter( + const StatesTagsParameter( map: { ProductState.COMPLETED: false, }, diff --git a/packages/smooth_app/pubspec.lock b/packages/smooth_app/pubspec.lock index 7a0c4d6c5dd..8202bd511f5 100644 --- a/packages/smooth_app/pubspec.lock +++ b/packages/smooth_app/pubspec.lock @@ -1092,10 +1092,10 @@ packages: dependency: "direct main" description: name: openfoodfacts - sha256: "4a3a331ad0abc3bbea189ced88a426a4a9955a59e28df5f773d0697bef06ccfc" + sha256: "47436d0d647700327b8df45d02658a5e6e8d89b328e0b3d95c3fc3c34d5aebb7" url: "https://pub.dev" source: hosted - version: "3.1.0" + version: "3.2.1" openfoodfacts_flutter_lints: dependency: "direct dev" description: diff --git a/packages/smooth_app/pubspec.yaml b/packages/smooth_app/pubspec.yaml index f57e08ec962..5b6bf7131c6 100644 --- a/packages/smooth_app/pubspec.yaml +++ b/packages/smooth_app/pubspec.yaml @@ -98,7 +98,7 @@ dependencies: path: ../scanner/zxing - openfoodfacts: 3.1.0 + openfoodfacts: 3.2.1 # openfoodfacts: # path: ../../../openfoodfacts-dart