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