forked from eatvio/eatvio_app
socket fixed
This commit is contained in:
@@ -9,7 +9,7 @@ import 'package:eatvio_app/features/feed/presentation/bloc/diets_cubit/diets_sta
|
||||
import 'package:eatvio_app/features/feed/repositories/feed_repository.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
class DietsCubit extends Cubit<DietsState>{
|
||||
class DietsCubit extends Cubit<DietsState> {
|
||||
final FeedRepository feedRepository;
|
||||
final DietRepository dietsRepository;
|
||||
int currentPage = 1;
|
||||
@@ -52,7 +52,6 @@ class DietsCubit extends Cubit<DietsState>{
|
||||
super.close();
|
||||
}
|
||||
|
||||
|
||||
void changeTypeFilter(int index) {
|
||||
emit(state.copyWith(filterState: state.filterState.copyWith(typeIndex: index), errorMessage: null));
|
||||
EasyDebounce.debounce(
|
||||
@@ -64,7 +63,6 @@ class DietsCubit extends Cubit<DietsState>{
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void changeSortingType(int index) {
|
||||
emit(state.copyWith(filterState: state.filterState.copyWith(sortingIndex: index), errorMessage: null));
|
||||
EasyDebounce.debounce(
|
||||
@@ -76,7 +74,6 @@ class DietsCubit extends Cubit<DietsState>{
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void changeDurationFilter(int index) {
|
||||
emit(state.copyWith(filterState: state.filterState.copyWith(durationIndex: index), errorMessage: null));
|
||||
EasyDebounce.debounce(
|
||||
@@ -153,6 +150,7 @@ class DietsCubit extends Cubit<DietsState>{
|
||||
|
||||
Future<void> likeDiet(int id, int index) async {
|
||||
final currentDiets = state.dietsList;
|
||||
if (currentDiets.isEmpty) return;
|
||||
final dietsForModification = [...currentDiets];
|
||||
final currentDiet = currentDiets[index];
|
||||
if (currentDiet.wasLikedByMe) {
|
||||
|
||||
@@ -284,4 +284,58 @@ class PlansCubit extends Cubit<PlansState> {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> likePlan(String slug, int index) async {
|
||||
final currentPlans = state.plans;
|
||||
final plansForModification = [...currentPlans];
|
||||
final currentPlan = currentPlans[index];
|
||||
if (currentPlan.wasLikedByMe) {
|
||||
plansForModification[index] = currentPlan.copyWith(
|
||||
totalLikes: currentPlan.totalLikes - 1,
|
||||
wasLikedByMe: false,
|
||||
);
|
||||
emit(
|
||||
state.copyWith(
|
||||
plans: [
|
||||
...plansForModification,
|
||||
],
|
||||
isLoading: isLoading,
|
||||
errorMessage: null,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
plansForModification[index] = currentPlan.copyWith(
|
||||
totalLikes: currentPlan.totalLikes + 1,
|
||||
wasLikedByMe: true,
|
||||
);
|
||||
emit(
|
||||
state.copyWith(
|
||||
plans: [
|
||||
...plansForModification,
|
||||
],
|
||||
isLoading: isLoading,
|
||||
errorMessage: null,
|
||||
),
|
||||
);
|
||||
}
|
||||
EasyDebounce.debounce(
|
||||
'like_plan',
|
||||
Duration(milliseconds: 200),
|
||||
() async {
|
||||
try {
|
||||
await planRepository.likePlan(slug);
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
emit(
|
||||
state.copyWith(
|
||||
plans: [
|
||||
...currentPlans,
|
||||
],
|
||||
isLoading: isLoading,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import 'package:eatvio_app/core/widgets/info_row.dart';
|
||||
import 'package:eatvio_app/core/widgets/feed_icon_button.dart';
|
||||
import 'package:eatvio_app/features/diets/presentation/widgets/info_bouble.dart';
|
||||
import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/bloc/diets_cubit/diets_cubit.dart';
|
||||
import 'package:eatvio_app/core/theme/custom_text_style.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/bloc/plans_cubit/plans_cubit.dart';
|
||||
@@ -183,7 +182,7 @@ class _PlanWidgetState extends State<PlanWidget> {
|
||||
iconColor: widget.plan.wasLikedByMe ? appTheme.blueA400 : null,
|
||||
backgroundColor: widget.plan.wasLikedByMe ? appTheme.transparentBlue : null,
|
||||
onTap: () async {
|
||||
await context.read<DietsCubit>().likeDiet(widget.plan.id, widget.index);
|
||||
await context.read<PlansCubit>().likePlan(widget.plan.slug, widget.index);
|
||||
},
|
||||
),
|
||||
SizedBox(
|
||||
|
||||
Reference in New Issue
Block a user