1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-13 17:08:49 +01:00

feat: add repo's issues and pull requests screen

This commit is contained in:
Rongjian Zhang 2019-02-10 12:42:21 +08:00
parent 5298c8736f
commit 55356315c4
5 changed files with 153 additions and 212 deletions

View File

@ -1,193 +0,0 @@
// import 'package:flutter/material.dart';
// import 'package:flutter/cupertino.dart';
// import '../widgets/list_scaffold.dart';
// import '../utils/utils.dart';
// import '../screens/issue.dart';
// import '../screens/pull_request.dart';
// import '../widgets/link.dart';
// class NotificationPayload {
// String type;
// String owner;
// String name;
// int number;
// String title;
// String updateAt;
// bool unread;
// NotificationPayload.fromJson(input) {
// type = input['subject']['type'];
// name = input['repository']['name'];
// owner = input['repository']['owner']['login'];
// String url = input['subject']['url'];
// String numberStr = url.split('/').lastWhere((_) => true);
// number = int.parse(numberStr);
// title = input['subject']['title'];
// updateAt = TimeAgo.formatFromString(input['updated_at']);
// unread = input['unread'];
// }
// }
// class NotificationItem extends StatelessWidget {
// const NotificationItem({
// Key key,
// @required this.payload,
// }) : super(key: key);
// final NotificationPayload payload;
// Widget _buildRoute() {
// switch (payload.type) {
// case 'Issue':
// return IssueScreen(payload.number, payload.owner, payload.name);
// case 'PullRequest':
// return PullRequestScreen(payload.number, payload.owner, payload.name);
// default:
// // throw new Exception('Unhandled notification type: $type');
// return Text('test');
// }
// }
// IconData _buildIconData() {
// switch (payload.type) {
// case 'Issue':
// return Octicons.issue_opened;
// // color: Color.fromRGBO(0x28, 0xa7, 0x45, 1),
// case 'PullRequest':
// return Octicons.git_pull_request;
// // color: Color.fromRGBO(0x6f, 0x42, 0xc1, 1),
// default:
// return Octicons.person;
// }
// }
// @override
// Widget build(BuildContext context) {
// return Link(
// onTap: () {
// Navigator.of(context).push(
// CupertinoPageRoute(builder: (context) => _buildRoute()),
// );
// },
// child: Container(
// padding: EdgeInsets.all(8),
// // color: payload.unread ? Colors.white : Colors.black12,
// child: Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: <Widget>[
// Row(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: <Widget>[
// Container(
// padding: EdgeInsets.only(right: 8, top: 20),
// child: Icon(_buildIconData(), color: Colors.black45),
// ),
// Expanded(
// child: Container(
// child: Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: <Widget>[
// Text(
// payload.owner +
// '/' +
// payload.name +
// ' #' +
// payload.number.toString(),
// style: TextStyle(fontSize: 13, color: Colors.black54),
// ),
// Padding(padding: EdgeInsets.only(top: 4)),
// Text(
// payload.title,
// style: TextStyle(fontSize: 15),
// maxLines: 3,
// overflow: TextOverflow.ellipsis,
// ),
// Padding(padding: EdgeInsets.only(top: 6)),
// Text(
// payload.updateAt,
// style: TextStyle(
// fontSize: 12,
// // fontWeight: FontWeight.w300,
// color: Colors.black54,
// ),
// )
// ],
// ),
// ),
// ),
// Column(
// children: <Widget>[
// Icon(Octicons.check, color: Colors.black45),
// Icon(Octicons.unmute, color: Colors.black45)
// ],
// ),
// ],
// ),
// ],
// ),
// ),
// );
// }
// }
// Future<List<NotificationPayload>> fetchNotifications(int page) async {
// List items =
// await getWithCredentials('/notifications?page=$page&per_page=20');
// return items.map((item) => NotificationPayload.fromJson(item)).toList();
// }
// /// [@deprecated]
// class InboxScreen extends StatefulWidget {
// @override
// _InboxScreenState createState() => _InboxScreenState();
// }
// class _InboxScreenState extends State<InboxScreen> {
// // int active = 0;
// int page = 0;
// var payload;
// List<NotificationPayload> _items = [];
// final titleMap = {
// 0: 'Unread',
// 1: 'Participating',
// 2: 'All',
// };
// Future<void> _refresh() async {
// page = 1;
// var items = await fetchNotifications(page);
// setState(() {
// _items = items;
// });
// }
// @override
// Widget build(BuildContext context) {
// return ListScaffold(
// title: Text('Inbox'),
// trailingIconData: Octicons.check,
// trailingOnTap: () async {
// bool answer = await showConfim(context, 'Mark all as read?');
// if (answer == true) {
// await putWithCredentials('/notifications');
// _refresh();
// }
// },
// onRefresh: _refresh,
// onLoadMore: () async {
// page = page + 1;
// var items = await fetchNotifications(page);
// setState(() {
// _items.addAll(items);
// });
// },
// itemCount: _items.length,
// itemBuilder: (context, index) {
// return NotificationItem(payload: _items[index]);
// },
// );
// }
// }

