From 9ba363e7809c40adf429ce34758fec42a2f7d658 Mon Sep 17 00:00:00 2001 From: mso7nueh Date: Wed, 2 Oct 2024 18:15:39 +0300 Subject: [PATCH] feat(feed): add search in blog posts and diets --- .../presentation/bloc/diets_cubit/diets_cubit.dart | 14 ++++++++++++-- .../feed/presentation/pages/feed_screen.dart | 6 ++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/features/feed/presentation/bloc/diets_cubit/diets_cubit.dart b/lib/features/feed/presentation/bloc/diets_cubit/diets_cubit.dart index 858bbe9e..23d1c657 100644 --- a/lib/features/feed/presentation/bloc/diets_cubit/diets_cubit.dart +++ b/lib/features/feed/presentation/bloc/diets_cubit/diets_cubit.dart @@ -4,12 +4,22 @@ import 'package:flutter_bloc/flutter_bloc.dart'; class DietsCubit extends Cubit { final FeedRepository feedRepository; + int currentPage = 1; + late int lastPage; + bool isLoading = false; + // String? _query; DietsCubit({required this.feedRepository}) : super(const DietsState.loading()); - loadDiets() async { + loadDiets({ + String? query, + }) async { try { - final diets = await feedRepository.getDiets(); + // _query = query; + final diets = await feedRepository.getDiets( + query: query, + ); + lastPage = diets.meta.lastPage; emit(DietsState.loaded(diets: diets)); } catch (e) { emit(DietsState.error(errorMessage: e.toString())); diff --git a/lib/features/feed/presentation/pages/feed_screen.dart b/lib/features/feed/presentation/pages/feed_screen.dart index ab1c9768..115f25f3 100644 --- a/lib/features/feed/presentation/pages/feed_screen.dart +++ b/lib/features/feed/presentation/pages/feed_screen.dart @@ -428,6 +428,9 @@ class _FeedScreenState extends State { case 1: recipesCubit.loadRecipesList(query: query); break; + case 2: + dietsCubit.loadDiets(query: query); + break; } }, ); @@ -443,6 +446,9 @@ class _FeedScreenState extends State { case 1: recipesCubit.loadRecipesList(); break; + case 2: + dietsCubit.loadDiets(query: query); + break; } }, );