mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-12-24 11:58:51 +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:math';
|
||||
|
||||
import 'package:comunic/enums/post_kind.dart';
|
||||
import 'package:comunic/enums/post_visibility_level.dart';
|
||||
@ -76,6 +77,7 @@ class _PostTileState extends State<PostTile> {
|
||||
TextEditingController _commentController = TextEditingController();
|
||||
File _commentImage;
|
||||
bool _submitting = false;
|
||||
int _maxNumberOfCommentToShow = 10;
|
||||
|
||||
User get _user => widget.usersInfo.getUser(widget.post.userID);
|
||||
|
||||
@ -344,13 +346,18 @@ class _PostTileState extends State<PostTile> {
|
||||
assert(widget.post.hasComments);
|
||||
|
||||
final comments = List<Widget>.generate(
|
||||
widget.post.comments.length,
|
||||
(num) => CommentTile(
|
||||
comment: widget.post.comments[num],
|
||||
user: widget.usersInfo.getUser(widget.post.comments[num].userID),
|
||||
onUpdateComment: _updateCommentContent,
|
||||
onDeleteComment: _deleteComment,
|
||||
),
|
||||
min(widget.post.comments.length, _maxNumberOfCommentToShow),
|
||||
(num) {
|
||||
final index = num +
|
||||
max(0, widget.post.comments.length - _maxNumberOfCommentToShow);
|
||||
final comment = widget.post.comments[index];
|
||||
return CommentTile(
|
||||
comment: comment,
|
||||
user: widget.usersInfo.getUser(comment.userID),
|
||||
onUpdateComment: _updateCommentContent,
|
||||
onDeleteComment: _deleteComment,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
// Add comments form
|
||||
@ -361,12 +368,23 @@ class _PostTileState extends State<PostTile> {
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 8.0, bottom: 8.0),
|
||||
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
|
||||
Widget _buildCommentsForm() {
|
||||
return Padding(
|
||||
|
Loading…
Reference in New Issue
Block a user