socket fixed

This commit is contained in:
Username1548
2025-01-19 15:10:56 +07:00
parent ab7004f9fd
commit 7eaf0bc1bb
29 changed files with 489 additions and 1006 deletions

View File

@@ -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,
),
);
}
},
);
}
}