Merge remote-tracking branch 'upstream/main' into issue-851

# Conflicts:
#	lib/features/feed/presentation/widgets/plan_widget.dart
#	lib/features/profile/presentation/pages/profile_screen.dart
This commit is contained in:
misha
2026-11-24 12:24:45 +03:00
90 changed files with 6002 additions and 3070 deletions

View File

@@ -5,6 +5,7 @@ import 'package:easy_debounce/easy_debounce.dart';
import 'package:eatvio_app/core/const.dart';
import 'package:eatvio_app/core/utils/toasts.dart';
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/feed/presentation/bloc/plans_cubit/plans_state.dart';
import 'package:eatvio_app/features/feed/repositories/feed_repository.dart';
import 'package:eatvio_app/features/plans/repositories/plan_repository.dart';
@@ -87,57 +88,51 @@ class PlansCubit extends Cubit<PlansState> {
}
void _changePlanLikeState(LikesState likesState) {
final currentPlans = state.plans;
final plansForModification = [...currentPlans];
final currentPlan = currentPlans[likesState.index];
plansForModification[likesState.index] = currentPlan.copyWith(
totalLikes: likesState.totalLikes,
wasLikedByMe: likesState.wasLikedByMe,
);
emit(
state.copyWith(
plans: [
...plansForModification,
],
isLoading: isLoading,
errorMessage: null,
_updatePlanAt(
slug: likesState.slug,
index: likesState.index,
transform: (currentPlan) => currentPlan.copyWith(
totalLikes: likesState.totalLikes,
wasLikedByMe: likesState.wasLikedByMe,
),
);
}
void _changePlanFavoriteState(FavoriteState favoriteState) {
final currentPlans = state.plans;
final plansForModification = [...currentPlans];
final currentPlan = currentPlans[favoriteState.index];
plansForModification[favoriteState.index] = currentPlan.copyWith(
isFavorite: favoriteState.isFavorite,
);
emit(
state.copyWith(
plans: [
...plansForModification,
],
isLoading: isLoading,
errorMessage: null,
_updatePlanAt(
slug: favoriteState.slug,
index: favoriteState.index,
transform: (currentPlan) => currentPlan.copyWith(
isFavorite: favoriteState.isFavorite,
),
);
}
void _changePlanCommentsState(CommentsState commentsState) {
final currentPlans = state.plans;
final plansForModification = [...currentPlans];
final currentPlan = currentPlans[commentsState.index];
plansForModification[commentsState.index] = currentPlan.copyWith(
totalComments: commentsState.totalComments,
_updatePlanAt(
slug: commentsState.slug,
index: commentsState.index,
transform: (currentPlan) => currentPlan.copyWith(
totalComments: commentsState.totalComments,
),
);
}
void _updatePlanAt({
required String? slug,
required int index,
required PlanModel Function(PlanModel currentPlan) transform,
}) {
final currentPlans = state.plans;
final targetIndex =
slug != null ? currentPlans.indexWhere((plan) => plan.slug == slug) : index;
if (targetIndex < 0 || targetIndex >= currentPlans.length) return;
final plansForModification = [...currentPlans];
plansForModification[targetIndex] = transform(currentPlans[targetIndex]);
emit(
state.copyWith(
plans: [
...plansForModification,
],
plans: plansForModification,
isLoading: isLoading,
errorMessage: null,
),

View File

@@ -13,10 +13,8 @@ import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart';
import 'package:eatvio_app/core/theme/custom_text_style.dart';
import 'package:eatvio_app/core/utils/url_utils.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/feed/presentation/bloc/plans_cubit/plans_cubit.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:material_ui/material_ui.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:go_router/go_router.dart';
import 'package:share_plus/share_plus.dart';
@@ -25,12 +23,18 @@ class PlanWidget extends StatefulWidget {
final PlanModel plan;
final int index;
final bool showPriceOnCover;
final Future<void> Function(String slug)? onLikeTap;
final Future<void> Function(String slug, bool isFavorite)? onToggleFavorite;
final VoidCallback? onPlanChanged;
const PlanWidget({
super.key,
required this.plan,
required this.index,
this.showPriceOnCover = false,
this.onLikeTap,
this.onToggleFavorite,
this.onPlanChanged,
});
@override
@@ -81,17 +85,10 @@ class _PlanWidgetState extends State<PlanWidget> {
left: 14,
child: BookmarkButton(
onTap: () async {
if (widget.plan.isFavorite) {
await context.read<PlansCubit>().removePlanFromFavorite(
widget.plan.slug,
widget.index,
);
} else {
await context.read<PlansCubit>().addPlanToFavorite(
widget.plan.slug,
widget.index,
);
}
await widget.onToggleFavorite?.call(
widget.plan.slug,
widget.plan.isFavorite,
);
},
color: appTheme.whiteA700,
isFavorite: widget.plan.isFavorite,
@@ -121,6 +118,7 @@ class _PlanWidgetState extends State<PlanWidget> {
plan: widget.plan,
complainedContentType: ComplainedContent.plan,
userSlug: widget.plan.author.authorSlug,
onPlanChanged: widget.onPlanChanged,
),
),
),
@@ -236,22 +234,25 @@ class _PlanWidgetState extends State<PlanWidget> {
),
subtitle: Row(
children: [
InfoBouble(
radius: 12,
backgroundColor: appTheme.gray50,
padding: const EdgeInsets.symmetric(
vertical: 4,
horizontal: 10,
),
children: [
Text(
'${widget.plan.author.authorPlaceInRating}-й в рейтинге',
style: TextStyles.textXSSemibold.copyWith(
color: appTheme.blueA400,
),
if (widget.plan.author.authorPlaceInRating != null)
InfoBouble(
radius: 12,
backgroundColor: appTheme.gray50,
padding: const EdgeInsets.symmetric(
vertical: 4,
horizontal: 10,
),
],
),
children: [
Text(
s.rating_place(
widget.plan.author.authorPlaceInRating!,
),
style: TextStyles.textXSSemibold.copyWith(
color: appTheme.blueA400,
),
),
],
),
if (!widget.showPriceOnCover) ...[
const Spacer(),
Text(
@@ -293,10 +294,7 @@ class _PlanWidgetState extends State<PlanWidget> {
? appTheme.transparentBlue
: null,
onTap: () async {
await context.read<PlansCubit>().likePlan(
widget.plan.slug,
widget.index,
);
await widget.onLikeTap?.call(widget.plan.slug);
},
),
const SizedBox(width: 12),

View File

@@ -44,7 +44,15 @@ class Plans extends StatelessWidget {
final id = state.plans[index].id;
handleVisibility(visibleFraction: info.visibleFraction, id: id, type: ViewableContentType.plans);
},
child: PlanWidget(plan: state.plans[index], index: index),
child: PlanWidget(
plan: state.plans[index],
index: index,
onLikeTap: (slug) => context.read<PlansCubit>().likePlan(slug, index),
onToggleFavorite: (slug, isFavorite) => isFavorite
? context.read<PlansCubit>().removePlanFromFavorite(slug, index)
: context.read<PlansCubit>().addPlanToFavorite(slug, index),
onPlanChanged: () => context.read<PlansCubit>().loadPlans(),
),
);
},
separatorBuilder: (context, index) {