Add comment pfp, op, banned

This commit is contained in:
krawieck 2020-08-31 15:29:02 +02:00
parent 663d4bb913
commit 6704fed4e5
2 changed files with 83 additions and 4 deletions

View File

@ -5,12 +5,20 @@ import 'markdown_text.dart';
class CommentWidget extends StatelessWidget {
final int indent;
final int postCreatorId;
final CommentTree commentTree;
CommentWidget(
this.commentTree, {
this.indent = 0,
@required this.postCreatorId,
});
void _goToUser() {
print('GO TO USER');
}
bool get isOP => commentTree.comment.creatorId == postCreatorId;
@override
Widget build(BuildContext context) {
var comment = commentTree.comment;
@ -47,7 +55,38 @@ class CommentWidget extends StatelessWidget {
child: Column(
children: [
Row(children: [
Text(comment.creatorPreferredUsername ?? comment.creatorName),
if (comment.creatorAvatar != null)
InkWell(
onTap: _goToUser,
child: Padding(
padding: const EdgeInsets.only(right: 5),
child: CachedNetworkImage(
imageUrl: comment.creatorAvatar,
height: 20,
width: 20,
imageBuilder: (context, imageProvider) => Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.cover,
image: imageProvider,
),
),
),
),
),
),
InkWell(
child: Text(username,
style: TextStyle(
color: Theme.of(context).accentColor,
)),
onLongPress: _goToUser,
),
if (isOP) CommentTag('OP', Theme.of(context).accentColor),
if (comment.banned) CommentTag('BANNED', Colors.red),
if (comment.bannedFromCommunity)
CommentTag('BANNED FROM COMMUNITY', Colors.red),
Spacer(),
Text(comment.score.toString()),
]),
@ -68,8 +107,37 @@ class CommentWidget extends StatelessWidget {
top: BorderSide(width: 0.2))),
),
for (var c in commentTree.children)
CommentWidget(c, indent: indent + 1),
CommentWidget(
c,
indent: indent + 1,
postCreatorId: postCreatorId,
),
],
);
}
}
class CommentTag extends StatelessWidget {
final String text;
final Color bgColor;
const CommentTag(this.text, this.bgColor);
@override
Widget build(BuildContext context) => Padding(
padding: const EdgeInsets.only(left: 5),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(5)),
color: bgColor,
),
padding: EdgeInsets.symmetric(horizontal: 3, vertical: 2),
child: Text(text,
style: TextStyle(
color: Colors.white,
fontSize: Theme.of(context).textTheme.bodyText1.fontSize - 5,
fontWeight: FontWeight.w800,
)),
),
);
}

View File

@ -9,15 +9,26 @@ import 'comment_tree.dart';
class CommentsWidget extends HookWidget {
final List<CommentView> rawComments;
final List<CommentTree> comments;
final int postCreatorId;
CommentsWidget(this.rawComments)
CommentsWidget(this.rawComments, this.postCreatorId)
: comments = CommentTree.fromList(rawComments);
@override
Widget build(BuildContext context) {
var sorting = useState(SortType.active);
return Column(children: [
// sorting menu goes here
for (var com in comments) CommentWidget(com),
if (comments.length == 0)
Padding(
padding: EdgeInsets.symmetric(vertical: 50),
child: Text(
'no comments yet',
style: TextStyle(fontStyle: FontStyle.italic),
),
),
for (var com in comments)
CommentWidget(com, postCreatorId: postCreatorId),
]);
}
}