1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-24 23:01:18 +01:00
git-touch-android-ios-app/lib/screens/issues.dart

66 lines
2.0 KiB
Dart
Raw Normal View History

2019-02-04 14:38:29 +01:00
import 'package:flutter/material.dart';
2019-09-27 14:52:38 +02:00
import 'package:git_touch/models/auth.dart';
2019-10-03 06:16:44 +02:00
import 'package:git_touch/models/theme.dart';
2019-09-25 11:06:36 +02:00
import 'package:git_touch/scaffolds/list_stateful.dart';
2019-10-03 06:16:44 +02:00
import 'package:git_touch/screens/issue_form.dart';
import 'package:git_touch/widgets/action_entry.dart';
2019-09-11 13:59:47 +02:00
import 'package:git_touch/widgets/app_bar_title.dart';
2019-09-25 14:51:23 +02:00
import 'package:git_touch/widgets/issue_item.dart';
2019-09-08 14:07:35 +02:00
import 'package:provider/provider.dart';
import '../utils/utils.dart';
2019-02-04 14:38:29 +01:00
2019-09-13 11:45:09 +02:00
class IssuesScreen extends StatelessWidget {
final String owner;
final String name;
final bool isPullRequest;
2019-11-02 17:02:41 +01:00
IssuesScreen(this.owner, this.name, {this.isPullRequest = false});
2019-09-13 11:45:09 +02:00
Future<ListPayload> _query(BuildContext context, [String cursor]) async {
var cursorChunk = cursor == null ? '' : ', after: "$cursor"';
var resource = isPullRequest ? 'pullRequests' : 'issues';
2019-09-27 14:52:38 +02:00
var data = await Provider.of<AuthModel>(context).query('''
{
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) {
pageInfo {
hasNextPage
endCursor
}
nodes {
2019-09-25 14:51:23 +02:00
$issueGqlChunk
}
}
}
}
''');
var repo = data["repository"][resource];
return ListPayload(
cursor: repo["pageInfo"]["endCursor"],
hasMore: repo['pageInfo']['hasNextPage'],
items: repo["nodes"],
);
}
2019-02-04 14:38:29 +01:00
@override
Widget build(BuildContext context) {
2019-09-25 11:06:36 +02:00
return ListStatefulScaffold(
2019-10-03 05:00:12 +02:00
title: AppBarTitle((isPullRequest ? 'Pull requests' : 'Issues')),
2019-10-03 06:16:44 +02:00
actionBuilder: () => ActionEntry(
iconData: Octicons.plus,
onTap: () {
Provider.of<ThemeModel>(context).pushRoute(
context, (_) => IssueFormScreen(owner, name),
fullscreenDialog: true);
}),
2019-09-13 11:45:09 +02:00
onRefresh: () => _query(context),
2019-10-03 05:00:12 +02:00
onLoadMore: (cursor) => _query(context, cursor),
2019-09-25 14:51:23 +02:00
itemBuilder: (payload) =>
IssueItem(payload: payload, isPullRequest: isPullRequest),
);
2019-02-04 14:38:29 +01:00
}
}