1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-18 03:09:36 +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;
String _selectedItem;

View File

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