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:
@@ -7,6 +7,7 @@ import 'package:eatvio_app/features/recipe/repositories/about_recipe_repository.
|
||||
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
|
||||
import 'package:eatvio_app/features/recipe/presentation/cubit/about_recipe_state.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:eatvio_app/core/error_reporting/report_from.dart';
|
||||
|
||||
class AboutRecipeCubit extends Cubit<AboutRecipeState> {
|
||||
AboutRecipeCubit({required this.recipeRepository, required this.profileRepository}) : super(const AboutRecipeState.initial());
|
||||
@@ -23,7 +24,8 @@ class AboutRecipeCubit extends Cubit<AboutRecipeState> {
|
||||
recipeRepository.emitCommentsStateToFeed(CommentsState(index: index, totalComments: recipe.commentsCount));
|
||||
}
|
||||
emit(AboutRecipeState.loaded(recipe: recipe));
|
||||
} catch (e) {
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
log(e.toString());
|
||||
emit(AboutRecipeState.error(message: e.toString()));
|
||||
}
|
||||
@@ -37,7 +39,8 @@ class AboutRecipeCubit extends Cubit<AboutRecipeState> {
|
||||
recipeRepository.emitCommentsStateToFeed(CommentsState(index: index, totalComments: recipe.commentsCount));
|
||||
}
|
||||
emit(AboutRecipeState.loaded(recipe: recipe));
|
||||
} catch (e) {
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
log(e.toString());
|
||||
emit(AboutRecipeState.error(message: e.toString()));
|
||||
}
|
||||
@@ -76,7 +79,8 @@ class AboutRecipeCubit extends Cubit<AboutRecipeState> {
|
||||
() async {
|
||||
try {
|
||||
await recipeRepository.likeRecipe(id);
|
||||
} catch (e) {
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
log(e.toString());
|
||||
if (recipeIndexInFeed != null) {
|
||||
recipeRepository
|
||||
@@ -107,7 +111,8 @@ class AboutRecipeCubit extends Cubit<AboutRecipeState> {
|
||||
() async {
|
||||
try {
|
||||
await recipeRepository.addToFavorite(id);
|
||||
} catch (e) {
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
log(e.toString());
|
||||
showErrorToast('Произошла ошибка. Попробуйте ещё раз через некоторое время');
|
||||
if (recipeIndex != null) {
|
||||
@@ -138,7 +143,8 @@ class AboutRecipeCubit extends Cubit<AboutRecipeState> {
|
||||
() async {
|
||||
try {
|
||||
await recipeRepository.removeFromFavorite(id);
|
||||
} catch (e) {
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
log(e.toString());
|
||||
showErrorToast('Произошла ошибка. Попробуйте ещё раз через некоторое время');
|
||||
if (recipeIndex != null) {
|
||||
|
||||
@@ -8,7 +8,7 @@ import 'package:eatvio_app/features/recipe/presentation/cubit/my_recipes_cubit/m
|
||||
import 'package:eatvio_app/features/recipe/repositories/about_recipe_repository.dart';
|
||||
import 'package:eatvio_app/features/recipe/repositories/my_recipes_repository.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
import 'package:eatvio_app/core/error_reporting/report_from.dart';
|
||||
|
||||
class MyRecipesCubit extends Cubit<MyRecipesState> {
|
||||
final MyRecipesRepository myRecipesRepository;
|
||||
@@ -31,7 +31,8 @@ class MyRecipesCubit extends Cubit<MyRecipesState> {
|
||||
final myRecipes = await myRecipesRepository.getMyRecipes();
|
||||
final List<MyRecipeModel> activeRecipes = myRecipes.where((recipe) => recipe.state == active).toList();
|
||||
emit(MyRecipesState.loaded(recipes: activeRecipes, selectedState: active));
|
||||
} catch (e) {
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
emit(const MyRecipesState.error());
|
||||
}
|
||||
}
|
||||
@@ -42,7 +43,8 @@ class MyRecipesCubit extends Cubit<MyRecipesState> {
|
||||
final myRecipes = await myRecipesRepository.getMyRecipes();
|
||||
final List<MyRecipeModel> activeRecipes = myRecipes.where((recipe) => recipe.state == active).toList();
|
||||
emit(MyRecipesState.loaded(recipes: activeRecipes, selectedState: active));
|
||||
} catch (e) {
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
emit(const MyRecipesState.error());
|
||||
}
|
||||
}
|
||||
@@ -53,7 +55,8 @@ class MyRecipesCubit extends Cubit<MyRecipesState> {
|
||||
final myRecipes = await myRecipesRepository.getMyRecipes();
|
||||
final List<MyRecipeModel> archivedRecipes = myRecipes.where((recipe) => recipe.state == archived).toList();
|
||||
emit(MyRecipesState.loaded(recipes: archivedRecipes, selectedState: archived));
|
||||
} catch (e) {
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
emit(const MyRecipesState.error());
|
||||
}
|
||||
}
|
||||
@@ -64,13 +67,19 @@ class MyRecipesCubit extends Cubit<MyRecipesState> {
|
||||
final myRecipes = await myRecipesRepository.getMyRecipes();
|
||||
final List<MyRecipeModel> draftedRecipes = myRecipes.where((recipe) => recipe.state == drafted).toList();
|
||||
emit(MyRecipesState.loaded(recipes: draftedRecipes, selectedState: drafted));
|
||||
} catch (e) {
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
emit(const MyRecipesState.error());
|
||||
}
|
||||
}
|
||||
|
||||
Future<Recipe> getRecipeById(String slug) async {
|
||||
return await aboutRecipeRepository.getRecipe(slug);
|
||||
Future<Recipe?> getRecipeById(String slug) async {
|
||||
try {
|
||||
return await aboutRecipeRepository.getRecipe(slug);
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// Attempts to publish a drafted recipe
|
||||
@@ -81,10 +90,9 @@ class MyRecipesCubit extends Cubit<MyRecipesState> {
|
||||
await recipeRepository.publishRecipe(recipe, true, slug);
|
||||
return true;
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
if (e is DioException && e.response?.statusCode == 422) {
|
||||
log('Validation failed for publishing draft: \${e.response?.data}');
|
||||
} else {
|
||||
await Sentry.captureException(e, stackTrace: st);
|
||||
log('Validation failed for publishing draft: ${e.response?.data}');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -96,8 +104,8 @@ class MyRecipesCubit extends Cubit<MyRecipesState> {
|
||||
await recipeRepository.draftExistingRecipe(id);
|
||||
return true;
|
||||
} catch (e, st) {
|
||||
log('Failed to draft recipe: \$e');
|
||||
await Sentry.captureException(e, stackTrace: st);
|
||||
await reportFrom(e, st, this);
|
||||
log('Failed to draft recipe: $e');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,6 +155,10 @@ class _MyRecipeWidgetState extends State<MyRecipeWidget> {
|
||||
final fullRecipe = await context.read<MyRecipesCubit>().getRecipeById(widget.recipe.slug);
|
||||
if (context.mounted) {
|
||||
Navigator.pop(context); // close dialog
|
||||
if (fullRecipe == null) {
|
||||
showErrorToast('Не удалось загрузить рецепт');
|
||||
return;
|
||||
}
|
||||
final result = await context.push(RecipeCreateScreen.path, extra: fullRecipe);
|
||||
if (!context.mounted) return;
|
||||
if (result == MyRecipesCubit.drafted) {
|
||||
@@ -226,11 +230,16 @@ class _MyRecipeWidgetState extends State<MyRecipeWidget> {
|
||||
builder: (context) => const Center(child: CircularProgressIndicator()),
|
||||
);
|
||||
final fullRecipe = await context.read<MyRecipesCubit>().getRecipeById(widget.recipe.slug);
|
||||
if (!context.mounted) return;
|
||||
Navigator.pop(context);
|
||||
if (fullRecipe == null) {
|
||||
showErrorToast('Не удалось загрузить рецепт');
|
||||
return;
|
||||
}
|
||||
final createCubit = sl<CreateRecipeCubit>();
|
||||
await createCubit.recipeToEntity(fullRecipe);
|
||||
|
||||
if (context.mounted) {
|
||||
Navigator.pop(context);
|
||||
if (createCubit.validateAll()) {
|
||||
final success = await createCubit.publishRecipe(true, widget.recipe.slug);
|
||||
if (success && context.mounted) {
|
||||
|
||||
Reference in New Issue
Block a user