mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 21:09:21 +00:00
Do not show too many comments at the same time
This commit is contained in:
parent
313e7a4b3c
commit
7f1130aca8
@ -1,4 +1,5 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:comunic/enums/post_kind.dart';
|
import 'package:comunic/enums/post_kind.dart';
|
||||||
import 'package:comunic/enums/post_visibility_level.dart';
|
import 'package:comunic/enums/post_visibility_level.dart';
|
||||||
@ -76,6 +77,7 @@ class _PostTileState extends State<PostTile> {
|
|||||||
TextEditingController _commentController = TextEditingController();
|
TextEditingController _commentController = TextEditingController();
|
||||||
File _commentImage;
|
File _commentImage;
|
||||||
bool _submitting = false;
|
bool _submitting = false;
|
||||||
|
int _maxNumberOfCommentToShow = 10;
|
||||||
|
|
||||||
User get _user => widget.usersInfo.getUser(widget.post.userID);
|
User get _user => widget.usersInfo.getUser(widget.post.userID);
|
||||||
|
|
||||||
@ -344,13 +346,18 @@ class _PostTileState extends State<PostTile> {
|
|||||||
assert(widget.post.hasComments);
|
assert(widget.post.hasComments);
|
||||||
|
|
||||||
final comments = List<Widget>.generate(
|
final comments = List<Widget>.generate(
|
||||||
widget.post.comments.length,
|
min(widget.post.comments.length, _maxNumberOfCommentToShow),
|
||||||
(num) => CommentTile(
|
(num) {
|
||||||
comment: widget.post.comments[num],
|
final index = num +
|
||||||
user: widget.usersInfo.getUser(widget.post.comments[num].userID),
|
max(0, widget.post.comments.length - _maxNumberOfCommentToShow);
|
||||||
onUpdateComment: _updateCommentContent,
|
final comment = widget.post.comments[index];
|
||||||
onDeleteComment: _deleteComment,
|
return CommentTile(
|
||||||
),
|
comment: comment,
|
||||||
|
user: widget.usersInfo.getUser(comment.userID),
|
||||||
|
onUpdateComment: _updateCommentContent,
|
||||||
|
onDeleteComment: _deleteComment,
|
||||||
|
);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add comments form
|
// Add comments form
|
||||||
@ -361,12 +368,23 @@ class _PostTileState extends State<PostTile> {
|
|||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.only(top: 8.0, bottom: 8.0),
|
padding: const EdgeInsets.only(top: 8.0, bottom: 8.0),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: comments,
|
children: (widget.post.comments.length > _maxNumberOfCommentToShow
|
||||||
|
? [_buildShowMoreCommentsButton()]
|
||||||
|
: [])
|
||||||
|
..addAll(comments),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildShowMoreCommentsButton() => InkWell(
|
||||||
|
onTap: () => setState(() => _maxNumberOfCommentToShow += 10),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Text(tr("Show more comments")),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
/// Build comments form
|
/// Build comments form
|
||||||
Widget _buildCommentsForm() {
|
Widget _buildCommentsForm() {
|
||||||
return Padding(
|
return Padding(
|
||||||
|
Loading…
Reference in New Issue
Block a user