comments delete and report + bug fixes
This commit is contained in:
parent
a52ac7cdae
commit
257e4b6a59
|
|
@ -145,6 +145,8 @@ class RequestHelper {
|
|||
baseUrl + '/$type/$id/comments/$commentId/feedback';
|
||||
static String addComment(int id, String type) =>
|
||||
baseUrl + '/$type/$id/comments/add';
|
||||
static String deleteComment(int id) => baseUrl + '/comment/$id';
|
||||
static String reportComment(int id) => baseUrl + '/comment/$id/report';
|
||||
|
||||
static String _urlConcatGenerator(List<MapEntry<String, dynamic>> additions) {
|
||||
String result = '';
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import 'package:didvan/constants/app_icons.dart';
|
|||
import 'package:didvan/constants/assets.dart';
|
||||
import 'package:didvan/models/view/app_bar_data.dart';
|
||||
import 'package:didvan/views/home/comments/comments_state.dart';
|
||||
import 'package:didvan/views/home/comments/widgets/comment_item.dart';
|
||||
import 'package:didvan/views/home/comments/widgets/comment.dart';
|
||||
import 'package:didvan/views/widgets/animated_visibility.dart';
|
||||
import 'package:didvan/views/widgets/didvan/icon_button.dart';
|
||||
import 'package:didvan/views/widgets/didvan/scaffold.dart';
|
||||
|
|
|
|||
|
|
@ -4,10 +4,12 @@ import 'package:didvan/models/comment/feedback.dart';
|
|||
import 'package:didvan/models/comment/reply.dart';
|
||||
import 'package:didvan/models/comment/user.dart';
|
||||
import 'package:didvan/models/enums.dart';
|
||||
import 'package:didvan/models/view/alert_data.dart';
|
||||
import 'package:didvan/providers/core.dart';
|
||||
import 'package:didvan/providers/user.dart';
|
||||
import 'package:didvan/services/network/request.dart';
|
||||
import 'package:didvan/services/network/request_helper.dart';
|
||||
import 'package:didvan/utils/action_sheet.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class CommentsState extends CoreProvier {
|
||||
|
|
@ -158,4 +160,42 @@ class CommentsState extends CoreProvier {
|
|||
replyingTo = null;
|
||||
}
|
||||
}
|
||||
|
||||
void reportComment(int id) {
|
||||
final service = RequestService(RequestHelper.reportComment(id));
|
||||
service.post();
|
||||
ActionSheetUtils.showAlert(
|
||||
AlertData(
|
||||
message: 'گزارش شما با موفقیت ثبت شد و به زودی بررسی میگردد.',
|
||||
aLertType: ALertType.success,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void deleteComment(int id, int? rootId) {
|
||||
final service = RequestService(RequestHelper.deleteComment(id));
|
||||
service.delete();
|
||||
if (rootId == null) {
|
||||
final comment = comments.firstWhere((element) => element.id == id);
|
||||
if (comment.replies.isNotEmpty) {
|
||||
comments.insertAll(
|
||||
comments.indexOf(comment),
|
||||
comment.replies.map(
|
||||
(rep) => CommentData(
|
||||
id: rep.id,
|
||||
text: rep.text,
|
||||
createdAt: rep.createdAt,
|
||||
liked: rep.liked,
|
||||
disliked: rep.disliked,
|
||||
feedback: rep.feedback,
|
||||
user: rep.user,
|
||||
replies: [],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
comments.remove(comment);
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,13 @@ import 'package:didvan/config/design_config.dart';
|
|||
import 'package:didvan/config/theme_data.dart';
|
||||
import 'package:didvan/constants/app_icons.dart';
|
||||
import 'package:didvan/models/comment/comment.dart';
|
||||
import 'package:didvan/models/comment/reply.dart';
|
||||
import 'package:didvan/models/view/action_sheet_data.dart';
|
||||
import 'package:didvan/providers/user.dart';
|
||||
import 'package:didvan/utils/action_sheet.dart';
|
||||
import 'package:didvan/utils/date_time.dart';
|
||||
import 'package:didvan/views/home/comments/comments_state.dart';
|
||||
import 'package:didvan/views/home/widgets/menu_item.dart';
|
||||
import 'package:didvan/views/widgets/animated_visibility.dart';
|
||||
import 'package:didvan/views/widgets/didvan/icon_button.dart';
|
||||
import 'package:didvan/views/widgets/didvan/text.dart';
|
||||
|
|
@ -84,17 +89,24 @@ class CommentState extends State<Comment> {
|
|||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
DidvanText(
|
||||
comment.user.fullName,
|
||||
style: Theme.of(context).textTheme.bodyText1,
|
||||
),
|
||||
const Spacer(),
|
||||
DidvanText(
|
||||
DateTimeUtils.momentGenerator(comment.createdAt),
|
||||
style: Theme.of(context).textTheme.caption,
|
||||
color: Theme.of(context).colorScheme.caption,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
DidvanIconButton(
|
||||
size: 18,
|
||||
gestureSize: 24,
|
||||
icon: DidvanIcons.menu_light,
|
||||
onPressed: () => _showCommentActions(comment),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
|
|
@ -171,6 +183,42 @@ class CommentState extends State<Comment> {
|
|||
],
|
||||
),
|
||||
);
|
||||
|
||||
Future<void> _showCommentActions(comment) async {
|
||||
ActionSheetUtils.showBottomSheet(
|
||||
data: ActionSheetData(
|
||||
title: 'گزینههای نظر',
|
||||
content: Column(
|
||||
children: [
|
||||
if (comment.user.id != context.read<UserProvider>().user.id)
|
||||
MenuItem(
|
||||
title: 'گزارش محتوای نامناسب',
|
||||
onTap: () {
|
||||
state.reportComment(comment.id);
|
||||
ActionSheetUtils.pop();
|
||||
},
|
||||
icon: DidvanIcons.alert_regular,
|
||||
),
|
||||
if (comment.user.id == context.read<UserProvider>().user.id)
|
||||
MenuItem(
|
||||
title: 'حذف نظر',
|
||||
color: Theme.of(context).colorScheme.secondary,
|
||||
onTap: () {
|
||||
state.deleteComment(
|
||||
comment.id,
|
||||
comment.runtimeType == Reply ? _comment.id : null,
|
||||
);
|
||||
ActionSheetUtils.pop();
|
||||
},
|
||||
icon: DidvanIcons.trash_solid,
|
||||
),
|
||||
],
|
||||
),
|
||||
hasConfirmButton: false,
|
||||
hasDismissButton: false,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _FeedbackButtons extends StatefulWidget {
|
||||
|
|
@ -88,7 +88,6 @@ class _StudioDetailsState extends State<StudioDetails> {
|
|||
),
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
child: SizedBox(
|
||||
height: d.size.height - d.padding.top - 56,
|
||||
child: Column(
|
||||
|
|
|
|||
Loading…
Reference in New Issue