1
0
mirror of https://github.com/git-touch/git-touch synced 2025-02-12 09:30:38 +01:00

75 lines
2.3 KiB
Dart
Raw Normal View History

2019-02-04 21:38:29 +08:00
import 'package:flutter/material.dart';
2019-09-27 20:52:38 +08:00
import 'package:git_touch/models/auth.dart';
2019-10-03 12:16:44 +08:00
import 'package:git_touch/models/theme.dart';
2019-09-25 17:06:36 +08:00
import 'package:git_touch/scaffolds/list_stateful.dart';
2019-12-13 13:13:45 +08:00
import 'package:git_touch/utils/utils.dart';
2019-10-03 12:16:44 +08:00
import 'package:git_touch/widgets/action_entry.dart';
2019-09-11 19:59:47 +08:00
import 'package:git_touch/widgets/app_bar_title.dart';
2019-09-25 20:51:23 +08:00
import 'package:git_touch/widgets/issue_item.dart';
2019-09-08 20:07:35 +08:00
import 'package:provider/provider.dart';
2019-12-13 13:13:45 +08:00
final issuesRouter = RouterScreen(
'/:owner/:name/issues',
(context, params) =>
IssuesScreen(params['owner'].first, params['name'].first));
2019-02-04 21:38:29 +08:00
2019-12-14 22:36:02 +08:00
final pullsRouter = RouterScreen(
'/:owner/:name/pulls',
(context, params) => IssuesScreen(
params['owner'].first, params['name'].first,
isPullRequest: true));
2019-09-13 17:45:09 +08:00
class IssuesScreen extends StatelessWidget {
final String owner;
final String name;
final bool isPullRequest;
2019-11-03 00:02:41 +08:00
IssuesScreen(this.owner, this.name, {this.isPullRequest = false});
2019-09-13 17:45:09 +08:00
Future<ListPayload> _query(BuildContext context, [String cursor]) async {
var cursorChunk = cursor == null ? '' : ', after: "$cursor"';
var resource = isPullRequest ? 'pullRequests' : 'issues';
2019-09-27 20:52:38 +08:00
var data = await Provider.of<AuthModel>(context).query('''
{
repository(owner: "$owner", name: "$name") {
2019-09-13 17:45:09 +08:00
$resource(states: OPEN, orderBy: {field: CREATED_AT, direction: DESC}, first: $pageSize$cursorChunk) {
pageInfo {
hasNextPage
endCursor
}
nodes {
2019-09-25 20:51:23 +08:00
$issueGqlChunk
}
}
}
}
''');
var repo = data["repository"][resource];
return ListPayload(
cursor: repo["pageInfo"]["endCursor"],
hasMore: repo['pageInfo']['hasNextPage'],
items: repo["nodes"],
);
}
2019-02-04 21:38:29 +08:00
@override
Widget build(BuildContext context) {
2019-09-25 17:06:36 +08:00
return ListStatefulScaffold(
2019-10-03 11:00:12 +08:00
title: AppBarTitle((isPullRequest ? 'Pull requests' : 'Issues')),
2019-10-03 12:16:44 +08:00
actionBuilder: () => ActionEntry(
iconData: Octicons.plus,
onTap: () {
2019-12-12 22:02:58 +08:00
Provider.of<ThemeModel>(context)
.push(context, '/$owner/$name/issues/new');
2019-10-03 12:16:44 +08:00
}),
2019-09-13 17:45:09 +08:00
onRefresh: () => _query(context),
2019-10-03 11:00:12 +08:00
onLoadMore: (cursor) => _query(context, cursor),
2019-09-25 20:51:23 +08:00
itemBuilder: (payload) =>
IssueItem(payload: payload, isPullRequest: isPullRequest),
);
2019-02-04 21:38:29 +08:00
}
}