Skip to content

Commit

Permalink
TF-3002 [MOBILE] Fix no result screen still show during search is i…
Browse files Browse the repository at this point in the history
…n progress
  • Loading branch information
dab246 committed Oct 3, 2024
1 parent 03768f8 commit 9431502
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class SearchEmailController extends BaseController
final selectionMode = Rx<SelectMode>(SelectMode.INACTIVE);
final emailSortOrderType = EmailSortOrderType.mostRecent.obs;
final suggestionSearchViewState = Rx<Either<Failure, Success>>(Right(UIState.idle));
final resultSearchViewState = Rx<Either<Failure, Success>>(Right(UIState.idle));

late Debouncer<String> _deBouncerTime;
late Worker dashBoardViewStateWorker;
Expand Down Expand Up @@ -175,6 +176,8 @@ class SearchEmailController extends BaseController
_searchMoreEmailsSuccess(success);
} else if (success is RefreshChangesSearchEmailSuccess) {
_refreshChangesSearchEmailsSuccess(success);
} else if (success is SearchingState) {
resultSearchViewState.value = Right(success);
}
}

Expand All @@ -188,6 +191,22 @@ class SearchEmailController extends BaseController
}
}

@override
void handleUrgentExceptionOnMobile({Failure? failure, Exception? exception}) {
super.handleUrgentExceptionOnMobile(failure: failure, exception: exception);
if (failure is SearchEmailFailure) {
_searchEmailsFailure(failure);
}
}

@override
void handleUrgentExceptionOnWeb({Failure? failure, Exception? exception}) {
super.handleUrgentExceptionOnWeb(failure: failure, exception: exception);
if (failure is SearchEmailFailure) {
_searchEmailsFailure(failure);
}
}

