forked from eatvio/eatvio_app
feat(diary): added state for future days with diet
This commit is contained in:
@@ -36,19 +36,33 @@ class DiaryCubit extends Cubit<DiaryState> {
|
||||
|
||||
String comment = '';
|
||||
|
||||
setSelectedDay(DateTime day) async {
|
||||
setSelectedDay(DateTime day, {bool? forDietOnly}) async {
|
||||
selectedDay = day;
|
||||
if (forDietOnly ?? false) {
|
||||
await fetchDiaryForDietOnly();
|
||||
return;
|
||||
}
|
||||
await fetchDiary(true);
|
||||
}
|
||||
|
||||
setSelectedMeal(int meal) {
|
||||
selectedMeal = meal;
|
||||
emit((state as DiaryStateLoaded).copyWith(selectedMeal: selectedMeal));
|
||||
final currentState = state;
|
||||
if (currentState is DiaryStateLoaded) {
|
||||
emit(currentState.copyWith(selectedMeal: selectedMeal));
|
||||
} else if (currentState is DiaryStateLoadedTomorrowWithDiet) {
|
||||
emit(currentState.copyWith(selectedMeal: selectedMeal));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchDiaryForDietOnly() async {
|
||||
final stringDate = selectedDay.format('yyyy-MM-dd');
|
||||
final diaryDay = await diaryRepository.getDiaryByDateForDietOnly(stringDate);
|
||||
emit(DiaryState.loadedTomorrowWithDiet(diary: diaryDay, selectedDay: selectedDay, selectedMeal: selectedMeal));
|
||||
}
|
||||
|
||||
fetchDiary([bool needLoading = false, int? diaryId]) async {
|
||||
this.diaryId ??= diaryId;
|
||||
await profileRepository.getChosenDiets();
|
||||
if (needLoading) {
|
||||
emit(const DiaryState.loading());
|
||||
selectedMeal = 1;
|
||||
@@ -58,7 +72,7 @@ class DiaryCubit extends Cubit<DiaryState> {
|
||||
if (diaryId != null) {
|
||||
diaryDay = await diaryRepository.getDiaryDay(diaryId);
|
||||
} else {
|
||||
final stringDate = selectedDay.toUtc().format('yyyy-MM-dd');
|
||||
final stringDate = selectedDay.format('yyyy-MM-dd');
|
||||
diaryDay = await diaryRepository.getDiaryByDate(stringDate);
|
||||
}
|
||||
ConsultantReviewModel? consultantReview;
|
||||
|
||||
@@ -21,8 +21,14 @@ class DiaryState with _$DiaryState {
|
||||
required DateTime selectedDay,
|
||||
required int selectedMeal,
|
||||
@Default(false) bool isConsultantView,
|
||||
ConsultantReviewModel? consultantReview,
|
||||
ConsultantReviewModel? consultantReview,
|
||||
@Default(false) bool isDiaryFinished,
|
||||
@Default(false) bool isDiaryCommented,
|
||||
}) = DiaryStateLoaded;
|
||||
|
||||
const factory DiaryState.loadedTomorrowWithDiet({
|
||||
required DiaryFutureDietDayModel diary,
|
||||
required DateTime selectedDay,
|
||||
required int selectedMeal,
|
||||
}) = DiaryStateLoadedTomorrowWithDiet;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user