git-touch-android-ios-app/lib/screens/ge_pull.dart

268 lines
11 KiB
Dart
Raw Normal View History

2022-09-24 20:46:37 +02:00
import 'package:antd_mobile/antd_mobile.dart';
2022-10-06 09:55:35 +02:00
import 'package:flutter/widgets.dart';
2022-10-07 18:55:47 +02:00
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
2022-09-17 14:35:45 +02:00
import 'package:git_touch/models/auth.dart';
import 'package:git_touch/models/gitee.dart';
import 'package:git_touch/scaffolds/refresh_stateful.dart';
import 'package:git_touch/utils/utils.dart';
import 'package:git_touch/widgets/action_button.dart';
import 'package:git_touch/widgets/action_entry.dart';
import 'package:git_touch/widgets/avatar.dart';
import 'package:git_touch/widgets/comment_item.dart';
2022-09-17 14:35:45 +02:00
import 'package:git_touch/widgets/link.dart';
import 'package:primer/primer.dart';
import 'package:provider/provider.dart';
import 'package:tuple/tuple.dart';
class GePullScreen extends StatelessWidget {
2022-09-21 18:28:21 +02:00
const GePullScreen(this.owner, this.name, this.number, {this.isPr = false});
final String owner;
final String name;
final String number;
final bool isPr;
List<ActionItem> _buildCommentActionItem(
BuildContext context, GiteeComment comment) {
final auth = context.read<AuthModel>();
return [
ActionItem(
2022-09-17 15:57:43 +02:00
text: 'Edit',
onTap: (_) {
final uri = Uri(
path: '/gitee/$owner/$name/pulls/$number/comment',
queryParameters: {
'body': comment.body,
'id': comment.id.toString(),
},
).toString();
2022-09-22 19:50:45 +02:00
context.pushUrl(uri);
2022-09-17 15:57:43 +02:00
},
),
ActionItem(
text: 'Delete',
onTap: (_) async {
await auth.fetchGitee(
'/repos/$owner/$name/pulls/comments/${comment.id}',
requestType: 'DELETE');
2022-09-22 19:50:45 +02:00
await context.pushUrl('/gitee/$owner/$name/pulls/$number',
replace: true);
},
),
];
}
@override
Widget build(BuildContext context) {
return RefreshStatefulScaffold<
Tuple4<GiteePull, List<GiteeComment>, List<GiteePullFile>,
List<GiteeCommit>>>(
title: Text('Pull Request: #$number'),
fetch: () async {
final auth = context.read<AuthModel>();
final items = await Future.wait([
auth.fetchGitee('/repos/$owner/$name/pulls/$number'),
auth.fetchGitee('/repos/$owner/$name/pulls/$number/comments'),
auth.fetchGitee('/repos/$owner/$name/pulls/$number/files'),
auth.fetchGitee('/repos/$owner/$name/pulls/$number/commits'),
]);
return Tuple4(
GiteePull.fromJson(items[0]),
[for (var v in items[1]) GiteeComment.fromJson(v)],
[for (var v in items[2]) GiteePullFile.fromJson(v)],
[for (var v in items[3]) GiteeCommit.fromJson(v)]);
},
actionBuilder: (data, _) => ActionEntry(
iconData: Octicons.plus,
url: '/gitee/$owner/$name/pulls/$number/comment',
),
bodyBuilder: (data, _) {
final pull = data.item1;
final comments = data.item2;
final files = data.item3;
final commits = data.item4;
var additions = 0;
var deletions = 0;
2022-09-24 07:41:46 +02:00
for (final file in files) {
2021-05-16 09:16:35 +02:00
additions += int.parse(file.additions!);
deletions += int.parse(file.deletions!);
}
2022-09-17 14:35:45 +02:00
return Column(
children: <Widget>[
Container(
padding: CommonStyle.padding,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
LinkWidget(
url: '/gitee/$owner/$name',
child: Container(
padding: const EdgeInsets.symmetric(vertical: 8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
2021-05-16 09:16:35 +02:00
LinkWidget(
url: '/gitee/$owner/$name',
child: Row(
children: <Widget>[
Avatar(
2021-05-16 09:16:35 +02:00
url: pull.user!.avatarUrl,
size: AvatarSize.extraSmall,
),
2022-09-06 18:28:12 +02:00
const SizedBox(width: 4),
Text(
'$owner / $name',
style: TextStyle(
fontSize: 17,
2022-09-24 20:46:37 +02:00
color: AntTheme.of(context)
.colorTextSecondary,
),
),
2022-09-06 18:28:12 +02:00
const SizedBox(width: 4),
Text(
'#$number',
style: TextStyle(
fontSize: 17,
2022-09-24 20:46:37 +02:00
color: AntTheme.of(context).colorWeak,
),
),
],
),
),
2022-09-06 18:28:12 +02:00
const SizedBox(height: 8),
Text(
2021-05-16 09:16:35 +02:00
pull.title!,
2022-09-06 18:28:12 +02:00
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.w600,
),
),
2022-09-06 18:28:12 +02:00
const SizedBox(height: 8),
StateLabel(
pull.state == 'open'
? StateLabelStatus.pullOpened
: StateLabelStatus.pullClosed,
small: true),
2022-09-06 18:28:12 +02:00
const SizedBox(height: 16),
CommonStyle.border,
CommonStyle.border,
2021-05-16 09:16:35 +02:00
LinkWidget(
url: '/gitee/$owner/$name/pulls/$number/files',
child: Container(
2022-09-17 14:35:45 +02:00
padding:
const EdgeInsets.symmetric(vertical: 8),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
'${files.length} files changed',
style: TextStyle(
2022-09-24 20:46:37 +02:00
color: AntTheme.of(context)
.colorTextSecondary,
fontSize: 17,
),
),
Row(
children: <Widget>[
Text(
'+$additions',
2022-10-06 09:55:35 +02:00
style: TextStyle(
color: AntTheme.of(context)
.colorSuccess,
fontSize: 15,
),
),
2022-09-06 18:28:12 +02:00
const SizedBox(width: 2),
Text(
'-$deletions',
2022-10-06 09:55:35 +02:00
style: TextStyle(
color: AntTheme.of(context)
.colorDanger,
fontSize: 15,
),
),
Icon(
2021-02-14 15:17:22 +01:00
Ionicons.chevron_forward,
2022-09-24 20:46:37 +02:00
color:
AntTheme.of(context).colorBorder,
),
],
)
],
),
),
),
CommonStyle.border,
2022-10-06 09:55:35 +02:00
Column(
// title: Text(
// 'Commits',
// style: TextStyle(
// color: AntTheme.of(context).colorPrimary,
// fontSize: 18,
// fontWeight: FontWeight.w600,
// ),
// ),
children: [
for (var commit in commits) ...[
LinkWidget(
url:
'/gitee/$owner/$name/commits/${commit.sha}',
child: Container(
padding: const EdgeInsets.symmetric(
vertical: 8),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
commit.sha!.substring(0, 7),
style: TextStyle(
color: AntTheme.of(context)
.colorPrimary,
fontSize: 17,
fontFamily: CommonStyle.monospace,
2022-09-17 14:35:45 +02:00
),
2022-10-06 09:55:35 +02:00
),
],
2022-09-17 14:35:45 +02:00
),
2022-10-06 09:55:35 +02:00
),
)
]
],
2022-09-17 14:35:45 +02:00
),
],
),
),
),
2022-09-17 14:35:45 +02:00
CommonStyle.border,
],
)),
Column(
children: [
for (var comment in comments) ...[
Padding(
padding: const EdgeInsets.only(left: 10),
child: CommentItem(
avatar: Avatar(
url: comment.user!.avatarUrl,
linkUrl: '/gitee/${comment.user!.login}',
),
createdAt: DateTime.parse(comment.createdAt!),
body: comment.body,
login: comment.user!.login,
prefix: 'gitee',
commentActionItemList:
_buildCommentActionItem(context, comment),
)),
CommonStyle.border,
2022-09-17 14:35:45 +02:00
const SizedBox(height: 16),
],
2022-09-17 14:35:45 +02:00
],
),
],
);
},
);
}
}