2019-02-04 14:38:29 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2019-09-08 14:07:35 +02:00
|
|
|
import 'package:git_touch/models/settings.dart';
|
2019-09-11 13:59:47 +02:00
|
|
|
import 'package:git_touch/widgets/app_bar_title.dart';
|
2019-09-13 11:45:09 +02:00
|
|
|
import 'package:git_touch/widgets/avatar.dart';
|
|
|
|
import 'package:primer/primer.dart';
|
2019-09-08 14:07:35 +02:00
|
|
|
import 'package:provider/provider.dart';
|
2019-09-13 11:45:09 +02:00
|
|
|
import 'package:timeago/timeago.dart' as timeago;
|
2019-02-10 05:42:21 +01:00
|
|
|
import '../scaffolds/list.dart';
|
|
|
|
import '../utils/utils.dart';
|
|
|
|
import '../widgets/link.dart';
|
|
|
|
import '../screens/issue.dart';
|
2019-02-04 14:38:29 +01:00
|
|
|
|
2019-09-13 11:45:09 +02:00
|
|
|
class IssuesScreen extends StatelessWidget {
|
2019-02-10 05:42:21 +01:00
|
|
|
final String owner;
|
|
|
|
final String name;
|
|
|
|
final bool isPullRequest;
|
|
|
|
|
|
|
|
IssuesScreen({
|
|
|
|
@required this.owner,
|
|
|
|
@required this.name,
|
|
|
|
this.isPullRequest = false,
|
|
|
|
});
|
|
|
|
|
2019-09-13 11:45:09 +02:00
|
|
|
Future<ListPayload> _query(BuildContext context, [String cursor]) async {
|
2019-02-10 05:42:21 +01:00
|
|
|
var cursorChunk = cursor == null ? '' : ', after: "$cursor"';
|
|
|
|
var resource = isPullRequest ? 'pullRequests' : 'issues';
|
|
|
|
|
2019-09-08 14:07:35 +02:00
|
|
|
var data = await Provider.of<SettingsModel>(context).query('''
|
2019-02-10 05:42:21 +01:00
|
|
|
{
|
|
|
|
repository(owner: "$owner", name: "$name") {
|
2019-09-13 11:45:09 +02:00
|
|
|
$resource(states: OPEN, orderBy: {field: CREATED_AT, direction: DESC}, first: $pageSize$cursorChunk) {
|
2019-02-10 05:42:21 +01:00
|
|
|
pageInfo {
|
|
|
|
hasNextPage
|
|
|
|
endCursor
|
|
|
|
}
|
|
|
|
nodes {
|
|
|
|
number
|
|
|
|
title
|
|
|
|
updatedAt
|
2019-09-13 11:45:09 +02:00
|
|
|
author {
|
|
|
|
login
|
|
|
|
avatarUrl
|
|
|
|
}
|
|
|
|
labels(first: 10) {
|
|
|
|
nodes {
|
|
|
|
name
|
|
|
|
color
|
|
|
|
}
|
|
|
|
}
|
|
|
|
comments {
|
|
|
|
totalCount
|
|
|
|
}
|
2019-02-10 05:42:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
''');
|
|
|
|
|
|
|
|
var repo = data["repository"][resource];
|
|
|
|
|
|
|
|
return ListPayload(
|
|
|
|
cursor: repo["pageInfo"]["endCursor"],
|
|
|
|
hasMore: repo['pageInfo']['hasNextPage'],
|
|
|
|
items: repo["nodes"],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
IconData _buildIconData() {
|
2019-09-13 11:45:09 +02:00
|
|
|
return isPullRequest ? Octicons.git_pull_request : Octicons.issue_opened;
|
2019-02-10 05:42:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildItem(payload) {
|
|
|
|
return Link(
|
|
|
|
screenBuilder: (context) {
|
2019-02-19 08:25:15 +01:00
|
|
|
return IssueScreen(
|
|
|
|
number: payload['number'],
|
|
|
|
owner: owner,
|
|
|
|
name: name,
|
|
|
|
isPullRequest: isPullRequest,
|
|
|
|
);
|
2019-02-10 05:42:21 +01:00
|
|
|
},
|
|
|
|
child: Container(
|
2019-09-13 11:45:09 +02:00
|
|
|
padding: EdgeInsets.all(12),
|
2019-02-10 05:42:21 +01:00
|
|
|
// color: payload.unread ? Colors.white : Colors.black12,
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
2019-09-14 09:58:53 +02:00
|
|
|
Icon(_buildIconData(), color: Palette.green, size: 16),
|
|
|
|
SizedBox(width: 6),
|
2019-02-10 05:42:21 +01:00
|
|
|
Expanded(
|
|
|
|
child: Container(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2019-09-14 09:58:53 +02:00
|
|
|
children: join(SizedBox(height: 8), [
|
2019-02-10 05:42:21 +01:00
|
|
|
// Text(
|
|
|
|
// owner +
|
|
|
|
// '/' +
|
|
|
|
// name +
|
|
|
|
// ' #' +
|
|
|
|
// payload['number'].toString(),
|
|
|
|
// style: TextStyle(fontSize: 13, color: Colors.black54),
|
|
|
|
// ),
|
|
|
|
// Padding(padding: EdgeInsets.only(top: 4)),
|
|
|
|
Text(
|
2019-09-14 09:58:53 +02:00
|
|
|
payload['title'] + ' (#${payload['number']})',
|
2019-09-13 11:45:09 +02:00
|
|
|
style: TextStyle(
|
2019-09-14 09:58:53 +02:00
|
|
|
fontSize: 16,
|
|
|
|
color: PrimerColors.gray900,
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
),
|
2019-02-10 05:42:21 +01:00
|
|
|
),
|
2019-09-14 09:58:53 +02:00
|
|
|
if ((payload['labels']['nodes'] as List).isNotEmpty)
|
|
|
|
Wrap(
|
|
|
|
spacing: 2,
|
|
|
|
runSpacing: 2,
|
|
|
|
children: (payload['labels']['nodes'] as List)
|
|
|
|
.map((label) {
|
|
|
|
final color = convertColor(label['color']);
|
|
|
|
return Container(
|
|
|
|
padding: EdgeInsets.symmetric(
|
|
|
|
vertical: 1, horizontal: 3),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: color,
|
|
|
|
borderRadius:
|
|
|
|
BorderRadius.all(Radius.circular(2)),
|
2019-09-13 11:45:09 +02:00
|
|
|
),
|
2019-09-14 09:58:53 +02:00
|
|
|
child: Text(
|
|
|
|
label['name'],
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 12,
|
|
|
|
color: getFontColorByBrightness(color),
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}).toList(),
|
|
|
|
),
|
2019-09-13 11:45:09 +02:00
|
|
|
DefaultTextStyle(
|
2019-02-10 05:42:21 +01:00
|
|
|
style: TextStyle(
|
2019-09-13 11:45:09 +02:00
|
|
|
fontSize: 13, color: PrimerColors.gray700),
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
2019-09-14 09:58:53 +02:00
|
|
|
Avatar(
|
|
|
|
login: payload['author']['login'],
|
|
|
|
url: payload['author']['avatarUrl'],
|
|
|
|
size: 8,
|
|
|
|
),
|
2019-09-13 11:45:09 +02:00
|
|
|
SizedBox(width: 4),
|
2019-09-14 09:58:53 +02:00
|
|
|
Text(
|
|
|
|
payload['author']['login'],
|
|
|
|
style: TextStyle(fontWeight: FontWeight.w500),
|
|
|
|
),
|
|
|
|
Text(' opened ' +
|
|
|
|
timeago.format(
|
|
|
|
DateTime.parse(payload['updatedAt']))),
|
2019-09-13 11:45:09 +02:00
|
|
|
if (payload['comments']['totalCount'] > 0) ...[
|
|
|
|
Expanded(child: SizedBox()),
|
|
|
|
Icon(Octicons.comment,
|
|
|
|
size: 13, color: PrimerColors.gray700),
|
|
|
|
SizedBox(width: 4),
|
2019-09-13 17:34:19 +02:00
|
|
|
Text(numberFormat
|
|
|
|
.format(payload['comments']['totalCount']))
|
2019-09-13 11:45:09 +02:00
|
|
|
],
|
|
|
|
],
|
2019-02-10 05:42:21 +01:00
|
|
|
),
|
|
|
|
)
|
2019-09-13 11:45:09 +02:00
|
|
|
]),
|
2019-02-10 05:42:21 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
// Column(
|
|
|
|
// children: <Widget>[
|
|
|
|
// Icon(Octicons.check, color: Colors.black45),
|
|
|
|
// Icon(Octicons.unmute, color: Colors.black45)
|
|
|
|
// ],
|
|
|
|
// ),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-02-04 14:38:29 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2019-02-10 05:42:21 +01:00
|
|
|
return ListScaffold(
|
2019-09-14 09:58:53 +02:00
|
|
|
title: AppBarTitle(
|
|
|
|
(isPullRequest ? 'Pull requests' : 'Issues') + ' of $owner/$name'),
|
2019-09-13 11:45:09 +02:00
|
|
|
onRefresh: () => _query(context),
|
2019-02-10 05:42:21 +01:00
|
|
|
onLoadMore: (cursor) => _query(cursor),
|
|
|
|
itemBuilder: _buildItem,
|
|
|
|
);
|
2019-02-04 14:38:29 +01:00
|
|
|
}
|
|
|
|
}
|