1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-18 11:19:28 +01:00

refactor(gh): reactions

This commit is contained in:
Rongjian Zhang 2020-02-08 13:02:12 +08:00
parent 3d9e2fd5e1
commit 381c3ef896
2 changed files with 11 additions and 69 deletions

View File

@ -262,64 +262,6 @@ class ThemeModel with ChangeNotifier {
// ); // );
} }
Future<T> showDialogOptions<T>(
BuildContext context, List<DialogOption<T>> options) {
var title = Text('Pick your reaction');
var cancelWidget = Text('Cancel');
switch (theme) {
case AppThemeType.cupertino:
return showCupertinoDialog<T>(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
title: title,
actions: options.map((option) {
return CupertinoDialogAction(
child: option.widget,
onPressed: () {
Navigator.pop(context, option.value);
},
);
}).toList()
..add(
CupertinoDialogAction(
child: cancelWidget,
isDestructiveAction: true,
onPressed: () {
Navigator.pop(context, null);
},
),
),
);
},
);
default:
return showDialog(
context: context,
builder: (BuildContext context) {
return SimpleDialog(
title: title,
children: options.map<Widget>((option) {
return SimpleDialogOption(
child: option.widget,
onPressed: () {
Navigator.pop(context, option.value);
},
);
}).toList()
..add(SimpleDialogOption(
child: cancelWidget,
onPressed: () {
Navigator.pop(context, null);
},
)),
);
},
);
}
}
static Timer _debounce; static Timer _debounce;
String _selectedItem; String _selectedItem;

View File

@ -1,6 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:git_touch/models/auth.dart'; import 'package:git_touch/models/auth.dart';
import 'package:git_touch/models/theme.dart'; import 'package:git_touch/models/theme.dart';
import 'package:git_touch/widgets/action_button.dart';
import 'package:git_touch/widgets/markdown_view.dart'; import 'package:git_touch/widgets/markdown_view.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:timeago/timeago.dart' as timeago; import 'package:timeago/timeago.dart' as timeago;
@ -37,9 +38,10 @@ class _GhEmojiActionState extends State<GhEmojiAction> {
get payload => widget.payload; get payload => widget.payload;
onReaction(String emojiKey, bool isRemove) async { onReaction(String emojiKey) async {
if (emojiKey == null) return; if (emojiKey == null) return;
final isRemove = _hasReacted(emojiKey);
var id = payload['id'] as String; var id = payload['id'] as String;
var operation = isRemove ? 'remove' : 'add'; var operation = isRemove ? 'remove' : 'add';
await Provider.of<AuthModel>(context).query(''' await Provider.of<AuthModel>(context).query('''
@ -75,7 +77,7 @@ mutation {
return Link( return Link(
onTap: () { onTap: () {
onReaction(emojiKey, _hasReacted(emojiKey)); onReaction(emojiKey);
}, },
child: Container( child: Container(
padding: EdgeInsets.all(4), padding: EdgeInsets.all(4),
@ -95,20 +97,18 @@ mutation {
}), }),
Link( Link(
onTap: () async { onTap: () async {
final result = await theme.showDialogOptions( await theme.showActions(
context, context,
emojiMap.entries.map((entry) { emojiMap.entries.map((entry) {
var emojiKey = entry.key; final emojiKey = entry.key;
return DialogOption( return ActionItem(
value: emojiKey, text: emojiKey + ' ' + entry.value,
widget: Container( onTap: (_) {
decoration: _getDecorationByKey(emojiKey), onReaction(emojiKey);
child: Text(emojiKey + ' ' + entry.value), },
),
); );
}).toList(), }).toList(),
); );
onReaction(result, _hasReacted(result));
}, },
child: Container( child: Container(
padding: EdgeInsets.all(4), padding: EdgeInsets.all(4),