Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TF-3408 Remove limit result in autocomplete #3431

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion contact/lib/data/network/contact_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class ContactAPI {
autoCompletePattern.accountId!,
ContactFilter(autoCompletePattern.word));

autoCompleteMethod.addLimit(UnsignedInt(autoCompletePattern.limit ?? 5));
if (autoCompletePattern.limit != null) {
autoCompleteMethod.addLimit(UnsignedInt(autoCompletePattern.limit!));
}

final autoCompleteInvocation = requestBuilder.invocation(autoCompleteMethod);
final response = await (requestBuilder
Expand Down
3 changes: 0 additions & 3 deletions core/lib/presentation/views/text/rich_text_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class RichTextBuilder extends StatefulWidget {
final TextStyle styleWord;
final String? preMarkedText;
final bool ensureHighlightVisible;
final bool? softWrap;

const RichTextBuilder({
super.key,
Expand All @@ -18,7 +17,6 @@ class RichTextBuilder extends StatefulWidget {
required this.styleWord,
this.preMarkedText,
this.ensureHighlightVisible = false,
this.softWrap,
});

@override
Expand Down Expand Up @@ -65,7 +63,6 @@ class _RichTextBuilderState extends State<RichTextBuilder> with AutomaticKeepAli
),
style: widget.styleOrigin,
maxLines: 1,
softWrap: widget.softWrap,
hoangdat marked this conversation as resolved.
Show resolved Hide resolved
overflow: TextOverflow.ellipsis
);

Expand Down
5 changes: 3 additions & 2 deletions lib/features/composer/presentation/composer_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1110,14 +1110,15 @@ class ComposerController extends BaseController
}
}

