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

72 lines
2.4 KiB
Dart
Raw Normal View History

2019-02-04 14:38:29 +01:00
import 'package:flutter/material.dart';
2020-01-28 16:19:05 +01:00
import 'package:git_touch/graphql/gh.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-12-13 06:13:45 +01:00
import 'package:git_touch/utils/utils.dart';
2019-10-03 06:16:44 +02:00
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';
2020-01-28 16:19:05 +01:00
import 'package:git_touch/widgets/label.dart';
2019-09-08 14:07:35 +02:00
import 'package:provider/provider.dart';
2019-12-13 06:13:45 +01:00
final issuesRouter = RouterScreen(
'/:owner/:name/issues',
(context, params) =>
IssuesScreen(params['owner'].first, params['name'].first));
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;
2020-01-28 16:19:05 +01:00
IssuesScreen(this.owner, this.name);
2020-01-28 16:19:05 +01:00
Future<ListPayload<GhIssuesIssue, String>> _query(BuildContext context,
[String cursor]) async {
final res =
await Provider.of<AuthModel>(context).gqlClient.execute(GhIssuesQuery(
variables: GhIssuesArguments(
owner: owner,
name: name,
cursor: cursor,
)));
final issues = res.data.repository.issues;
return ListPayload(
2020-01-28 16:19:05 +01:00
cursor: issues.pageInfo.endCursor,
hasMore: issues.pageInfo.hasNextPage,
items: issues.nodes,
);
}
2019-02-04 14:38:29 +01:00
@override
Widget build(BuildContext context) {
2020-01-28 16:19:05 +01:00
return ListStatefulScaffold<GhIssuesIssue, String>(
title: AppBarTitle('Issues'),
2019-10-03 06:16:44 +02:00
actionBuilder: () => ActionEntry(
iconData: Octicons.plus,
onTap: () {
2019-12-12 15:02:58 +01:00
Provider.of<ThemeModel>(context)
.push(context, '/$owner/$name/issues/new');
2019-10-03 06:16:44 +02:00
}),
2019-09-13 11:45:09 +02:00
onRefresh: () => _query(context),
2019-10-03 05:00:12 +02:00
onLoadMore: (cursor) => _query(context, cursor),
2020-01-28 16:19:05 +01:00
itemBuilder: (p) => IssueItem(
author: p.author?.login,
avatarUrl: p.author?.avatarUrl,
commentCount: p.comments.totalCount,
number: p.number,
title: p.title,
updatedAt: p.updatedAt,
labels: p.labels.nodes.isEmpty
? null
: Wrap(spacing: 4, runSpacing: 4, children: [
for (var label in p.labels.nodes)
MyLabel(name: label.name, cssColor: label.color)
]),
url:
'/${p.repository.owner.login}/${p.repository.name}/issues/${p.number}',
),
);
2019-02-04 14:38:29 +01:00
}
}