mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 04:49:21 +00:00
Show newly created comment
This commit is contained in:
parent
1f899f7594
commit
754745fd5f
@ -25,6 +25,18 @@ class CommentsHelper {
|
||||
return response.getObject()["commentID"];
|
||||
}
|
||||
|
||||
/// Get a single comment from the server, specified by its [id]
|
||||
Future<Comment> getSingle(int id) async {
|
||||
final response = await APIRequest(
|
||||
uri: "comments/get_single",
|
||||
needLogin: true,
|
||||
args: {"commentID": id.toString()}).exec();
|
||||
|
||||
if (response.code != 200) return null;
|
||||
|
||||
return apiToComment(response.getObject());
|
||||
}
|
||||
|
||||
/// Turn an API entry into a [Comment] object
|
||||
static Comment apiToComment(Map<String, dynamic> entry) {
|
||||
return Comment(
|
||||
|
@ -45,6 +45,9 @@ class PostTile extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _PostTileState extends State<PostTile> {
|
||||
// Helpers
|
||||
final _commentsHelper = CommentsHelper();
|
||||
|
||||
// Class members
|
||||
TextEditingController _commentController = TextEditingController();
|
||||
File _commentImage;
|
||||
@ -308,7 +311,7 @@ class _PostTileState extends State<PostTile> {
|
||||
Future<void> _submitComment() async {
|
||||
_sendingComment = true;
|
||||
|
||||
final commentID = await CommentsHelper().createComment(NewComment(
|
||||
final commentID = await _commentsHelper.createComment(NewComment(
|
||||
postID: widget.post.id,
|
||||
content: _commentController.text,
|
||||
image: _commentImage,
|
||||
@ -322,5 +325,14 @@ class _PostTileState extends State<PostTile> {
|
||||
clearCommentForm();
|
||||
|
||||
// Get and show new comment
|
||||
final newComment = await _commentsHelper.getSingle(commentID);
|
||||
|
||||
if (newComment == null)
|
||||
return showSimpleSnack(
|
||||
context, tr("Could not retrieve created comment!"));
|
||||
|
||||
setState(() {
|
||||
widget.post.comments.add(newComment);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user