void _initializeDebounceTimeTextSearchChange() {
_deBouncerTime = Debouncer<String>(
const Duration(milliseconds: 500),
Expand Down Expand Up @@ -345,6 +364,7 @@ class SearchEmailController extends BaseController
textInputSearchFocus.unfocus();

if (session != null && accountId != null) {
resultSearchViewState.value = Right(SearchingState());
canSearchMore = true;
searchIsRunning.value = true;
cancelSelectionMode();
Expand Down Expand Up @@ -400,6 +420,8 @@ class SearchEmailController extends BaseController
isSearchEmailRunning: true
);

resultSearchViewState.value = Right(success);

if (resultSearchScrollController.hasClients) {
resultSearchScrollController.animateTo(
0,
Expand All @@ -410,6 +432,7 @@ class SearchEmailController extends BaseController

void _searchEmailsFailure(SearchEmailFailure failure) {
listResultSearch.clear();
resultSearchViewState.value = Left(failure);
}

void searchMoreEmailsAction() {
Expand Down
23 changes: 7 additions & 16 deletions lib/features/search/email/presentation/search_email_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ import 'package:tmail_ui_user/features/search/email/presentation/widgets/email_r
import 'package:tmail_ui_user/features/search/email/presentation/widgets/email_receive_time_cupertino_action_sheet_action_builder.dart';
import 'package:tmail_ui_user/features/search/email/presentation/widgets/email_sort_by_action_tile_widget.dart';
import 'package:tmail_ui_user/features/search/email/presentation/widgets/email_sort_by_cupertino_action_sheet_action_builder.dart';
import 'package:tmail_ui_user/features/search/email/presentation/widgets/empty_search_email_widget.dart';
import 'package:tmail_ui_user/features/search/email/presentation/widgets/search_email_loading_bar_widget.dart';
import 'package:tmail_ui_user/features/thread/domain/state/search_email_state.dart';
import 'package:tmail_ui_user/features/thread/domain/state/search_more_email_state.dart';
import 'package:tmail_ui_user/features/thread/presentation/styles/item_email_tile_styles.dart';
import 'package:tmail_ui_user/features/thread/presentation/widgets/email_tile_builder.dart'
if (dart.library.html) 'package:tmail_ui_user/features/thread/presentation/widgets/email_tile_web_builder.dart';
import 'package:tmail_ui_user/features/thread/presentation/widgets/empty_emails_widget.dart';
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';

class SearchEmailView extends GetWidget<SearchEmailController>
Expand Down Expand Up @@ -82,7 +81,7 @@ class SearchEmailView extends GetWidget<SearchEmailController>
_buildListSearchFilterAction(context),
Obx(() => SearchEmailLoadingBarWidget(
suggestionViewState: controller.suggestionSearchViewState.value,
resultSearchViewState: controller.viewState.value,
resultSearchViewState: controller.resultSearchViewState.value,
)),
Expanded(child: Obx(() {
if (controller.searchIsRunning.isFalse) {
Expand Down Expand Up @@ -110,7 +109,11 @@ class SearchEmailView extends GetWidget<SearchEmailController>
controller.listResultSearch
);
} else {
return _buildEmptyEmail(context);
return Obx(() => EmptySearchEmailWidget(
suggestionViewState: controller.suggestionSearchViewState.value,
resultSearchViewState: controller.resultSearchViewState.value,
isNetworkConnectionAvailable: controller.networkConnectionController.isNetworkConnectionAvailable(),
));
}
}
})),
Expand Down Expand Up @@ -613,18 +616,6 @@ class SearchEmailView extends GetWidget<SearchEmailController>
);
}

Widget _buildEmptyEmail(BuildContext context) {
return Obx(() => controller.viewState.value.fold(
(failure) => const SizedBox.shrink(),
(success) => success is! SearchingState
? EmptyEmailsWidget(
key: const Key('empty_search_email_view'),
isNetworkConnectionAvailable: controller.networkConnectionController.isNetworkConnectionAvailable(),
isSearchActive: true)
: const SizedBox.shrink())
);
}

Widget _buildListEmailBody(BuildContext context, List<PresentationEmail> listPresentationEmail) {
return NotificationListener<ScrollNotification>(
onNotification: (ScrollNotification scrollInfo) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart';
import 'package:flutter/material.dart';
import 'package:tmail_ui_user/features/thread/domain/state/search_email_state.dart';
import 'package:tmail_ui_user/features/thread/presentation/widgets/empty_emails_widget.dart';

class EmptySearchEmailWidget extends StatelessWidget {

final Either<Failure, Success> resultSearchViewState;
final Either<Failure, Success> suggestionViewState;
final bool isNetworkConnectionAvailable;

const EmptySearchEmailWidget({
super.key,
required this.resultSearchViewState,
required this.suggestionViewState,
required this.isNetworkConnectionAvailable,
});

@override
Widget build(BuildContext context) {
return resultSearchViewState.fold(
(failure) => _suggestionViewStateToUI(suggestionViewState),
(success) {
if (success is SearchingState) {
return const SizedBox.shrink();
} else {
return _suggestionViewStateToUI(suggestionViewState);
}
}
);
}

Widget _suggestionViewStateToUI(Either<Failure, Success> viewState) {
return viewState.fold(
(failure) => EmptyEmailsWidget(
key: const Key('empty_search_email_view'),
isNetworkConnectionAvailable: isNetworkConnectionAvailable,
isSearchActive: true
),
(success) {
if (success is LoadingState) {
return const SizedBox.shrink();
} else {
return EmptyEmailsWidget(
key: const Key('empty_search_email_view'),
isNetworkConnectionAvailable: isNetworkConnectionAvailable,
isSearchActive: true
);
}
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,31 @@ class SearchEmailLoadingBarWidget extends StatelessWidget with AppLoaderMixin {
@override
Widget build(BuildContext context) {
return resultSearchViewState.fold(
(failure) {
return suggestionViewState.fold(
(failure) => const SizedBox.shrink(),
(success) => success is LoadingState
? Padding(
padding: const EdgeInsets.symmetric(vertical: 16),
child: loadingWidget
)
: const SizedBox.shrink()
);
},
(failure) => _suggestionViewStateToUI(suggestionViewState),
(success) {
if (success is SearchingState) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 16),
child: loadingWidget
);
} else {
return suggestionViewState.fold(
(failure) => const SizedBox.shrink(),
(success) => success is LoadingState
? Padding(
padding: const EdgeInsets.symmetric(vertical: 16),
child: loadingWidget
)
: const SizedBox.shrink()
return _suggestionViewStateToUI(suggestionViewState);
}
}
);
}

Widget _suggestionViewStateToUI(Either<Failure, Success> viewState) {
return viewState.fold(
(failure) => const SizedBox.shrink(),
(success) {
if (success is LoadingState) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 16),
child: loadingWidget
);
} else {
return const SizedBox.shrink();
}
}
);
Expand Down

0 comments on commit 9431502

Please sign in to comment.