Future<List<EmailAddress>> getAutoCompleteSuggestion(String queryString) async {
log('ComposerController::getAutoCompleteSuggestion(): $queryString | $_contactSuggestionSource');
Future<List<EmailAddress>> getAutoCompleteSuggestion(String queryString, {int? limit}) async {
log('ComposerController::getAutoCompleteSuggestion():queryString = $queryString | limit = $limit | $_contactSuggestionSource');
_getAllAutoCompleteInteractor = getBinding<GetAllAutoCompleteInteractor>();
_getAutoCompleteInteractor = getBinding<GetAutoCompleteInteractor>();
_getDeviceContactSuggestionsInteractor = getBinding<GetDeviceContactSuggestionsInteractor>();

final autoCompletePattern = AutoCompletePattern(
word: queryString,
limit: limit,
accountId: mailboxDashBoardController.accountId.value);

if (_contactSuggestionSource == ContactSuggestionSource.all) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ComposerStyle {
static const double radius = 28;
static const double keyboardToolBarHeight = 200;
static const double popupMenuRadius = 8;
static const double suggestionItemHeight = 60;

static const Color borderColor = AppColor.colorLineComposer;
static const Color backgroundEditorColor = Colors.white;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@

import 'package:core/presentation/extensions/color_extension.dart';
import 'package:flutter/material.dart';
import 'package:tmail_ui_user/features/composer/presentation/styles/composer_style.dart';

class RecipientComposerWidgetStyle {
static const double deleteRecipientFieldIconSize = 20;
static const double space = 8;
static const double enableBorderRadius = 10;
static const double suggestionsBoxElevation = 20.0;
static const double suggestionsBoxRadius = 20;
static const double suggestionsBoxMaxHeight = 350;
static const double suggestionsBoxMaxHeight = 300;
static const double suggestionBoxWidth = 300;
static const double suggestionBoxItemHeight = ComposerStyle.suggestionItemHeight;
static const double minTextFieldWidth = 20;
static const double tagSpacing = 8;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class RecipientSuggestionItemWidgetStyle {
static const double selectedIconSize = 24;

static const EdgeInsetsGeometry suggestionDuplicatedMargin = EdgeInsets.all(8.0);
static const EdgeInsetsGeometry labelDuplicatedPadding = EdgeInsets.symmetric(horizontal: 8.0);
static const EdgeInsetsGeometry labelPadding = EdgeInsets.symmetric(horizontal: 16.0);

static const TextStyle labelTextStyle = TextStyle(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import 'package:tmail_ui_user/features/composer/presentation/widgets/recipient_t
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
import 'package:tmail_ui_user/main/utils/app_config.dart';

typedef OnSuggestionEmailAddress = Future<List<EmailAddress>> Function(String word);
typedef OnSuggestionEmailAddress = Future<List<EmailAddress>> Function(String word, {int? limit});
typedef OnUpdateListEmailAddressAction = void Function(PrefixEmailAddress prefix, List<EmailAddress> newData);
typedef OnAddEmailAddressTypeAction = void Function(PrefixEmailAddress prefix);
typedef OnDeleteEmailAddressTypeAction = void Function(PrefixEmailAddress prefix);
Expand Down Expand Up @@ -180,6 +180,7 @@ class _RecipientComposerWidgetState extends State<RecipientComposerWidget> {
suggestionsBoxBackgroundColor: RecipientComposerWidgetStyle.suggestionsBoxBackgroundColor,
suggestionsBoxRadius: RecipientComposerWidgetStyle.suggestionsBoxRadius,
suggestionsBoxMaxHeight: RecipientComposerWidgetStyle.suggestionsBoxMaxHeight,
suggestionItemHeight: RecipientComposerWidgetStyle.suggestionBoxItemHeight,
suggestionBoxWidth: _getSuggestionBoxWidth(widget.maxWidth),
textStyle: RecipientComposerWidgetStyle.inputTextStyle,
onFocusTagAction: (focused) => _handleFocusTagAction.call(focused, stateSetter),
Expand Down Expand Up @@ -213,7 +214,13 @@ class _RecipientComposerWidgetState extends State<RecipientComposerWidget> {
);
},
onTagChanged: (value) => _handleOnTagChangeAction.call(value, stateSetter),
findSuggestions: _findSuggestions,
findSuggestions: (queryString) => _findSuggestions(
queryString,
limit: AppConfig.defaultLimitAutocomplete,
),
isLoadMoreOnlyOnce: true,
isLoadMoreReplaceAllOld: false,
loadMoreSuggestions: _findSuggestions,
useDefaultHighlight: false,
suggestionBuilder: (context, tagEditorState, suggestionEmailAddress, index, length, highlight, suggestionValid) {
return RecipientSuggestionItemWidget(
Expand Down Expand Up @@ -264,6 +271,7 @@ class _RecipientComposerWidgetState extends State<RecipientComposerWidget> {
suggestionsBoxBackgroundColor: RecipientComposerWidgetStyle.suggestionsBoxBackgroundColor,
suggestionsBoxRadius: RecipientComposerWidgetStyle.suggestionsBoxRadius,
suggestionsBoxMaxHeight: RecipientComposerWidgetStyle.suggestionsBoxMaxHeight,
suggestionItemHeight: RecipientComposerWidgetStyle.suggestionBoxItemHeight,
suggestionBoxWidth: _getSuggestionBoxWidth(widget.maxWidth),
textStyle: RecipientComposerWidgetStyle.inputTextStyle,
onFocusTagAction: (focused) => _handleFocusTagAction.call(focused, stateSetter),
Expand Down Expand Up @@ -297,7 +305,13 @@ class _RecipientComposerWidgetState extends State<RecipientComposerWidget> {
);
},
onTagChanged: (value) => _handleOnTagChangeAction.call(value, stateSetter),
findSuggestions: _findSuggestions,
findSuggestions: (queryString) => _findSuggestions(
queryString,
limit: AppConfig.defaultLimitAutocomplete,
),
isLoadMoreOnlyOnce: true,
isLoadMoreReplaceAllOld: false,
loadMoreSuggestions: _findSuggestions,
useDefaultHighlight: false,
suggestionBuilder: (context, tagEditorState, suggestionEmailAddress, index, length, highlight, suggestionValid) {
return RecipientSuggestionItemWidget(
Expand Down Expand Up @@ -402,7 +416,7 @@ class _RecipientComposerWidgetState extends State<RecipientComposerWidget> {
? _currentListEmailAddress.sublist(0, 1)
: _currentListEmailAddress;

FutureOr<List<SuggestionEmailAddress>> _findSuggestions(String query) async {
FutureOr<List<SuggestionEmailAddress>> _findSuggestions(String query, {int? limit}) async {
if (_gapBetweenTagChangedAndFindSuggestion?.isActive ?? false) {
return [];
}
Expand All @@ -415,7 +429,10 @@ class _RecipientComposerWidgetState extends State<RecipientComposerWidget> {
final tmailSuggestion = List<SuggestionEmailAddress>.empty(growable: true);
if (processedQuery.length >= widget.minInputLengthAutocomplete &&
widget.onSuggestionEmailAddress != null) {
final listEmailAddress = await widget.onSuggestionEmailAddress!(processedQuery);
final listEmailAddress = await widget.onSuggestionEmailAddress!(
processedQuery,
limit: limit,
);
final listSuggestionEmailAddress = listEmailAddress
.map((emailAddress) => _toSuggestionEmailAddress(
emailAddress,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@

import 'package:core/presentation/extensions/color_extension.dart';
import 'package:core/presentation/resources/image_paths.dart';
import 'package:core/presentation/views/text/rich_text_builder.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
import 'package:model/extensions/email_address_extension.dart';
import 'package:super_tag_editor/widgets/rich_text_widget.dart';
import 'package:tmail_ui_user/features/composer/presentation/model/suggestion_email_address.dart';
import 'package:tmail_ui_user/features/composer/presentation/styles/composer_style.dart';
import 'package:tmail_ui_user/features/composer/presentation/styles/recipient_suggestion_item_widget_style.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/widgets/advanced_search/avatar_suggestion_item_widget.dart';

Expand Down Expand Up @@ -38,59 +40,91 @@ class RecipientSuggestionItemWidget extends StatelessWidget {
margin: RecipientSuggestionItemWidgetStyle.suggestionDuplicatedMargin,
decoration: const BoxDecoration(
color: AppColor.colorBgMenuItemDropDownSelected,
borderRadius: BorderRadius.all(Radius.circular(RecipientSuggestionItemWidgetStyle.radius))
borderRadius: BorderRadius.all(Radius.circular(RecipientSuggestionItemWidgetStyle.radius)),
),
height: ComposerStyle.suggestionItemHeight,
child: Material(
type: MaterialType.transparency,
child: ListTile(
contentPadding: RecipientSuggestionItemWidgetStyle.labelDuplicatedPadding,
leading: AvatarSuggestionItemWidget(emailAddress: emailAddress),
title: RichTextWidget(
textOrigin: emailAddress.asString(),
wordSearched: suggestionValid ?? '',
overflow: TextOverflow.ellipsis,
),
subtitle: emailAddress.displayName.isNotEmpty
? RichTextWidget(
textOrigin: emailAddress.emailAddress,
wordSearched: suggestionValid ?? '',
overflow: TextOverflow.ellipsis,
styleTextOrigin: RecipientSuggestionItemWidgetStyle.labelTextStyle,
styleWordSearched: RecipientSuggestionItemWidgetStyle.labelHighlightTextStyle
)
: null,
trailing: SvgPicture.asset(
imagePaths.icFilterSelected,
width: RecipientSuggestionItemWidgetStyle.selectedIconSize,
height: RecipientSuggestionItemWidgetStyle.selectedIconSize,
fit: BoxFit.fill
child: InkWell(
onTap: () {},
child: Padding(
padding: RecipientSuggestionItemWidgetStyle.labelPadding,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
AvatarSuggestionItemWidget(emailAddress: emailAddress),
const SizedBox(width: 8),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
RichTextWidget(
textOrigin: emailAddress.asString(),
wordSearched: suggestionValid ?? '',
overflow: TextOverflow.ellipsis,
),
if (emailAddress.displayName.isNotEmpty)
RichTextBuilder(
textOrigin: emailAddress.emailAddress,
wordToStyle: suggestionValid ?? '',
styleOrigin: RecipientSuggestionItemWidgetStyle.labelTextStyle,
styleWord: RecipientSuggestionItemWidgetStyle.labelHighlightTextStyle,
),
],
),
),
const SizedBox(width: 8),
SvgPicture.asset(
imagePaths.icFilterSelected,
width: RecipientSuggestionItemWidgetStyle.selectedIconSize,
height: RecipientSuggestionItemWidgetStyle.selectedIconSize,
fit: BoxFit.fill,
),
],
),
),
),
)
),
);
} else {
return Container(
color: highlight ? AppColor.colorItemSelected : Colors.white,
height: ComposerStyle.suggestionItemHeight,
child: Material(
type: MaterialType.transparency,
child: ListTile(
contentPadding: RecipientSuggestionItemWidgetStyle.labelPadding,
leading: AvatarSuggestionItemWidget(emailAddress: emailAddress),
title: RichTextWidget(
textOrigin: emailAddress.asString(),
wordSearched: suggestionValid ?? '',
overflow: TextOverflow.ellipsis,
),
subtitle: emailAddress.displayName.isNotEmpty
? RichTextWidget(
textOrigin: emailAddress.emailAddress,
wordSearched: suggestionValid ?? '',
overflow: TextOverflow.ellipsis,
styleTextOrigin: RecipientSuggestionItemWidgetStyle.labelTextStyle,
styleWordSearched: RecipientSuggestionItemWidgetStyle.labelHighlightTextStyle
)
: null,
child: InkWell(
onTap: () => onSelectedAction?.call(emailAddress),
child: Padding(
padding: RecipientSuggestionItemWidgetStyle.labelPadding,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
AvatarSuggestionItemWidget(emailAddress: emailAddress),
const SizedBox(width: 8),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
RichTextWidget(
textOrigin: emailAddress.asString(),
wordSearched: suggestionValid ?? '',
overflow: TextOverflow.ellipsis,
),
if (emailAddress.displayName.isNotEmpty)
RichTextBuilder(
textOrigin: emailAddress.emailAddress,
wordToStyle: suggestionValid ?? '',
styleOrigin: RecipientSuggestionItemWidgetStyle.labelTextStyle,
styleWord: RecipientSuggestionItemWidgetStyle.labelHighlightTextStyle,
),
],
),
),
],
),
),
),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,32 @@ import 'package:core/presentation/utils/style_utils.dart';
import 'package:core/presentation/views/avatar/gradient_circle_avatar_icon.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
import 'package:model/extensions/email_address_extension.dart';
import 'package:tmail_ui_user/features/composer/presentation/model/suggestion_email_address.dart';
import 'package:tmail_ui_user/features/composer/presentation/styles/composer_style.dart';

typedef SelectedContactCallbackAction = Function(EmailAddress contactSelected);

class ContactSuggestionBoxItem extends StatelessWidget {

final ImagePaths imagePaths;
final SuggestionEmailAddress suggestionEmailAddress;
final SelectedContactCallbackAction? selectedContactCallbackAction;
final EdgeInsets? padding;
final ShapeBorder? shapeBorder;

const ContactSuggestionBoxItem(this.suggestionEmailAddress, {
Key? key,
this.padding,
this.shapeBorder,
this.selectedContactCallbackAction
}) : super(key: key);
const ContactSuggestionBoxItem(
this.suggestionEmailAddress,
this.imagePaths,
{
Key? key,
this.shapeBorder,
this.selectedContactCallbackAction,
}
) : super(key: key);

@override
Widget build(BuildContext context) {
final imagePaths = Get.find<ImagePaths>();

final itemChild = Row(children: [
GradientCircleAvatarIcon(
colors: suggestionEmailAddress.emailAddress.avatarColors,
Expand Down Expand Up @@ -82,17 +83,19 @@ class ContactSuggestionBoxItem extends StatelessWidget {
child: InkWell(
onTap: () => selectedContactCallbackAction?.call(suggestionEmailAddress.emailAddress),
customBorder: shapeBorder,
child: Padding(
padding: padding ?? const EdgeInsets.all(12),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12),
height: ComposerStyle.suggestionItemHeight,
child: itemChild,
),
),
);
} else {
return Material(
color: Colors.transparent,
child: Padding(
padding: padding ?? const EdgeInsets.all(12),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12),
height: ComposerStyle.suggestionItemHeight,
child: itemChild,
),
);
Expand Down
Loading
Loading