diff --git a/lib/presentation/feed/blog_post_screen/bloc/blog_post_bloc.dart b/lib/presentation/feed/blog_post_screen/bloc/blog_post_bloc.dart index b4889913..e1a98497 100644 --- a/lib/presentation/feed/blog_post_screen/bloc/blog_post_bloc.dart +++ b/lib/presentation/feed/blog_post_screen/bloc/blog_post_bloc.dart @@ -73,6 +73,27 @@ class BlogPostBloc extends Bloc { } } + FutureOr _createComment( + CreateComment event, Emitter emit) async { + if (state is BlogPostLoadedState) { + var currentState = state as BlogPostLoadedState; + // Отправляем данные по HTTP маршруту и ждем ответ + var response = await _sendCommentData( + currentState.token, event.body, currentState.blog_post?['id']); + + if (response.statusCode == 200) { + var updatedComments = fillCommentList( + await _fetchComments(currentState.blog_post?['id'])); + var updatedState = currentState.copyWith( + comments: updatedComments, + commentController: + TextEditingController(), // Clear the comment input field + ); + emit(updatedState); // Emit the updated state to trigger a screen update + } + } + } + FutureOr _deleteEntry( DeleteEntry event, Emitter emit) async { final box = await Hive.openBox('token'); @@ -150,25 +171,6 @@ class BlogPostBloc extends Bloc { return list; } - FutureOr _createComment( - CreateComment event, Emitter emit) async { - if (state is BlogPostLoadedState) { - var currentState = state as BlogPostLoadedState; - var updatedState = currentState.copyWith( - commentController: TextEditingController(text: event.body), - ); - - // Отправляем данные по HTTP маршруту и ждем ответ - var response = await _sendCommentData( - currentState.token, event.body, currentState.blog_post?['id']); - print(response.body); - - if (response.statusCode == 200) { - emit(updatedState); // Передаем обновленное состояние в emit - } - } - } - Future _sendCommentData( String? token, String body, int id) async { String url = dotenv.env['SERVER_ROOT']! + '/feed/createComment/$id'; diff --git a/lib/presentation/feed/feed_screen/bloc/feed_bloc.dart b/lib/presentation/feed/feed_screen/bloc/feed_bloc.dart index 984bbbf7..3932f495 100644 --- a/lib/presentation/feed/feed_screen/bloc/feed_bloc.dart +++ b/lib/presentation/feed/feed_screen/bloc/feed_bloc.dart @@ -34,6 +34,9 @@ class FeedBloc extends Bloc { } final response = await http.get( Uri.parse(dotenv.env['SERVER_ROOT']! + '/feed/index'), + headers: { + 'Authorization': 'Bearer $token', + }, ); print('Got response'); if (response.statusCode == 200) { diff --git a/lib/presentation/feed/feed_screen/feed_screen.dart b/lib/presentation/feed/feed_screen/feed_screen.dart index b15ab6df..4ebff264 100644 --- a/lib/presentation/feed/feed_screen/feed_screen.dart +++ b/lib/presentation/feed/feed_screen/feed_screen.dart @@ -118,7 +118,6 @@ class FeedScreen extends StatelessWidget { itemCount: state.posts?.length ?? 0, itemBuilder: (context, index) { final post = state.posts?[index]; - print(post['author']['name']); return Container( margin: EdgeInsets.only(bottom: 10), decoration: BoxDecoration( @@ -161,7 +160,7 @@ class FeedScreen extends StatelessWidget { onTap: () => Navigator.pushNamed( context, AppRoutes.blogPostScreen, - arguments: post?['id'].toString(), + arguments: post?['post']['id'].toString(), ), trailing: PopupMenuButton( onSelected: (value) => print("tap"),