feat(profile): subscribers and subscriptions

This commit is contained in:
mso7nueh
2024-11-22 15:27:51 +03:00
parent f805505cb3
commit c909c75d47
45 changed files with 2790 additions and 451 deletions

View File

@@ -12,7 +12,6 @@ import 'package:flutter_bloc/flutter_bloc.dart';
class DiaryCubit extends Cubit<DiaryState> {
final DiaryRepository diaryRepository;
final GlossaryRepository glossaryRepository;
double currentSelectedSatietyRating = 3;
DiaryCubit({
required this.diaryRepository,
@@ -22,11 +21,16 @@ class DiaryCubit extends Cubit<DiaryState> {
getDiaryDay(String date, [bool needLoading = true]) async {
if (needLoading) emit(const DiaryState.loading());
try {
final diaryDay = await diaryRepository.getDiaryByDate(date);
final List<int> satiety = [];
for (int i = 0; i < diaryDay.meals.length; i++) {
satiety.add(diaryDay.meals[i].satiety);
}
emit(
DiaryState.loaded(
diary: await diaryRepository.getDiaryByDate(date),
diary: diaryDay,
nutrition: await getNutrition((await diaryRepository.getDiaryByDate(date)).id),
currentSelectedSatietyRating: currentSelectedSatietyRating,
currentSelectedSatietyRating: satiety,
),
);
} catch (e) {
@@ -136,17 +140,23 @@ class DiaryCubit extends Cubit<DiaryState> {
await getDiaryDay(date, false);
}
updateCurrentSelectedSatietyRating(double value) {
currentSelectedSatietyRating = value;
emit((state as DiaryStateLoaded).copyWith(currentSelectedSatietyRating: currentSelectedSatietyRating));
updateCurrentSelectedSatietyRating({
required int diaryId,
required int meal,
required int value,
}) {
List<int> satiety = [...(state as DiaryStateLoaded).currentSelectedSatietyRating];
satiety[meal] = value;
diaryRepository.fillSatiety(diaryId: diaryId, meal: meal, satiety: value.toInt() - 1);
emit((state as DiaryStateLoaded).copyWith(currentSelectedSatietyRating: satiety));
}
sendProductToModeration({
required String name,
required int energy,
required int proteins,
required int fats,
required int carbohydrates,
required double energy,
required double proteins,
required double fats,
required double carbohydrates,
}) async {
return await diaryRepository.sendProductToModeration(
name: name,