mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 08:15:16 +00:00
Can update post content
This commit is contained in:
@ -31,7 +31,7 @@ const TextStyle _userNameStyle = TextStyle(
|
||||
fontSize: 16.0);
|
||||
|
||||
/// Post actions
|
||||
enum _PostActions { DELETE }
|
||||
enum _PostActions { DELETE, UPDATE_CONTENT }
|
||||
|
||||
class PostTile extends StatefulWidget {
|
||||
final Post post;
|
||||
@ -99,6 +99,13 @@ class _PostTileState extends State<PostTile> {
|
||||
|
||||
PopupMenuButton<_PostActions>(
|
||||
itemBuilder: (c) => [
|
||||
// Update post content
|
||||
PopupMenuItem(
|
||||
child: Text(tr("Update content")),
|
||||
value: _PostActions.UPDATE_CONTENT,
|
||||
enabled: widget.post.canUpdate,
|
||||
),
|
||||
|
||||
// Delete post
|
||||
PopupMenuItem(
|
||||
child: Text(tr("Delete")),
|
||||
@ -422,12 +429,38 @@ class _PostTileState extends State<PostTile> {
|
||||
/// Method called each time the user has selected an option
|
||||
void _selectedPostMenuAction(_PostActions value) {
|
||||
switch (value) {
|
||||
// Update post content
|
||||
case _PostActions.UPDATE_CONTENT:
|
||||
updateContent();
|
||||
break;
|
||||
|
||||
// Delete post
|
||||
case _PostActions.DELETE:
|
||||
confirmDelete();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// Update post content
|
||||
Future<void> updateContent() async {
|
||||
final newContent = await askUserString(
|
||||
context: context,
|
||||
title: tr("Update post content"),
|
||||
message: tr("Please enter message content: "),
|
||||
defaultValue: widget.post.content,
|
||||
hint: tr("Post content"),
|
||||
);
|
||||
|
||||
if (newContent == null) return;
|
||||
|
||||
if (!await _postsHelper.updateContent(widget.post.id, newContent)) {
|
||||
showSimpleSnack(context, tr("Could not update post content!"));
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() => widget.post.content = newContent);
|
||||
}
|
||||
|
||||
/// Perform the deletion of the post
|
||||
Future<void> confirmDelete() async {
|
||||
// Ask user confirmation
|
||||
|
Reference in New Issue
Block a user