TF-4004 Add loading bar for email rule filter view
This commit is contained in:
@@ -2,6 +2,8 @@ import 'package:core/presentation/state/failure.dart';
|
|||||||
import 'package:core/presentation/state/success.dart';
|
import 'package:core/presentation/state/success.dart';
|
||||||
import 'package:rule_filter/rule_filter/tmail_rule.dart';
|
import 'package:rule_filter/rule_filter/tmail_rule.dart';
|
||||||
|
|
||||||
|
class GettingAllRules extends LoadingState {}
|
||||||
|
|
||||||
class GetAllRulesSuccess extends UIState {
|
class GetAllRulesSuccess extends UIState {
|
||||||
final List<TMailRule>? rules;
|
final List<TMailRule>? rules;
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class GetAllRulesInteractor {
|
|||||||
|
|
||||||
Stream<Either<Failure, Success>> execute(AccountId accountId) async* {
|
Stream<Either<Failure, Success>> execute(AccountId accountId) async* {
|
||||||
try {
|
try {
|
||||||
yield Right<Failure, Success>(LoadingState());
|
yield Right(GettingAllRules());
|
||||||
final rulesResponse = await _ruleFilterRepository.getAllTMailRule(accountId);
|
final rulesResponse = await _ruleFilterRepository.getAllTMailRule(accountId);
|
||||||
yield Right(GetAllRulesSuccess(rulesResponse));
|
yield Right(GetAllRulesSuccess(rulesResponse));
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
import 'package:core/presentation/state/failure.dart';
|
||||||
import 'package:core/presentation/state/success.dart';
|
import 'package:core/presentation/state/success.dart';
|
||||||
import 'package:core/utils/app_logger.dart';
|
import 'package:core/utils/app_logger.dart';
|
||||||
import 'package:core/utils/platform_info.dart';
|
import 'package:core/utils/platform_info.dart';
|
||||||
|
import 'package:dartz/dartz.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||||
@@ -39,6 +41,11 @@ class EmailRulesController extends BaseController {
|
|||||||
|
|
||||||
final listEmailRule = <TMailRule>[].obs;
|
final listEmailRule = <TMailRule>[].obs;
|
||||||
|
|
||||||
|
bool get isLoading => viewState.value.fold(
|
||||||
|
(failure) => false,
|
||||||
|
(success) => success is GettingAllRules,
|
||||||
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
@@ -75,6 +82,15 @@ class EmailRulesController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void handleFailureViewState(Failure failure) {
|
||||||
|
if (failure is GetAllRulesFailure) {
|
||||||
|
listEmailRule.clear();
|
||||||
|
} else {
|
||||||
|
super.handleFailureViewState(failure);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> goToCreateNewRule() async {
|
Future<void> goToCreateNewRule() async {
|
||||||
final accountId = _accountDashBoardController.accountId.value;
|
final accountId = _accountDashBoardController.accountId.value;
|
||||||
final session = _accountDashBoardController.sessionCurrent;
|
final session = _accountDashBoardController.sessionCurrent;
|
||||||
@@ -216,6 +232,8 @@ class EmailRulesController extends BaseController {
|
|||||||
void _getAllRules() {
|
void _getAllRules() {
|
||||||
if (_getAllRulesInteractor != null) {
|
if (_getAllRulesInteractor != null) {
|
||||||
consumeState(_getAllRulesInteractor!.execute(_accountDashBoardController.accountId.value!));
|
consumeState(_getAllRulesInteractor!.execute(_accountDashBoardController.accountId.value!));
|
||||||
|
} else {
|
||||||
|
consumeState(Stream.value(Left(GetAllRulesFailure(null))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'package:core/presentation/utils/theme_utils.dart';
|
import 'package:core/presentation/utils/theme_utils.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
import 'package:tmail_ui_user/features/base/mixin/app_loader_mixin.dart';
|
||||||
import 'package:tmail_ui_user/features/manage_account/presentation/base/setting_detail_view_builder.dart';
|
import 'package:tmail_ui_user/features/manage_account/presentation/base/setting_detail_view_builder.dart';
|
||||||
import 'package:tmail_ui_user/features/manage_account/presentation/email_rules/email_rules_controller.dart';
|
import 'package:tmail_ui_user/features/manage_account/presentation/email_rules/email_rules_controller.dart';
|
||||||
import 'package:tmail_ui_user/features/manage_account/presentation/email_rules/widgets/add_rule_button_widget.dart';
|
import 'package:tmail_ui_user/features/manage_account/presentation/email_rules/widgets/add_rule_button_widget.dart';
|
||||||
@@ -13,7 +14,8 @@ import 'package:tmail_ui_user/features/manage_account/presentation/model/email_r
|
|||||||
import 'package:tmail_ui_user/features/manage_account/presentation/widgets/setting_explanation_widget.dart';
|
import 'package:tmail_ui_user/features/manage_account/presentation/widgets/setting_explanation_widget.dart';
|
||||||
import 'package:tmail_ui_user/features/manage_account/presentation/widgets/setting_header_widget.dart';
|
import 'package:tmail_ui_user/features/manage_account/presentation/widgets/setting_header_widget.dart';
|
||||||
|
|
||||||
class EmailRulesView extends GetWidget<EmailRulesController> {
|
class EmailRulesView extends GetWidget<EmailRulesController>
|
||||||
|
with AppLoaderMixin {
|
||||||
const EmailRulesView({Key? key}) : super(key: key);
|
const EmailRulesView({Key? key}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -92,13 +94,25 @@ class EmailRulesView extends GetWidget<EmailRulesController> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Obx(
|
||||||
|
() => controller.isLoading
|
||||||
|
? Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 8.0),
|
||||||
|
child: loadingWidget,
|
||||||
|
)
|
||||||
|
: const SizedBox.shrink(),
|
||||||
|
),
|
||||||
Obx(() {
|
Obx(() {
|
||||||
if (controller.listEmailRule.isEmpty) {
|
if (controller.listEmailRule.isEmpty) {
|
||||||
return NoRulesWidget(
|
if (controller.isLoading) {
|
||||||
imagePaths: controller.imagePaths,
|
return const SizedBox.shrink();
|
||||||
responsiveUtils: controller.responsiveUtils,
|
} else {
|
||||||
onAddRuleAction: controller.goToCreateNewRule,
|
return NoRulesWidget(
|
||||||
);
|
imagePaths: controller.imagePaths,
|
||||||
|
responsiveUtils: controller.responsiveUtils,
|
||||||
|
onAddRuleAction: controller.goToCreateNewRule,
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return Expanded(
|
return Expanded(
|
||||||
child: ListEmailRulesWidget(
|
child: ListEmailRulesWidget(
|
||||||
|
|||||||
Reference in New Issue
Block a user