2019-01-28 14:32:01 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2019-09-02 15:52:32 +02:00
|
|
|
import 'package:git_touch/models/theme.dart';
|
2019-09-13 10:27:33 +02:00
|
|
|
import 'package:git_touch/widgets/markdown_view.dart';
|
2019-09-02 15:52:32 +02:00
|
|
|
import 'package:provider/provider.dart';
|
2019-08-31 14:44:59 +02:00
|
|
|
import 'package:timeago/timeago.dart' as timeago;
|
2019-05-12 09:14:28 +02:00
|
|
|
import 'package:primer/primer.dart';
|
2019-01-31 07:37:25 +01:00
|
|
|
import '../utils/utils.dart';
|
2019-02-07 07:35:19 +01:00
|
|
|
import 'avatar.dart';
|
2019-04-05 15:19:00 +02:00
|
|
|
import 'link.dart';
|
2019-02-07 07:35:19 +01:00
|
|
|
import 'user_name.dart';
|
2019-01-28 14:32:01 +01:00
|
|
|
|
2019-03-20 18:21:50 +01:00
|
|
|
final emojiMap = {
|
|
|
|
'THUMBS_UP': '👍',
|
|
|
|
'THUMBS_DOWN': '👎',
|
|
|
|
'LAUGH': '😄',
|
|
|
|
'HOORAY': '🎉',
|
|
|
|
'CONFUSED': '😕',
|
|
|
|
'HEART': '❤️',
|
|
|
|
'ROCKET': '🚀',
|
|
|
|
'EYES': '👀'
|
|
|
|
};
|
|
|
|
|
2019-01-28 14:32:01 +01:00
|
|
|
class CommentItem extends StatelessWidget {
|
2019-02-19 08:25:15 +01:00
|
|
|
final Map<String, dynamic> payload;
|
2019-04-05 15:19:00 +02:00
|
|
|
final Function(String emojiKey, bool isRemove) onReaction;
|
2019-01-28 14:32:01 +01:00
|
|
|
|
2019-04-05 15:19:00 +02:00
|
|
|
CommentItem(this.payload, {@required this.onReaction});
|
|
|
|
|
|
|
|
bool _hasReacted(String emojiKey) {
|
|
|
|
if (payload[emojiKey] == null) return false;
|
|
|
|
return payload[emojiKey]['viewerHasReacted'] as bool;
|
|
|
|
}
|
|
|
|
|
|
|
|
Decoration _getDecorationByKey(String emojiKey) {
|
|
|
|
return BoxDecoration(
|
2019-05-12 09:14:28 +02:00
|
|
|
color:
|
|
|
|
_hasReacted(emojiKey) ? PrimerColors.blue000 : Colors.transparent);
|
2019-04-05 15:19:00 +02:00
|
|
|
}
|
2019-01-28 14:32:01 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2019-11-08 11:29:08 +01:00
|
|
|
final theme = Provider.of<ThemeModel>(context);
|
|
|
|
|
2019-03-20 18:21:50 +01:00
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
Row(children: <Widget>[
|
2019-10-03 04:12:22 +02:00
|
|
|
Link(
|
2019-12-12 13:29:56 +01:00
|
|
|
url: '/' + payload['author']['login'],
|
2019-10-03 04:12:22 +02:00
|
|
|
child: Avatar.medium(url: payload['author']['avatarUrl']),
|
2019-03-20 18:21:50 +01:00
|
|
|
),
|
2019-09-07 11:48:59 +02:00
|
|
|
SizedBox(width: 8),
|
2019-03-20 18:21:50 +01:00
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
UserName(payload['author']['login']),
|
2019-09-07 11:48:59 +02:00
|
|
|
SizedBox(height: 2),
|
2019-03-20 18:21:50 +01:00
|
|
|
Text(
|
2019-08-31 14:44:59 +02:00
|
|
|
timeago.format(DateTime.parse(payload['createdAt'])),
|
2019-11-08 11:29:08 +01:00
|
|
|
style: TextStyle(
|
|
|
|
color: theme.palette.tertiaryText, fontSize: 13),
|
2019-03-20 18:21:50 +01:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
]),
|
2019-09-07 11:48:59 +02:00
|
|
|
SizedBox(height: 12),
|
2019-09-13 10:27:33 +02:00
|
|
|
MarkdownView(payload['body'] as String),
|
2019-09-07 11:48:59 +02:00
|
|
|
SizedBox(height: 12),
|
2019-03-20 18:21:50 +01:00
|
|
|
Wrap(
|
2019-09-07 11:48:59 +02:00
|
|
|
crossAxisAlignment: WrapCrossAlignment.center,
|
|
|
|
children: [
|
|
|
|
...emojiMap.entries
|
|
|
|
.where((entry) => payload[entry.key]['totalCount'] as int != 0)
|
|
|
|
.map<Widget>((entry) {
|
|
|
|
var emojiKey = entry.key;
|
|
|
|
var emoji = entry.value;
|
|
|
|
var count = payload[entry.key]['totalCount'] as int;
|
2019-03-20 18:21:50 +01:00
|
|
|
|
2019-09-07 11:48:59 +02:00
|
|
|
return Link(
|
|
|
|
onTap: () {
|
|
|
|
onReaction(emojiKey, _hasReacted(emojiKey));
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.all(4),
|
|
|
|
decoration: _getDecorationByKey(emojiKey),
|
|
|
|
child: Wrap(
|
|
|
|
crossAxisAlignment: WrapCrossAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
Text(emoji, style: TextStyle(fontSize: 18)),
|
|
|
|
SizedBox(width: 4),
|
2019-09-13 17:34:19 +02:00
|
|
|
Text(numberFormat.format(count),
|
2019-09-07 11:48:59 +02:00
|
|
|
style: TextStyle(
|
2019-11-08 11:29:08 +01:00
|
|
|
color: theme.palette.primary, fontSize: 14))
|
2019-04-05 15:19:00 +02:00
|
|
|
],
|
|
|
|
),
|
2019-03-20 18:21:50 +01:00
|
|
|
),
|
2019-09-07 11:48:59 +02:00
|
|
|
);
|
|
|
|
}),
|
|
|
|
Link(
|
|
|
|
onTap: () async {
|
|
|
|
var result =
|
|
|
|
await Provider.of<ThemeModel>(context).showDialogOptions(
|
|
|
|
context,
|
|
|
|
emojiMap.entries.map((entry) {
|
|
|
|
var emojiKey = entry.key;
|
|
|
|
return DialogOption(
|
|
|
|
value: emojiKey,
|
|
|
|
widget: Container(
|
|
|
|
decoration: _getDecorationByKey(emojiKey),
|
|
|
|
child: Text(emojiKey + ' ' + entry.value),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}).toList());
|
|
|
|
onReaction(result, _hasReacted(result));
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.all(4),
|
|
|
|
child: Wrap(
|
|
|
|
crossAxisAlignment: WrapCrossAlignment.center,
|
|
|
|
children: <Widget>[
|
2019-11-08 11:29:08 +01:00
|
|
|
Text('+', style: TextStyle(color: theme.palette.primary)),
|
2019-09-07 11:48:59 +02:00
|
|
|
Icon(Octicons.smiley,
|
2019-11-08 11:29:08 +01:00
|
|
|
color: theme.palette.primary, size: 18),
|
2019-09-07 11:48:59 +02:00
|
|
|
],
|
2019-04-05 15:19:00 +02:00
|
|
|
),
|
2019-09-07 11:48:59 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2019-02-02 17:28:51 +01:00
|
|
|
),
|
2019-03-20 18:21:50 +01:00
|
|
|
],
|
|
|
|
);
|
2019-01-28 14:32:01 +01:00
|
|
|
}
|
|
|
|
}
|