forked from eatvio/eatvio_app
plans filters ready
This commit is contained in:
@@ -25,7 +25,7 @@ class DietsCubit extends Cubit<DietsState> {
|
||||
'name:desc',
|
||||
];
|
||||
static const List<int?> _durationValues = [null, ...durationValues];
|
||||
static const List<String?> _types = [null, ...typeValues];
|
||||
static const List<String?> _types = [null, ...dietTypeValues];
|
||||
late final StreamSubscription likesStateSubscription;
|
||||
late final StreamSubscription favoriteStateSubscription;
|
||||
late final StreamSubscription commentsStateSubscription;
|
||||
@@ -54,17 +54,35 @@ class DietsCubit extends Cubit<DietsState> {
|
||||
|
||||
void changeTypeFilter(int index) {
|
||||
emit(state.copyWith(filterState: state.filterState.copyWith(typeIndex: index), errorMessage: null));
|
||||
loadDiets(query: _query);
|
||||
EasyDebounce.debounce(
|
||||
'loadDiets',
|
||||
Duration(seconds: 1),
|
||||
() => loadDiets(
|
||||
query: _query,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void changeSortingType(int index) {
|
||||
emit(state.copyWith(filterState: state.filterState.copyWith(sortingIndex: index), errorMessage: null));
|
||||
loadDiets(query: _query);
|
||||
EasyDebounce.debounce(
|
||||
'loadDiets',
|
||||
Duration(seconds: 1),
|
||||
() => loadDiets(
|
||||
query: _query,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void changeDurationFilter(int index) {
|
||||
emit(state.copyWith(filterState: state.filterState.copyWith(durationIndex: index), errorMessage: null));
|
||||
loadDiets(query: _query);
|
||||
EasyDebounce.debounce(
|
||||
'loadDiets',
|
||||
Duration(seconds: 1),
|
||||
() => loadDiets(
|
||||
query: _query,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
loadDiets({
|
||||
@@ -82,9 +100,8 @@ class DietsCubit extends Cubit<DietsState> {
|
||||
sorting: sorting,
|
||||
);
|
||||
lastPage = dietsPagination.meta.lastPage;
|
||||
|
||||
emit(
|
||||
state.copyWith(dietsList: dietsPagination.data, isLoading: isLoading, errorMessage: null),
|
||||
state.copyWith(dietsList: dietsPagination.data, isLoading: isLoading, errorMessage: null,),
|
||||
);
|
||||
} catch (e) {
|
||||
emit(
|
||||
@@ -181,7 +198,7 @@ class DietsCubit extends Cubit<DietsState> {
|
||||
);
|
||||
}
|
||||
|
||||
void _changeDietLikeState(DietLikesState likesState) {
|
||||
void _changeDietLikeState(LikesState likesState) {
|
||||
final currentDiets = state.dietsList;
|
||||
final dietsForModification = [...currentDiets];
|
||||
final currentDiet = currentDiets[likesState.index];
|
||||
@@ -201,7 +218,7 @@ class DietsCubit extends Cubit<DietsState> {
|
||||
);
|
||||
}
|
||||
|
||||
void _changeDietFavoriteState(DietFavoriteState favoriteState) {
|
||||
void _changeDietFavoriteState(FavoriteState favoriteState) {
|
||||
final currentDiets = state.dietsList;
|
||||
final dietsForModification = [...currentDiets];
|
||||
final currentDiet = currentDiets[favoriteState.index];
|
||||
@@ -220,7 +237,7 @@ class DietsCubit extends Cubit<DietsState> {
|
||||
);
|
||||
}
|
||||
|
||||
void _changeDietCommentsState(DietCommentsState commentsState) {
|
||||
void _changeDietCommentsState(CommentsState commentsState) {
|
||||
final currentDiets = state.dietsList;
|
||||
final dietsForModification = [...currentDiets];
|
||||
final currentDiet = currentDiets[commentsState.index];
|
||||
@@ -261,7 +278,7 @@ class DietsCubit extends Cubit<DietsState> {
|
||||
Duration(milliseconds: 200),
|
||||
() async {
|
||||
try {
|
||||
await dietsRepository.addToFavorite(id);
|
||||
await dietsRepository.addToFavorite(id);
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
showErrorToast('Произошла ошибка. Попробуйте ещё раз через некоторое время');
|
||||
@@ -301,7 +318,7 @@ class DietsCubit extends Cubit<DietsState> {
|
||||
Duration(milliseconds: 200),
|
||||
() async {
|
||||
try {
|
||||
await dietsRepository.removeFromFavorite(id);
|
||||
await dietsRepository.removeFromFavorite(id);
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
showErrorToast('Произошла ошибка. Попробуйте ещё раз через некоторое время');
|
||||
|
||||
Reference in New Issue
Block a user