TF-1613 Implement handleSuccessViewState and handleFailureViewState for all controller
(cherry picked from commit 35e727e795bb3c44cc9c47e02542b5bdc3955fdd)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:core/core.dart';
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:tmail_ui_user/features/session/domain/repository/session_repository.dart';
|
||||
import 'package:tmail_ui_user/features/session/domain/state/get_session_state.dart';
|
||||
@@ -8,12 +9,12 @@ class GetSessionInteractor {
|
||||
|
||||
GetSessionInteractor(this.sessionRepository);
|
||||
|
||||
Future<Either<Failure, Success>> execute() async {
|
||||
Stream<Either<Failure, Success>> execute() async* {
|
||||
try {
|
||||
final session = await sessionRepository.getSession();
|
||||
return Right<Failure, Success>(GetSessionSuccess(session));
|
||||
yield Right<Failure, Success>(GetSessionSuccess(session));
|
||||
} catch (e) {
|
||||
return Left<Failure, Success>(GetSessionFailure(e));
|
||||
yield Left<Failure, Success>(GetSessionFailure(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:core/data/network/config/dynamic_url_interceptors.dart';
|
||||
import 'package:core/presentation/extensions/uri_extension.dart';
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/presentation/utils/app_toast.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:get/get.dart';
|
||||
@@ -49,6 +50,23 @@ class SessionController extends ReloadableController {
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void handleFailureViewState(Failure failure) {
|
||||
super.handleFailureViewState(failure);
|
||||
if (failure is GetSessionFailure) {
|
||||
_handleSessionFailure(failure);
|
||||
_goToLogin();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void handleSuccessViewState(Success success) {
|
||||
super.handleSuccessViewState(success);
|
||||
if (success is GetSessionSuccess) {
|
||||
_goToMailboxDashBoard(success);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void handleReloaded(Session session) {
|
||||
pushAndPop(
|
||||
@@ -57,15 +75,7 @@ class SessionController extends ReloadableController {
|
||||
}
|
||||
|
||||
void _getSession() async {
|
||||
await _getSessionInteractor.execute()
|
||||
.then((response) => response.fold(
|
||||
(failure) {
|
||||
_handleSessionFailure(failure);
|
||||
_goToLogin();
|
||||
},
|
||||
(success) => success is GetSessionSuccess
|
||||
? _goToMailboxDashBoard(success)
|
||||
: _goToLogin()));
|
||||
consumeState(_getSessionInteractor.execute());
|
||||
}
|
||||
|
||||
void _handleSessionFailure(Failure failure) {
|
||||
@@ -93,7 +103,7 @@ class SessionController extends ReloadableController {
|
||||
}
|
||||
|
||||
bool _checkUrlError(dynamic sessionException) {
|
||||
return sessionException is ConnectError || sessionException is BadGateway;
|
||||
return sessionException is ConnectError || sessionException is BadGateway || sessionException is SocketError;
|
||||
}
|
||||
|
||||
void _goToLogin() async {
|
||||
@@ -121,7 +131,4 @@ class SessionController extends ReloadableController {
|
||||
_goToLogin();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void onDone() {}
|
||||
}
|
||||
Reference in New Issue
Block a user