TF-2064 Handle limit storage to show warning banner

(cherry picked from commit 3e36cebd5cbe880f9832c62463e71979e15e1741)
This commit is contained in:
dab246
2023-08-04 21:43:33 +07:00
committed by Dat Vu
parent 3aa2b91a89
commit a2875ea921
17 changed files with 78 additions and 293 deletions
@@ -0,0 +1,16 @@
import 'package:core/utils/app_logger.dart';
import 'package:jmap_dart_client/jmap/quotas/data_types.dart';
import 'package:jmap_dart_client/jmap/quotas/quota.dart';
extension ListQuotasExtensions on List<Quota> {
Quota? get octetsQuota {
try {
return firstWhere((quota) => quota.resourceType == ResourceType.octets);
} catch(e) {
logError('ListQuotasExtensions::octetsQuota: Not found octets quota');
return null;
}
}
}
@@ -1,30 +0,0 @@
import 'package:equatable/equatable.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/id.dart';
import 'package:jmap_dart_client/jmap/core/state.dart';
import 'package:jmap_dart_client/jmap/quotas/quota.dart';
class QuotasResponse with EquatableMixin {
final AccountId accountId;
final State state;
final List<Quota> quotas;
final List<Id>? notFound;
QuotasResponse({
required this.accountId,
required this.state,
required this.quotas,
this.notFound,
});
bool hasData() {
return quotas.isNotEmpty;
}
@override
List<Object?> get props => [
quotas,
state,
notFound,
];
}
@@ -1,6 +1,6 @@
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:tmail_ui_user/features/quotas/domain/model/quotas_response.dart';
import 'package:jmap_dart_client/jmap/quotas/quota.dart';
abstract class QuotasRepository {
Future<QuotasResponse> getQuotas(AccountId accountId);
Future<List<Quota>> getQuotas(AccountId accountId);
}
@@ -1,18 +1,16 @@
import 'package:core/core.dart';
import 'package:jmap_dart_client/jmap/core/state.dart';
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:jmap_dart_client/jmap/quotas/quota.dart';
class GetQuotasLoading extends LoadingState {}
class GetQuotasSuccess extends UIState {
final List<Quota> quotas;
final State? state;
GetQuotasSuccess(this.quotas, this.state);
GetQuotasSuccess(this.quotas);
@override
List<Object?> get props => [
quotas,
state,
];
List<Object?> get props => [quotas];
}
class GetQuotasFailure extends FeatureFailure {
@@ -1,6 +1,5 @@
import 'dart:core';
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:jmap_dart_client/jmap/account_id.dart';
import 'package:tmail_ui_user/features/quotas/domain/repository/quotas_repository.dart';
@@ -13,9 +12,9 @@ class GetQuotasInteractor {
Stream<Either<Failure, Success>> execute(AccountId accountId) async* {
try {
yield Right<Failure, Success>(LoadingState());
final response = await quotasRepository.getQuotas(accountId);
yield Right(GetQuotasSuccess(response.quotas, response.state));
yield Right<Failure, Success>(GetQuotasLoading());
final listQuotas = await quotasRepository.getQuotas(accountId);
yield Right(GetQuotasSuccess(listQuotas));
} catch (exception) {
yield Left(GetQuotasFailure(exception));
}