mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 21:09: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"];
|
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
|
/// Turn an API entry into a [Comment] object
|
||||||
static Comment apiToComment(Map<String, dynamic> entry) {
|
static Comment apiToComment(Map<String, dynamic> entry) {
|
||||||
return Comment(
|
return Comment(
|
||||||
|
@ -45,6 +45,9 @@ class PostTile extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _PostTileState extends State<PostTile> {
|
class _PostTileState extends State<PostTile> {
|
||||||
|
// Helpers
|
||||||
|
final _commentsHelper = CommentsHelper();
|
||||||
|
|
||||||
// Class members
|
// Class members
|
||||||
TextEditingController _commentController = TextEditingController();
|
TextEditingController _commentController = TextEditingController();
|
||||||
File _commentImage;
|
File _commentImage;
|
||||||
@ -308,7 +311,7 @@ class _PostTileState extends State<PostTile> {
|
|||||||
Future<void> _submitComment() async {
|
Future<void> _submitComment() async {
|
||||||
_sendingComment = true;
|
_sendingComment = true;
|
||||||
|
|
||||||
final commentID = await CommentsHelper().createComment(NewComment(
|
final commentID = await _commentsHelper.createComment(NewComment(
|
||||||
postID: widget.post.id,
|
postID: widget.post.id,
|
||||||
content: _commentController.text,
|
content: _commentController.text,
|
||||||
image: _commentImage,
|
image: _commentImage,
|
||||||
@ -322,5 +325,14 @@ class _PostTileState extends State<PostTile> {
|
|||||||
clearCommentForm();
|
clearCommentForm();
|
||||||
|
|
||||||
// Get and show new comment
|
// 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