2019-08-30 10:26:56 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2019-09-27 14:52:38 +02:00
|
|
|
import 'package:git_touch/models/auth.dart';
|
2019-09-25 11:06:36 +02:00
|
|
|
import 'package:git_touch/scaffolds/list_stateful.dart';
|
2019-09-03 08:59:08 +02:00
|
|
|
import 'package:git_touch/utils/utils.dart';
|
2019-09-11 13:59:47 +02:00
|
|
|
import 'package:git_touch/widgets/app_bar_title.dart';
|
2019-08-30 10:26:56 +02:00
|
|
|
import 'package:git_touch/widgets/link.dart';
|
2019-09-08 14:07:35 +02:00
|
|
|
import 'package:provider/provider.dart';
|
2019-08-30 10:26:56 +02:00
|
|
|
import 'package:timeago/timeago.dart' as timeago;
|
|
|
|
import 'package:git_touch/widgets/avatar.dart';
|
|
|
|
import 'package:primer/primer.dart';
|
|
|
|
|
|
|
|
class CommitsScreen extends StatelessWidget {
|
|
|
|
final String owner;
|
|
|
|
final String name;
|
2019-09-23 11:08:51 +02:00
|
|
|
final String branch;
|
2019-08-30 10:26:56 +02:00
|
|
|
|
2019-09-23 11:08:51 +02:00
|
|
|
CommitsScreen(this.owner, this.name, {this.branch});
|
2019-08-30 10:26:56 +02:00
|
|
|
|
|
|
|
Future<ListPayload> _query(BuildContext context, [String cursor]) async {
|
|
|
|
var params = 'first: 30';
|
|
|
|
if (cursor != null) {
|
|
|
|
params += ', after: "$cursor"';
|
|
|
|
}
|
2019-09-23 14:04:53 +02:00
|
|
|
var key = getBranchQueryKey(branch, withParams: true);
|
2019-09-27 14:52:38 +02:00
|
|
|
var data = await Provider.of<AuthModel>(context).query('''
|
2019-08-30 10:26:56 +02:00
|
|
|
{
|
|
|
|
repository(owner: "$owner", name: "$name") {
|
2019-09-23 14:04:53 +02:00
|
|
|
$key {
|
2019-08-30 10:26:56 +02:00
|
|
|
target {
|
|
|
|
... on Commit {
|
|
|
|
history($params) {
|
|
|
|
pageInfo {
|
|
|
|
hasNextPage
|
|
|
|
endCursor
|
|
|
|
}
|
|
|
|
nodes {
|
|
|
|
oid
|
2019-09-03 08:59:08 +02:00
|
|
|
url
|
2019-08-30 10:26:56 +02:00
|
|
|
messageHeadline
|
|
|
|
committedDate
|
|
|
|
author {
|
2019-09-03 08:32:17 +02:00
|
|
|
name
|
2019-08-30 10:26:56 +02:00
|
|
|
email
|
|
|
|
avatarUrl
|
|
|
|
user {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
}
|
2019-09-03 08:59:08 +02:00
|
|
|
status {
|
|
|
|
state
|
|
|
|
}
|
2019-08-30 10:26:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
''');
|
|
|
|
|
2019-09-23 14:04:53 +02:00
|
|
|
var history =
|
|
|
|
data["repository"][getBranchQueryKey(branch)]['target']['history'];
|
2019-08-30 10:26:56 +02:00
|
|
|
|
|
|
|
return ListPayload(
|
|
|
|
cursor: history["pageInfo"]["endCursor"],
|
|
|
|
hasMore: history['pageInfo']['hasNextPage'],
|
|
|
|
items: history["nodes"],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-09-03 08:59:08 +02:00
|
|
|
Widget _buildStatus(String state) {
|
|
|
|
var size = 18.0;
|
|
|
|
switch (state) {
|
|
|
|
case 'SUCCESS':
|
|
|
|
return Icon(Octicons.check, color: PrimerColors.green500, size: size);
|
|
|
|
case 'FAILURE':
|
|
|
|
return Icon(Octicons.x, color: PrimerColors.red600, size: size);
|
|
|
|
default:
|
|
|
|
return Container();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-30 10:26:56 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2019-09-25 11:06:36 +02:00
|
|
|
return ListStatefulScaffold(
|
2019-09-11 13:59:47 +02:00
|
|
|
title: AppBarTitle('Commits'),
|
2019-08-30 10:26:56 +02:00
|
|
|
onRefresh: () => _query(context),
|
|
|
|
onLoadMore: (cursor) => _query(context, cursor),
|
|
|
|
itemBuilder: (payload) {
|
|
|
|
return Link(
|
2019-09-03 08:59:08 +02:00
|
|
|
url: payload['url'],
|
2019-08-30 10:26:56 +02:00
|
|
|
child: Container(
|
2019-10-02 10:09:54 +02:00
|
|
|
padding: CommonStyle.padding,
|
2019-08-30 10:26:56 +02:00
|
|
|
child: Row(
|
2019-09-03 08:59:08 +02:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2019-08-30 10:26:56 +02:00
|
|
|
children: <Widget>[
|
2019-10-02 09:23:33 +02:00
|
|
|
Avatar.medium(url: payload['author']['avatarUrl']),
|
2019-08-30 10:26:56 +02:00
|
|
|
SizedBox(width: 8),
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
Text(payload['messageHeadline'],
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.w500, fontSize: 14)),
|
|
|
|
SizedBox(height: 4),
|
2019-09-03 08:59:08 +02:00
|
|
|
Wrap(
|
2019-08-30 10:26:56 +02:00
|
|
|
children: <Widget>[
|
2019-09-03 08:32:17 +02:00
|
|
|
Text(
|
|
|
|
payload['author']['user'] == null
|
|
|
|
? payload['author']['name']
|
|
|
|
: payload['author']['user']['login'],
|
2019-08-30 10:26:56 +02:00
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.w500, fontSize: 14)),
|
|
|
|
Text(
|
|
|
|
' committed ' +
|
|
|
|
timeago.format(
|
|
|
|
DateTime.parse(payload['committedDate'])),
|
|
|
|
style: TextStyle(
|
|
|
|
color: PrimerColors.gray600, fontSize: 14)),
|
2019-09-12 10:30:35 +02:00
|
|
|
if (payload['status'] != null) ...[
|
|
|
|
SizedBox(width: 4),
|
|
|
|
_buildStatus(payload['status']['state'])
|
|
|
|
],
|
2019-08-30 10:26:56 +02:00
|
|
|
],
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|