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

74 lines
2.3 KiB
Dart
Raw Normal View History

2021-05-16 09:16:35 +02:00
import 'package:ferry/ferry.dart';
2019-02-04 11:32:39 +01:00
import 'package:flutter/material.dart';
2021-01-17 15:08:32 +01:00
import 'package:git_touch/graphql/github.data.gql.dart';
import 'package:git_touch/graphql/github.req.gql.dart';
2021-05-16 09:16:35 +02:00
import 'package:git_touch/graphql/github.var.gql.dart';
2019-09-25 11:06:36 +02:00
import 'package:git_touch/scaffolds/list_stateful.dart';
2019-09-11 13:59:47 +02:00
import 'package:git_touch/widgets/app_bar_title.dart';
2019-09-27 14:52:38 +02:00
import 'package:git_touch/models/auth.dart';
2019-09-08 14:07:35 +02:00
import 'package:provider/provider.dart';
2019-09-23 12:28:33 +02:00
import 'package:git_touch/widgets/repository_item.dart';
2020-01-11 12:25:33 +01:00
import 'package:timeago/timeago.dart' as timeago;
2019-02-04 11:32:39 +01:00
2021-01-17 15:08:32 +01:00
class GhRepos extends StatelessWidget {
final String login;
GhRepos(this.login);
2019-02-09 06:36:15 +01:00
2019-02-04 11:32:39 +01:00
@override
Widget build(BuildContext context) {
2021-05-16 09:16:35 +02:00
return ListStatefulScaffold<GReposRepoItem, String?>(
2021-01-17 15:08:32 +01:00
title: AppBarTitle('Repositories'),
fetch: (cursor) async {
2020-10-04 16:10:05 +02:00
final auth = context.read<AuthModel>();
2021-01-17 15:08:32 +01:00
final req = GReposReq((b) {
b.vars.login = login;
b.vars.after = cursor;
});
2021-05-16 09:16:35 +02:00
final OperationResponse<GReposData, GReposVars?> res =
2021-06-14 08:56:42 +02:00
await auth.gqlClient.request(req).first;
2021-05-16 09:16:35 +02:00
final p = res.data!.user!.repositories;
2021-01-17 15:08:32 +01:00
return ListPayload(
cursor: p.pageInfo.endCursor,
hasMore: p.pageInfo.hasNextPage,
2021-06-13 19:23:16 +02:00
items: p.nodes!,
2021-01-17 15:08:32 +01:00
);
2020-10-04 16:10:05 +02:00
},
2021-01-17 15:08:32 +01:00
itemBuilder: (p) {
return RepositoryItem.gql(p,
note: 'Updated ${timeago.format(p.updatedAt)}');
},
);
}
}
class GhStars extends StatelessWidget {
final String login;
GhStars(this.login);
@override
Widget build(BuildContext context) {
2021-05-16 09:16:35 +02:00
return ListStatefulScaffold<GReposRepoItem, String?>(
2021-01-17 15:08:32 +01:00
title: AppBarTitle('Stars'),
fetch: (cursor) async {
final auth = context.read<AuthModel>();
final req = GStarsReq((b) {
b.vars.login = login;
b.vars.after = cursor;
});
2021-05-16 09:16:35 +02:00
final OperationResponse<GStarsData, GStarsVars?> res =
2021-06-14 08:56:42 +02:00
await auth.gqlClient.request(req).first;
2021-05-16 09:16:35 +02:00
final p = res.data!.user!.starredRepositories;
2021-01-17 15:08:32 +01:00
return ListPayload(
cursor: p.pageInfo.endCursor,
hasMore: p.pageInfo.hasNextPage,
2021-06-13 19:23:16 +02:00
items: p.nodes!,
);
},
2021-01-17 15:08:32 +01:00
itemBuilder: (p) {
return RepositoryItem.gql(p,
note: 'Updated ${timeago.format(p.updatedAt)}');
},
);
2019-02-04 11:32:39 +01:00
}
}