1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2025-06-19 00:05:16 +00:00

Can delete comments

This commit is contained in:
2019-05-18 16:48:19 +02:00
parent 55088f2b23
commit 6d73d38bf8
5 changed files with 64 additions and 5 deletions

View File

@ -9,16 +9,20 @@ import 'package:flutter/material.dart';
///
/// @author Pierre HUBERT
enum _CommentAction { DELETE }
class CommentTile extends StatelessWidget {
final Comment comment;
final User user;
final void Function(Comment) onUpdateLike;
final void Function(Comment) onDeleteComment;
const CommentTile({
Key key,
@required this.comment,
@required this.user,
@required this.onUpdateLike,
@required this.onDeleteComment,
}) : assert(comment != null),
assert(user != null),
assert(onUpdateLike != null),
@ -27,9 +31,7 @@ class CommentTile extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ListTile(
leading: AccountImageWidget(
user: user,
),
leading: _buildAccountImageWidget(),
title: Text(
user.displayName,
),
@ -37,6 +39,22 @@ class CommentTile extends StatelessWidget {
);
}
Widget _buildAccountImageWidget() {
return PopupMenuButton<_CommentAction>(
child: AccountImageWidget(
user: user,
),
onSelected: _selectedMenuOption,
itemBuilder: (c) => [
PopupMenuItem(
enabled: comment.isOwner,
child: Text("Delete"),
value: _CommentAction.DELETE,
)
],
);
}
Widget _buildCommentContent() {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
@ -106,4 +124,14 @@ class CommentTile extends StatelessWidget {
),
);
}
/// A menu option has been selected
void _selectedMenuOption(_CommentAction value) {
switch (value) {
// Delete comment
case _CommentAction.DELETE:
onDeleteComment(comment);
break;
}
}
}

View File

@ -195,6 +195,7 @@ class _PostTileState extends State<PostTile> {
comment: widget.post.comments[num],
user: widget.usersInfo.getUser(widget.post.comments[num].userID),
onUpdateLike: _updateCommentLike,
onDeleteComment: _deleteComment,
),
);
@ -290,7 +291,7 @@ class _PostTileState extends State<PostTile> {
Future<void> _pickImageForComment() async {
// Ask the user to confirm image removal if there is already one selected
if (_hasImage) {
if (await askUserConfirmation(
if (await showConfirmDialog(
context: context,
title: tr("Remove selected image"),
message: tr("Do you want to unselected currently selected image ?"),
@ -364,4 +365,22 @@ class _PostTileState extends State<PostTile> {
element.userLike ? element.likes++ : element.likes--;
});
}
/// Process the deletion of a user
Future<void> _deleteComment(Comment comment) async {
if (!await showConfirmDialog(
context: context,
message: tr("Do you really want to delete this comment ?"),
title: tr("Delete comment"))) return;
if (!await _commentsHelper.delete(comment.id)) {
showSimpleSnack(context, tr("Could not delete the comment!"));
return;
}
// Remove the comment from the list
setState(() {
widget.post.comments.remove(comment);
});
}
}