mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-03 19:54:12 +00:00 
			
		
		
		
	Show newly created comment
This commit is contained in:
		@@ -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);
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user