feat: add reaction emoji to issue screen

This commit is contained in:
Rongjian Zhang 2019-03-21 01:21:50 +08:00
parent a4d00e5a81
commit af79d33a7f
2 changed files with 77 additions and 27 deletions

View File

@ -9,6 +9,15 @@ import '../widgets/comment_item.dart';
import '../providers/settings.dart'; import '../providers/settings.dart';
import '../widgets/action.dart'; import '../widgets/action.dart';
var reactionChunk = emojiMap.entries.map((entry) {
var key = entry.key;
return '''
$key: reactions(content: $key) {
totalCount
viewerHasReacted
}''';
}).join('\n');
/// Screen for issue and pull request /// Screen for issue and pull request
class IssueScreen extends StatefulWidget { class IssueScreen extends StatefulWidget {
final int number; final int number;
@ -53,6 +62,7 @@ author {
} }
closed closed
url url
$reactionChunk
'''; ''';
if (isPullRequest) { if (isPullRequest) {
@ -78,6 +88,7 @@ __typename
login login
avatarUrl avatarUrl
} }
$reactionChunk
} }
... on Commit { ... on Commit {
committedDate committedDate

View File

@ -4,6 +4,17 @@ import '../utils/utils.dart';
import 'avatar.dart'; import 'avatar.dart';
import 'user_name.dart'; import 'user_name.dart';
final emojiMap = {
'THUMBS_UP': '👍',
'THUMBS_DOWN': '👎',
'LAUGH': '😄',
'HOORAY': '🎉',
'CONFUSED': '😕',
'HEART': '❤️',
'ROCKET': '🚀',
'EYES': '👀'
};
class CommentItem extends StatelessWidget { class CommentItem extends StatelessWidget {
final Map<String, dynamic> payload; final Map<String, dynamic> payload;
@ -11,35 +22,63 @@ class CommentItem extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column(children: <Widget>[ return Column(
Row(children: <Widget>[ crossAxisAlignment: CrossAxisAlignment.start,
Avatar( children: <Widget>[
url: payload['author']['avatarUrl'], Row(children: <Widget>[
size: 16, Avatar(
login: payload['author']['login'], url: payload['author']['avatarUrl'],
), size: 16,
Padding(padding: EdgeInsets.only(left: 6)), login: payload['author']['login'],
Expanded( ),
child: Column( Padding(padding: EdgeInsets.only(left: 6)),
crossAxisAlignment: CrossAxisAlignment.start, Expanded(
children: <Widget>[ child: Column(
UserName(payload['author']['login']), crossAxisAlignment: CrossAxisAlignment.start,
Padding(padding: EdgeInsets.only(bottom: 2)), children: <Widget>[
Text( UserName(payload['author']['login']),
TimeAgo.formatFromString(payload['createdAt']), Padding(padding: EdgeInsets.only(bottom: 2)),
style: TextStyle(color: Colors.black54, fontSize: 13), Text(
), TimeAgo.formatFromString(payload['createdAt']),
], style: TextStyle(color: Colors.black54, fontSize: 13),
),
],
),
),
]),
Padding(
padding: const EdgeInsets.only(top: 12),
child: MarkdownBody(
data: payload['body'],
// styleSheet: MarkdownStyleSheet(code: TextStyle(fontSize: 14)),
), ),
), ),
]), Wrap(
Padding( children: emojiMap.entries
padding: const EdgeInsets.only(left: 36, top: 8), .where((entry) => payload[entry.key]['totalCount'] != 0)
child: MarkdownBody( .map((entry) {
data: payload['body'], var emoji = entry.value;
// styleSheet: MarkdownStyleSheet(code: TextStyle(fontSize: 14)), int count = payload[entry.key]['totalCount'];
return Container(
padding: EdgeInsets.all(6),
child: RichText(
text: TextSpan(
style: TextStyle(fontSize: 16),
children: [
TextSpan(text: emoji),
TextSpan(text: ' '),
TextSpan(
text: count.toString(),
style: TextStyle(color: Palette.link),
),
],
),
),
);
}).toList(),
), ),
), ],
]); );
} }
} }