Skip to content

Commit

Permalink
TF-3226 Apply minInputLength on autocomplete capability to app
Browse files Browse the repository at this point in the history
  • Loading branch information
dab246 authored and hoangdat committed Nov 20, 2024
1 parent b344062 commit 2177082
Show file tree
Hide file tree
Showing 18 changed files with 135 additions and 10 deletions.
18 changes: 18 additions & 0 deletions lib/features/composer/presentation/composer_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ class ComposerView extends GetWidget<ComposerController> {
listEmailAddress: controller.listToEmailAddress,
imagePaths: controller.imagePaths,
maxWidth: constraints.maxWidth,
minInputLengthAutocomplete: controller
.mailboxDashBoardController
.minInputLengthAutocomplete,
fromState: controller.fromRecipientState.value,
ccState: controller.ccRecipientState.value,
bccState: controller.bccRecipientState.value,
Expand All @@ -150,6 +153,9 @@ class ComposerView extends GetWidget<ComposerController> {
listEmailAddress: controller.listCcEmailAddress,
imagePaths: controller.imagePaths,
maxWidth: constraints.maxWidth,
minInputLengthAutocomplete: controller
.mailboxDashBoardController
.minInputLengthAutocomplete,
expandMode: controller.ccAddressExpandMode.value,
controller: controller.ccEmailAddressController,
focusNode: controller.ccAddressFocusNode,
Expand All @@ -176,6 +182,9 @@ class ComposerView extends GetWidget<ComposerController> {
listEmailAddress: controller.listBccEmailAddress,
imagePaths: controller.imagePaths,
maxWidth: constraints.maxWidth,
minInputLengthAutocomplete: controller
.mailboxDashBoardController
.minInputLengthAutocomplete,
expandMode: controller.bccAddressExpandMode.value,
controller: controller.bccEmailAddressController,
focusNode: controller.bccAddressFocusNode,
Expand Down Expand Up @@ -280,6 +289,9 @@ class ComposerView extends GetWidget<ComposerController> {
listEmailAddress: controller.listToEmailAddress,
imagePaths: controller.imagePaths,
maxWidth: constraints.maxWidth,
minInputLengthAutocomplete: controller
.mailboxDashBoardController
.minInputLengthAutocomplete,
fromState: controller.fromRecipientState.value,
ccState: controller.ccRecipientState.value,
bccState: controller.bccRecipientState.value,
Expand All @@ -305,6 +317,9 @@ class ComposerView extends GetWidget<ComposerController> {
listEmailAddress: controller.listCcEmailAddress,
imagePaths: controller.imagePaths,
maxWidth: constraints.maxWidth,
minInputLengthAutocomplete: controller
.mailboxDashBoardController
.minInputLengthAutocomplete,
expandMode: controller.ccAddressExpandMode.value,
controller: controller.ccEmailAddressController,
focusNode: controller.ccAddressFocusNode,
Expand All @@ -326,6 +341,9 @@ class ComposerView extends GetWidget<ComposerController> {
listEmailAddress: controller.listBccEmailAddress,
imagePaths: controller.imagePaths,
maxWidth: constraints.maxWidth,
minInputLengthAutocomplete: controller
.mailboxDashBoardController
.minInputLengthAutocomplete,
expandMode: controller.bccAddressExpandMode.value,
controller: controller.bccEmailAddressController,
focusNode: controller.bccAddressFocusNode,
Expand Down
27 changes: 27 additions & 0 deletions lib/features/composer/presentation/composer_view_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ class ComposerView extends GetWidget<ComposerController> {
listEmailAddress: controller.listToEmailAddress,
imagePaths: controller.imagePaths,
maxWidth: constraints.maxWidth,
minInputLengthAutocomplete: controller
.mailboxDashBoardController
.minInputLengthAutocomplete,
fromState: controller.fromRecipientState.value,
ccState: controller.ccRecipientState.value,
bccState: controller.bccRecipientState.value,
Expand All @@ -115,6 +118,9 @@ class ComposerView extends GetWidget<ComposerController> {
listEmailAddress: controller.listCcEmailAddress,
imagePaths: controller.imagePaths,
maxWidth: constraints.maxWidth,
minInputLengthAutocomplete: controller
.mailboxDashBoardController
.minInputLengthAutocomplete,
expandMode: controller.ccAddressExpandMode.value,
controller: controller.ccEmailAddressController,
focusNode: controller.ccAddressFocusNode,
Expand All @@ -138,6 +144,9 @@ class ComposerView extends GetWidget<ComposerController> {
listEmailAddress: controller.listBccEmailAddress,
imagePaths: controller.imagePaths,
maxWidth: constraints.maxWidth,
minInputLengthAutocomplete: controller
.mailboxDashBoardController
.minInputLengthAutocomplete,
expandMode: controller.bccAddressExpandMode.value,
controller: controller.bccEmailAddressController,
focusNode: controller.bccAddressFocusNode,
Expand Down Expand Up @@ -328,6 +337,9 @@ class ComposerView extends GetWidget<ComposerController> {
listEmailAddress: controller.listToEmailAddress,
imagePaths: controller.imagePaths,
maxWidth: constraints.maxWidth,
minInputLengthAutocomplete: controller
.mailboxDashBoardController
.minInputLengthAutocomplete,
fromState: controller.fromRecipientState.value,
ccState: controller.ccRecipientState.value,
bccState: controller.bccRecipientState.value,
Expand All @@ -354,6 +366,9 @@ class ComposerView extends GetWidget<ComposerController> {
listEmailAddress: controller.listCcEmailAddress,
imagePaths: controller.imagePaths,
maxWidth: constraints.maxWidth,
minInputLengthAutocomplete: controller
.mailboxDashBoardController
.minInputLengthAutocomplete,
expandMode: controller.ccAddressExpandMode.value,
controller: controller.ccEmailAddressController,
focusNode: controller.ccAddressFocusNode,
Expand All @@ -377,6 +392,9 @@ class ComposerView extends GetWidget<ComposerController> {
listEmailAddress: controller.listBccEmailAddress,
imagePaths: controller.imagePaths,
maxWidth: constraints.maxWidth,
minInputLengthAutocomplete: controller
.mailboxDashBoardController
.minInputLengthAutocomplete,
expandMode: controller.bccAddressExpandMode.value,
controller: controller.bccEmailAddressController,
focusNode: controller.bccAddressFocusNode,
Expand Down Expand Up @@ -600,6 +618,9 @@ class ComposerView extends GetWidget<ComposerController> {
listEmailAddress: controller.listToEmailAddress,
imagePaths: controller.imagePaths,
maxWidth: constraints.maxWidth,
minInputLengthAutocomplete: controller
.mailboxDashBoardController
.minInputLengthAutocomplete,
fromState: controller.fromRecipientState.value,
ccState: controller.ccRecipientState.value,
bccState: controller.bccRecipientState.value,
Expand All @@ -626,6 +647,9 @@ class ComposerView extends GetWidget<ComposerController> {
listEmailAddress: controller.listCcEmailAddress,
imagePaths: controller.imagePaths,
maxWidth: constraints.maxWidth,
minInputLengthAutocomplete: controller
.mailboxDashBoardController
.minInputLengthAutocomplete,
expandMode: controller.ccAddressExpandMode.value,
controller: controller.ccEmailAddressController,
focusNode: controller.ccAddressFocusNode,
Expand All @@ -649,6 +673,9 @@ class ComposerView extends GetWidget<ComposerController> {
listEmailAddress: controller.listBccEmailAddress,
imagePaths: controller.imagePaths,
maxWidth: constraints.maxWidth,
minInputLengthAutocomplete: controller
.mailboxDashBoardController
.minInputLengthAutocomplete,
expandMode: controller.bccAddressExpandMode.value,
controller: controller.bccEmailAddressController,
focusNode: controller.bccAddressFocusNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ class RecipientComposerWidget extends StatefulWidget {
final EdgeInsetsGeometry? margin;
final OnEnableAllRecipientsInputAction? onEnableAllRecipientsInputAction;
final bool isTestingForWeb;
final int minInputLengthAutocomplete;

const RecipientComposerWidget({
super.key,
required this.prefix,
required this.listEmailAddress,
required this.imagePaths,
required this.maxWidth,
this.minInputLengthAutocomplete = AppConfig.defaultMinInputLengthAutocomplete,
@visibleForTesting this.isTestingForWeb = false,
this.ccState = PrefixRecipientState.disabled,
this.bccState = PrefixRecipientState.disabled,
Expand Down Expand Up @@ -410,10 +412,13 @@ class _RecipientComposerWidgetState extends State<RecipientComposerWidget> {
}

final tmailSuggestion = List<SuggestionEmailAddress>.empty(growable: true);
if (processedQuery.length >= AppConfig.limitCharToStartSearch &&
if (processedQuery.length >= widget.minInputLengthAutocomplete &&
widget.onSuggestionEmailAddress != null) {
final listEmailAddress = await widget.onSuggestionEmailAddress!(processedQuery);
final listSuggestionEmailAddress = listEmailAddress.map((emailAddress) => _toSuggestionEmailAddress(emailAddress, _currentListEmailAddress));
final listSuggestionEmailAddress = listEmailAddress
.map((emailAddress) => _toSuggestionEmailAddress(
emailAddress,
_currentListEmailAddress));
tmailSuggestion.addAll(listSuggestionEmailAddress);
}

Expand Down
15 changes: 14 additions & 1 deletion lib/features/contact/presentation/contact_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class ContactController extends BaseController with AutoCompleteResultMixin {
VoidCallback? onDismissContactView;
StreamSubscription<String>? _deBouncerTimeStreamSubscription;

late int _minInputLengthAutocomplete;

@override
void onInit() {
super.onInit();
Expand All @@ -79,6 +81,7 @@ class ContactController extends BaseController with AutoCompleteResultMixin {
textInputSearchFocus.requestFocus();
}
}
_minInputLengthAutocomplete = _fetchMinInputLengthAutocomplete();
if (PlatformInfo.isMobile) {
Future.delayed(
const Duration(milliseconds: 500),
Expand All @@ -95,6 +98,7 @@ class ContactController extends BaseController with AutoCompleteResultMixin {
textInputSearchController.dispose();
_deBouncerTimeStreamSubscription?.cancel();
_deBouncerTime.cancel();
_accountId = null;
super.onClose();
}

Expand All @@ -115,7 +119,7 @@ class ContactController extends BaseController with AutoCompleteResultMixin {
Future<void> _handleDeBounceTimeSearchContact(String value) async {
final queryStringTrimmed = value.trim();

if (queryStringTrimmed.length < AppConfig.limitCharToStartSearch) {
if (queryStringTrimmed.length < _minInputLengthAutocomplete) {
searchStatus.value = SearchStatus.INACTIVE;
return;
}
Expand Down Expand Up @@ -235,4 +239,13 @@ class ContactController extends BaseController with AutoCompleteResultMixin {
FocusManager.instance.primaryFocus?.unfocus();
searchStatus.value = SearchStatus.INACTIVE;
}

int _fetchMinInputLengthAutocomplete() {
if (contactArguments.value?.session == null || _accountId == null) {
return AppConfig.defaultMinInputLengthAutocomplete;
}
return getMinInputLengthAutocomplete(
session: contactArguments.value!.session,
accountId: _accountId!);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import 'package:tmail_ui_user/features/email_recovery/presentation/model/email_r
import 'package:tmail_ui_user/features/email_recovery/presentation/model/email_recovery_time_type.dart';
import 'package:tmail_ui_user/features/manage_account/presentation/extensions/datetime_extension.dart';
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
import 'package:tmail_ui_user/main/utils/app_config.dart';

class EmailRecoveryController extends BaseController with DateRangePickerMixin {
GetAllAutoCompleteInteractor? _getAllAutoCompleteInteractor;
Expand Down Expand Up @@ -87,6 +88,15 @@ class EmailRecoveryController extends BaseController with DateRangePickerMixin {
super.onReady();
}

int get minInputLengthAutocomplete {
if (_session == null || _accountId == null) {
return AppConfig.defaultMinInputLengthAutocomplete;
}
return getMinInputLengthAutocomplete(
session: _session!,
accountId: _accountId!);
}

void _checkContactPermission() async {
final permissionStatus = await Permission.contacts.status;
if (permissionStatus.isGranted) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class EmailRecoveryFormDesktopBuilder extends GetWidget<EmailRecoveryController>
listEmailAddress: controller.listRecipients,
responsiveUtils: controller.responsiveUtils,
expandMode: controller.recipientsExpandMode.value,
minInputLengthAutocomplete: controller.minInputLengthAutocomplete,
textEditingController: controller.recipientsFieldInputController,
focusNode: controller.focusManager.recipientsFieldFocusNode,
nextFocusNode: controller.listSenders.length != 1
Expand All @@ -90,6 +91,7 @@ class EmailRecoveryFormDesktopBuilder extends GetWidget<EmailRecoveryController>
listEmailAddress: controller.listSenders,
responsiveUtils: controller.responsiveUtils,
expandMode: controller.senderExpandMode.value,
minInputLengthAutocomplete: controller.minInputLengthAutocomplete,
textEditingController: controller.senderFieldInputController,
focusNode: controller.focusManager.senderFieldFocusNode,
nextFocusNode: controller.focusManager.attachmentCheckboxFocusNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class EmailRecoveryFormMobileBuilder extends GetWidget<EmailRecoveryController>
focusNode: controller.focusManager.recipientsFieldFocusNode,
nextFocusNode: controller.focusManager.senderFieldFocusNode,
expandMode: controller.recipientsExpandMode.value,
minInputLengthAutocomplete: controller.minInputLengthAutocomplete,
textEditingController: controller.recipientsFieldInputController,
onShowFullListEmailAddressAction: controller.showFullEmailAddress,
onUpdateListEmailAddressAction: controller.updateListEmailAddress,
Expand All @@ -86,6 +87,7 @@ class EmailRecoveryFormMobileBuilder extends GetWidget<EmailRecoveryController>
focusNode: controller.focusManager.senderFieldFocusNode,
nextFocusNode: controller.focusManager.attachmentCheckboxFocusNode,
expandMode: controller.senderExpandMode.value,
minInputLengthAutocomplete: controller.minInputLengthAutocomplete,
textEditingController: controller.senderFieldInputController,
onShowFullListEmailAddressAction: controller.showFullEmailAddress,
onUpdateListEmailAddressAction: controller.updateListEmailAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class EmailRecoveryFormTabletBuilder extends GetWidget<EmailRecoveryController>
listEmailAddress: controller.listRecipients,
responsiveUtils: controller.responsiveUtils,
expandMode: controller.recipientsExpandMode.value,
minInputLengthAutocomplete: controller.minInputLengthAutocomplete,
textEditingController: controller.recipientsFieldInputController,
focusNode: controller.focusManager.recipientsFieldFocusNode,
nextFocusNode: controller.focusManager.senderFieldFocusNode,
Expand All @@ -88,6 +89,7 @@ class EmailRecoveryFormTabletBuilder extends GetWidget<EmailRecoveryController>
listEmailAddress: controller.listSenders,
responsiveUtils: controller.responsiveUtils,
expandMode: controller.senderExpandMode.value,
minInputLengthAutocomplete: controller.minInputLengthAutocomplete,
textEditingController: controller.senderFieldInputController,
focusNode: controller.focusManager.senderFieldFocusNode,
nextFocusNode: controller.focusManager.attachmentCheckboxFocusNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ class TextInputFieldSuggestionWidget extends StatefulWidget {
final OnDeleteTagAction? onDeleteTagAction;
final TextEditingController? textEditingController;
final VoidCallback? onCreateAction;
final int minInputLengthAutocomplete;

const TextInputFieldSuggestionWidget({
super.key,
required this.field,
required this.listEmailAddress,
required this.responsiveUtils,
this.expandMode = ExpandMode.EXPAND,
this.minInputLengthAutocomplete = AppConfig.defaultMinInputLengthAutocomplete,
this.focusNode,
this.keyTagEditor,
this.nextFocusNode,
Expand Down Expand Up @@ -325,7 +327,7 @@ class _TextInputFieldSuggestionWidgetState extends State<TextInputFieldSuggestio

final tmailSuggestion = List<SuggestionEmailAddress>.empty(growable: true);
if (
processedQuery.length >= AppConfig.limitCharToStartSearch
processedQuery.length >= widget.minInputLengthAutocomplete
&& widget.onSuggestionEmailAddress != null
) {
final listEmailAddress = await widget.onSuggestionEmailAddress!(processedQuery);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ class AdvancedFilterController extends BaseController {
_memorySearchFilter = searchFilter;
}

@visibleForTesting
MailboxDashBoardController get mailboxDashBoardController => _mailboxDashBoardController;

void _updateMemorySearchFilter({
Expand Down
Loading

0 comments on commit 2177082

Please sign in to comment.