From 2c88e6038bb13234d2ee05547792e45e38695fcd Mon Sep 17 00:00:00 2001 From: wcjord <32568597+wcjord@users.noreply.github.com> Date: Thu, 2 Jan 2025 08:56:18 -0500 Subject: [PATCH] feat: using translation in IT feedback as more succinct (#1295) * feat: using translation in IT feedback as more succinct * fix: removed unused / commented over code --------- Co-authored-by: ggurdin <46800240+ggurdin@users.noreply.github.com> Co-authored-by: ggurdin --- .../widgets/it_feedback_card.dart | 148 +++--------------- 1 file changed, 24 insertions(+), 124 deletions(-) diff --git a/lib/pangea/choreographer/widgets/it_feedback_card.dart b/lib/pangea/choreographer/widgets/it_feedback_card.dart index db19f303a..63e1fd96e 100644 --- a/lib/pangea/choreographer/widgets/it_feedback_card.dart +++ b/lib/pangea/choreographer/widgets/it_feedback_card.dart @@ -1,6 +1,4 @@ import 'package:fluffychat/pangea/repo/full_text_translation_repo.dart'; -import 'package:fluffychat/pangea/utils/error_handler.dart'; -import 'package:fluffychat/pangea/widgets/igc/why_button.dart'; import 'package:flutter/material.dart'; import 'package:http/http.dart'; @@ -9,9 +7,7 @@ import '../../../widgets/matrix.dart'; import '../../controllers/it_feedback_controller.dart'; import '../../controllers/pangea_controller.dart'; import '../../utils/bot_style.dart'; -import '../../widgets/common/bot_face_svg.dart'; import '../../widgets/igc/card_error_widget.dart'; -import '../../widgets/igc/card_header.dart'; class ITFeedbackCard extends StatefulWidget { final ITFeedbackRequestModel req; @@ -43,40 +39,18 @@ class ITFeedbackCardController extends State { if (!mounted) return; //any setup? super.initState(); + getFeedback(); } Future getFeedback() async { setState(() { isLoadingFeedback = true; }); - controller.itFeedback - .get(widget.req) - .then((value) { - res = value; - }) - .catchError((e) => error = e) - .whenComplete( - () => setState(() { - isLoadingFeedback = false; - }), - ); - } - Future translateFeedback() async { - if (res == null) { - ErrorHandler.logError( - m: "Cannot translate feedback because res is null", - data: {}, - ); - return; - } - setState(() { - isTranslating = true; - }); FullTextTranslationRepo.translate( accessToken: controller.userController.accessToken, request: FullTextTranslationRequestModel( - text: res!.text, + text: widget.req.chosenContinuance, tgtLang: controller.languageController.userL1?.langCode ?? widget.req.sourceTextLang, userL1: controller.languageController.userL1?.langCode ?? @@ -85,22 +59,20 @@ class ITFeedbackCardController extends State { widget.req.targetLang, ), ) - .then((value) { - translatedFeedback = value.bestTranslation; + .then((translationResponse) { + res = ITFeedbackResponseModel( + text: translationResponse.bestTranslation, + ); }) .catchError((e) => error = e) .whenComplete( () => setState(() { - isTranslating = false; + // isTranslating = false; + isLoadingFeedback = false; }), ); } - void handleGetExplanationButtonPress() { - if (isLoadingFeedback) return; - getFeedback(); - } - @override Widget build(BuildContext context) => error == null ? ITFeedbackCardView(controller: this) @@ -128,99 +100,27 @@ class ITFeedbackCardView extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.center, children: [ - CardHeader( - text: controller.widget.req.chosenContinuance, - botExpression: BotExpression.nonGold, + Text( + controller.widget.req.chosenContinuance, ), - // Text( - // controller.widget.choiceFeedback, - // style: BotStyle.text(context), - // ), const SizedBox(height: 10), - if (controller.res == null) - WhyButton( - onPress: controller.handleGetExplanationButtonPress, - loading: controller.isLoadingFeedback, + Text( + "≈", + style: TextStyle( + fontSize: + AppConfig.fontSizeFactor * AppConfig.messageFontSize * 1.5, + fontWeight: FontWeight.bold, ), - if (controller.res != null) - Text( - controller.res!.text, - style: BotStyle.text(context), - ), - // if res is not null and feedback not in the userL1, show a button to translate the text - if (controller.res != null && - controller.translatedFeedback == null && - controller.widget.req.feedbackLang != - controller.controller.languageController.userL1?.langCode) - Column( - children: [ - const SizedBox(height: 10), - TranslateButton( - onPress: controller.translateFeedback, - loading: controller.isTranslating, - ), - ], - ), - if (controller.translatedFeedback != null) - //add little line to separate the text from the translation - Column( - children: [ - const Divider( - color: AppConfig.primaryColor, - thickness: 2, - height: 20, // Set the space around the divider - indent: 20, // Set the starting space (left padding) - endIndent: 20, // Set the ending space (right padding) - ), - Text( - controller.translatedFeedback!, - style: BotStyle.text(context), - ), - ], + ), + Container( + constraints: const BoxConstraints( + minHeight: 30, ), - ], - ), - ), - ); - } -} - -// button to translate the text -class TranslateButton extends StatelessWidget { - const TranslateButton({ - super.key, - required this.onPress, - required this.loading, - }); - - final VoidCallback onPress; - final bool loading; - - @override - Widget build(BuildContext context) { - return TextButton( - onPressed: loading ? null : onPress, - style: ButtonStyle( - backgroundColor: WidgetStateProperty.all( - AppConfig.primaryColor.withOpacity(0.1), - ), - ), - child: SizedBox( - width: 150, // set the width of the button contents here - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - if (!loading) const Icon(Icons.translate), - if (loading) - const Center( - child: SizedBox( - width: 24.0, - height: 24.0, - child: CircularProgressIndicator(), - ), + child: Text( + controller.res?.text ?? "loading", + style: BotStyle.text(context), ), - // const SizedBox(width: 8), - // Text(L10n.of(context).translate), + ), ], ), ),