git-touch-android-ios-app/lib/screens/gh_issues.dart

63 lines
2.3 KiB
Dart
Raw Normal View History

2021-05-16 09:16:35 +02:00
import 'package:ferry/ferry.dart';
2022-09-17 14:35:45 +02:00
import 'package:flutter/widgets.dart';
2022-09-12 05:46:42 +02:00
import 'package:flutter_gen/gen_l10n/S.dart';
2022-09-06 18:00:51 +02:00
import 'package:git_touch/graphql/__generated__/github.data.gql.dart';
import 'package:git_touch/graphql/__generated__/github.req.gql.dart';
import 'package:git_touch/graphql/__generated__/github.var.gql.dart';
2019-09-27 14:52:38 +02:00
import 'package:git_touch/models/auth.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/widgets/action_entry.dart';
2019-09-11 13:59:47 +02:00
import 'package:git_touch/widgets/app_bar_title.dart';
2022-09-12 05:46:42 +02:00
import 'package:git_touch/widgets/hex_color_tag.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';
2019-12-13 06:13:45 +01:00
2020-02-07 07:17:05 +01:00
class GhIssuesScreen extends StatelessWidget {
2022-09-21 18:28:21 +02:00
const GhIssuesScreen(this.owner, this.name);
final String owner;
final String name;
2019-02-04 14:38:29 +01:00
@override
Widget build(BuildContext context) {
2021-05-16 09:16:35 +02:00
return ListStatefulScaffold<GIssuesData_repository_issues_nodes, String?>(
title: AppBarTitle(AppLocalizations.of(context)!.issues),
2019-10-03 06:16:44 +02:00
actionBuilder: () => ActionEntry(
2020-01-31 09:54:01 +01:00
iconData: Octicons.plus,
url: '/github/$owner/$name/issues/new',
2020-01-31 09:54:01 +01:00
),
fetch: (cursor) async {
2021-01-17 15:08:32 +01:00
final req = GIssuesReq((b) {
b.vars.owner = owner;
b.vars.name = name;
b.vars.cursor = cursor;
});
2021-05-16 09:16:35 +02:00
final OperationResponse<GIssuesData, GIssuesVars?> res =
2021-06-14 08:56:42 +02:00
await context.read<AuthModel>().gqlClient.request(req).first;
2021-05-16 09:16:35 +02:00
final issues = res.data!.repository!.issues;
2020-10-04 16:10:05 +02:00
return ListPayload(
cursor: issues.pageInfo.endCursor,
hasMore: issues.pageInfo.hasNextPage,
2021-05-16 09:16:35 +02:00
items: issues.nodes!.toList(),
2021-01-17 15:08:32 +01:00
);
},
itemBuilder: (p) {
return IssueItem(
author: p.author?.login,
avatarUrl: p.author?.avatarUrl,
commentCount: p.comments.totalCount,
2022-09-06 18:28:12 +02:00
subtitle: '#${p.number}',
2021-01-17 15:08:32 +01:00
title: p.title,
updatedAt: p.updatedAt,
2021-05-16 09:16:35 +02:00
labels: p.labels!.nodes!.isEmpty
2021-01-17 15:08:32 +01:00
? null
: Wrap(spacing: 4, runSpacing: 4, children: [
2021-05-16 09:16:35 +02:00
for (var label in p.labels!.nodes!)
2022-09-30 20:54:09 +02:00
HexColorTag(name: label.name, color: label.color)
2021-01-17 15:08:32 +01:00
]),
url: '/github/$owner/$name/issues/${p.number}',
2020-10-04 16:10:05 +02:00
);
},
);
2019-02-04 14:38:29 +01:00
}
}