feat(comments): added actions bottom sheet with different actions for comments, added copy, reply and complain

This commit is contained in:
Username1548
2025-07-08 09:17:20 +07:00
parent 0886d1cd7b
commit 0a636e05b8
20 changed files with 395 additions and 100 deletions

View File

@@ -0,0 +1,106 @@
import 'dart:developer';
import 'package:eatvio_app/core/comments/comments_cubit/comments_state.dart';
import 'package:eatvio_app/core/comments/repositories/comments_repository.dart';
import 'package:eatvio_app/features/feed/presentation/widgets/comments_widget.dart';
import 'package:eatvio_app/features/feed/repositories/feed_repository.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class CommentsCubit extends Cubit<CommentsState> {
final FeedRepository feedRepository;
final CommentsRepository commentsRepository;
CommentsCubit({
required this.feedRepository,
required this.commentsRepository,
}) : super(const CommentsState());
void setReplyId(int? replyId) {
emit((state as CommentsStateLoaded).copyWith(replyId: replyId));
}
Future<void> getComments(String id, CommentSourceType commentSourceType, [bool isFirstFetch = false]) async {
if (isFirstFetch) emit(const CommentsState.loading());
try {
switch (commentSourceType) {
case CommentSourceType.blogPost:
emit(CommentsState.loaded(comment: await feedRepository.getBlogPostComments(id: id)));
break;
case CommentSourceType.diet:
emit(CommentsState.loaded(comment: await feedRepository.getDietsComments(id: id)));
break;
case CommentSourceType.recipe:
emit(CommentsState.loaded(comment: await feedRepository.getRecipesComments(id: id)));
break;
case CommentSourceType.plan:
emit(CommentsState.loaded(comment: await feedRepository.getPlansComments(slug: id)));
break;
}
} catch (e) {
emit(CommentsState.error(errorMessage: e.toString()));
}
}
Future<void> sendComment({
required String id,
required String commentText,
required CommentSourceType commentSourceType,
int? parentCommentId,
}) async {
try {
switch (commentSourceType) {
case CommentSourceType.blogPost:
await feedRepository.sendBlogPostComment(
id: id,
commentText: commentText,
parentCommentId: parentCommentId,
);
break;
case CommentSourceType.diet:
await feedRepository.sendDietsComment(
id: id,
commentText: commentText,
parentCommentId: parentCommentId,
);
break;
case CommentSourceType.recipe:
await feedRepository.sendRecipesComment(
id: id,
commentText: commentText,
parentCommentId: parentCommentId,
);
break;
case CommentSourceType.plan:
await feedRepository.sendPlansComment(
slug: id,
commentText: commentText,
parentCommentId: parentCommentId,
);
break;
}
getComments(id, commentSourceType);
} catch (e) {
emit(CommentsState.error(errorMessage: e.toString()));
}
}
Future<bool> deleteComment({required int id}) async {
try {
await commentsRepository.deleteComment(id: id);
return true;
} catch (e, st) {
log(e.toString(), stackTrace: st);
}
return false;
}
Future<bool> updateComment({required int id, required String body}) async {
try {
await commentsRepository.updateComment(id: id, body: body);
return true;
} catch (e, st) {
log(e.toString(), stackTrace: st);
}
return false;
}
}

View File

@@ -0,0 +1,20 @@
import 'package:eatvio_app/features/feed/models/comment_model.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'comments_state.freezed.dart';
@freezed
abstract class CommentsState with _$CommentsState {
const factory CommentsState() = _CommentsState;
const factory CommentsState.loading() = CommentsStateLoading;
const factory CommentsState.loaded({
required CommentModel comment,
int? replyId,
}) = CommentsStateLoaded;
const factory CommentsState.error({
required String errorMessage,
}) = CommentsStateError;
}