View File

@ -1,13 +1,152 @@
import 'package:flutter/material.dart';
import '../scaffolds/list.dart';
import '../providers/settings.dart';
import '../utils/utils.dart';
import '../widgets/link.dart';
import '../screens/pull_request.dart';
import '../screens/issue.dart';
class IssuesScreen extends StatefulWidget {
final String owner;
final String name;
final bool isPullRequest;
IssuesScreen({
@required this.owner,
@required this.name,
this.isPullRequest = false,
});
@override
_IssuesScreenState createState() => _IssuesScreenState();
}
class _IssuesScreenState extends State<IssuesScreen> {
@override
Widget build(BuildContext context) {
return Container();
get owner => widget.owner;
get name => widget.name;
get isPullRequest => widget.isPullRequest;
Future<ListPayload> _query([String cursor]) async {
var cursorChunk = cursor == null ? '' : ', after: "$cursor"';
var resource = isPullRequest ? 'pullRequests' : 'issues';
var data = await SettingsProvider.of(context).query('''
{
repository(owner: "$owner", name: "$name") {
$resource(states: OPEN, first: $pageSize$cursorChunk) {
pageInfo {
hasNextPage
endCursor
}
nodes {
number
title
updatedAt
}
}
}
}
''');
var repo = data["repository"][resource];
return ListPayload(
cursor: repo["pageInfo"]["endCursor"],
hasMore: repo['pageInfo']['hasNextPage'],
items: repo["nodes"],
);
}
IconData _buildIconData() {
return widget.isPullRequest
? Octicons.git_pull_request
: Octicons.issue_opened;
}
Widget _buildItem(payload) {
return Link(
screenBuilder: (context) {
if (widget.isPullRequest) {
return PullRequestScreen(
number: payload['number'],
owner: owner,
name: name,
);
} else {
return IssueScreen(
number: payload['number'],
owner: owner,
name: name,
);
}
},
child: Container(
padding: EdgeInsets.all(8),
// color: payload.unread ? Colors.white : Colors.black12,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
padding: EdgeInsets.only(right: 8, top: 4),
child: Icon(_buildIconData(), color: Palette.green),
),
Expanded(
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
// Text(
// owner +
// '/' +
// name +
// ' #' +
// payload['number'].toString(),
// style: TextStyle(fontSize: 13, color: Colors.black54),
// ),
// Padding(padding: EdgeInsets.only(top: 4)),
Text(
payload['title'],
style: TextStyle(fontSize: 15),
maxLines: 3,
overflow: TextOverflow.ellipsis,
),
Padding(padding: EdgeInsets.only(top: 6)),
Text(
payload['updatedAt'],
style: TextStyle(
fontSize: 12,
// fontWeight: FontWeight.w300,
color: Colors.black54,
),
)
],
),
),
),
// Column(
// children: <Widget>[
// Icon(Octicons.check, color: Colors.black45),
// Icon(Octicons.unmute, color: Colors.black45)
// ],
// ),
],
),
],
),
),
);
}
@override
Widget build(BuildContext context) {
return ListScaffold(
title: Text('Issues of $owner/$name'),
onRefresh: () => _query(),
onLoadMore: (cursor) => _query(cursor),
itemBuilder: _buildItem,
);
}
}

View File

@ -157,6 +157,8 @@ $key: pullRequest(number: ${item.number}) {
}
Future<void> _onSwitchTab([int index]) async {
if (loading) return;
setState(() {
error = '';
if (index != null) {

View File

@ -1,13 +0,0 @@
import 'package:flutter/material.dart';
class PullRequestsScreen extends StatefulWidget {
@override
_PullRequestsScreenState createState() => _PullRequestsScreenState();
}
class _PullRequestsScreenState extends State<PullRequestsScreen> {
@override
Widget build(BuildContext context) {
return Container();
}
}

View File

@ -7,7 +7,6 @@ import '../scaffolds/refresh.dart';
import '../widgets/repo_item.dart';
import '../widgets/entry_item.dart';
import '../screens/issues.dart';
import '../screens/pull_requests.dart';
class RepoScreen extends StatefulWidget {
final String owner;
@ -93,12 +92,19 @@ class _RepoScreenState extends State<RepoScreen> {
EntryItem(
count: payload['issues']['totalCount'],
text: 'Issues',
screenBuilder: (context) => IssuesScreen(),
screenBuilder: (context) => IssuesScreen(
owner: widget.owner,
name: widget.name,
),
),
EntryItem(
count: payload['pullRequests']['totalCount'],
text: 'Pull Requests',
screenBuilder: (context) => PullRequestsScreen(),
screenBuilder: (context) => IssuesScreen(
owner: widget.owner,
name: widget.name,
isPullRequest: true,
),
),
],
),