forked from eatvio/eatvio_app
feat(app): refactoring of sentry using, feat(become_consultant): fixed possible infinite loading, feat(push_notifications): fixed push navigation from paid plan push
This commit is contained in:
@@ -8,6 +8,7 @@ import 'package:eatvio_app/features/plans/models/chosen_plan_model.dart';
|
||||
import 'package:eatvio_app/features/plans/presentation/cubit/about_plan_state.dart';
|
||||
import 'package:eatvio_app/features/plans/repositories/plan_repository.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:eatvio_app/core/error_reporting/report_from.dart';
|
||||
|
||||
class AboutPlanCubit extends Cubit<AboutPlanState> {
|
||||
final PlanRepository planRepository;
|
||||
@@ -21,6 +22,7 @@ class AboutPlanCubit extends Cubit<AboutPlanState> {
|
||||
}
|
||||
emit(state.copyWith(planModel: plan, error: null));
|
||||
} catch (e, stackTrace) {
|
||||
await reportFrom(e, stackTrace, this);
|
||||
log(e.toString(), stackTrace: stackTrace);
|
||||
emit(state.copyWith(error: e.toString(), isLoading: false));
|
||||
}
|
||||
@@ -32,6 +34,7 @@ class AboutPlanCubit extends Cubit<AboutPlanState> {
|
||||
final plan = await planRepository.getPlan(slug);
|
||||
emit(state.copyWith(planModel: plan, error: null, isLoading: false));
|
||||
} catch (e, stackTrace) {
|
||||
await reportFrom(e, stackTrace, this);
|
||||
log(e.toString(), stackTrace: stackTrace);
|
||||
emit(state.copyWith(error: e.toString(), isLoading: false));
|
||||
}
|
||||
@@ -59,7 +62,8 @@ class AboutPlanCubit extends Cubit<AboutPlanState> {
|
||||
EasyDebounce.debounce('like_plan_$slug', const Duration(seconds: 1), () async {
|
||||
try {
|
||||
await planRepository.likePlan(slug);
|
||||
} catch (e) {
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
log(e.toString());
|
||||
if (index != null) {
|
||||
planRepository.emitLikesStateToFeed(LikesState(wasLikedByMe: currentPlan.wasLikedByMe, totalLikes: currentPlan.totalLikes, index: index));
|
||||
@@ -80,7 +84,8 @@ class AboutPlanCubit extends Cubit<AboutPlanState> {
|
||||
EasyDebounce.debounce('add_or_remove_plan_to_favorites', const Duration(seconds: 1), () async {
|
||||
try {
|
||||
await planRepository.addToFavorite(slug);
|
||||
} catch (e) {
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
log(e.toString());
|
||||
showErrorToast('Произошла ошибка. Попробуйте ещё раз через некоторое время');
|
||||
if (index != null) {
|
||||
@@ -102,7 +107,8 @@ class AboutPlanCubit extends Cubit<AboutPlanState> {
|
||||
EasyDebounce.debounce('add_or_remove_plan_to_favorites', const Duration(seconds: 1), () async {
|
||||
try {
|
||||
await planRepository.removeFromFavorite(slug);
|
||||
} catch (e) {
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
log(e.toString());
|
||||
showErrorToast('Произошла ошибка. Попробуйте ещё раз через некоторое время');
|
||||
if (index != null) {
|
||||
@@ -123,11 +129,13 @@ class AboutPlanCubit extends Cubit<AboutPlanState> {
|
||||
return (await planRepository.chosePlan(slug, body), null);
|
||||
}
|
||||
} on DioException catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
if (e.response?.statusCode == 400) {
|
||||
return (null, 'hasPlan');
|
||||
}
|
||||
log(e.toString(), stackTrace: st);
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
log(e.toString(), stackTrace: st);
|
||||
}
|
||||
return (null, '');
|
||||
|
||||
@@ -3,7 +3,6 @@ import 'package:eatvio_app/features/diets/repositories/diet_repository.dart';
|
||||
import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart';
|
||||
import 'package:eatvio_app/features/plans/models/chosen_plan_model.dart';
|
||||
import 'package:eatvio_app/features/plans/services/plan_service.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
|
||||
class PlanRepository {
|
||||
final PlanService planService;
|
||||
@@ -18,48 +17,28 @@ class PlanRepository {
|
||||
Stream get planCommentsState => _planCommentsStateStreamController.stream;
|
||||
|
||||
Future<PlanModel> getPlan(String slug) async {
|
||||
try {
|
||||
return planService.getPlan(slug);
|
||||
} catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
rethrow;
|
||||
}
|
||||
return planService.getPlan(slug);
|
||||
|
||||
}
|
||||
|
||||
Future<void> likePlan(String slug) async {
|
||||
try {
|
||||
await planService.likePlan(slug: slug);
|
||||
} catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
rethrow;
|
||||
}
|
||||
await planService.likePlan(slug: slug);
|
||||
|
||||
}
|
||||
|
||||
Future<void> addToFavorite(String slug) async {
|
||||
try {
|
||||
await planService.addToFavorite(slug: slug);
|
||||
} catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
rethrow;
|
||||
}
|
||||
await planService.addToFavorite(slug: slug);
|
||||
|
||||
}
|
||||
|
||||
Future<void> removeFromFavorite(String slug) async {
|
||||
try {
|
||||
await planService.removeFromFavorite(slug: slug);
|
||||
} catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
rethrow;
|
||||
}
|
||||
await planService.removeFromFavorite(slug: slug);
|
||||
|
||||
}
|
||||
|
||||
Future<ChosenPlanModel> chosePlan(String slug, Map<String, dynamic> option ) async {
|
||||
try {
|
||||
return await planService.chosePlan(slug: slug, option: option);
|
||||
} catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
rethrow;
|
||||
}
|
||||
return await planService.chosePlan(slug: slug, option: option);
|
||||
|
||||
}
|
||||
|
||||
void emitLikesStateToFeed(LikesState state) => _planLikeStateStreamController.add(state);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart';
|
||||
import 'package:eatvio_app/features/plans/services/plans_service.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
|
||||
class PlansRepository {
|
||||
final PlansService plansService;
|
||||
@@ -8,12 +7,8 @@ class PlansRepository {
|
||||
PlansRepository({required this.plansService});
|
||||
|
||||
Future<List<PlanModel>> getPlansBySlug(String slug) async {
|
||||
try {
|
||||
final plans = (await plansService.getPlansBySlug(author: slug)).data;
|
||||
return plans.where((plan) => plan.state == 'active').toList();
|
||||
} catch (e, s) {
|
||||
await Sentry.captureException(e, stackTrace: s);
|
||||
rethrow;
|
||||
}
|
||||
final plans = (await plansService.getPlansBySlug(author: slug)).data;
|
||||
return plans.where((plan) => plan.state == 'active').toList();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user