2019-02-04 11:32:39 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2019-02-09 06:36:15 +01:00
|
|
|
import '../scaffolds/list.dart';
|
|
|
|
import '../providers/settings.dart';
|
|
|
|
import '../utils/utils.dart';
|
|
|
|
import '../widgets/repo_item.dart';
|
2019-02-04 11:32:39 +01:00
|
|
|
|
|
|
|
/// Repos of user
|
|
|
|
class ReposScreen extends StatefulWidget {
|
2019-02-09 06:36:15 +01:00
|
|
|
final String login;
|
2019-02-09 06:42:18 +01:00
|
|
|
final bool star;
|
2019-02-09 06:36:15 +01:00
|
|
|
|
2019-02-09 06:42:18 +01:00
|
|
|
ReposScreen({this.login, this.star = false});
|
2019-02-09 06:36:15 +01:00
|
|
|
|
2019-02-04 11:32:39 +01:00
|
|
|
@override
|
|
|
|
_ReposScreenState createState() => _ReposScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ReposScreenState extends State<ReposScreen> {
|
2019-02-09 06:36:15 +01:00
|
|
|
get login => widget.login;
|
|
|
|
|
|
|
|
Future<ListPayload> _queryRepos([String cursor]) async {
|
|
|
|
var cursorChunk = cursor == null ? '' : ', after: "$cursor"';
|
2019-02-09 06:42:18 +01:00
|
|
|
var resouce = widget.star ? 'starredRepositories' : 'repositories';
|
|
|
|
var fieldOrderBy = widget.star ? 'STARRED_AT' : 'UPDATED_AT';
|
|
|
|
|
2019-02-09 06:36:15 +01:00
|
|
|
var data = await SettingsProvider.of(context).query('''
|
|
|
|
{
|
|
|
|
user(login: "$login") {
|
2019-02-09 06:42:18 +01:00
|
|
|
$resouce(first: $pageSize$cursorChunk, orderBy: {field: $fieldOrderBy, direction: DESC}) {
|
2019-02-09 06:36:15 +01:00
|
|
|
pageInfo {
|
|
|
|
hasNextPage
|
|
|
|
endCursor
|
|
|
|
}
|
|
|
|
nodes {
|
|
|
|
$repoChunk
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
''');
|
2019-02-09 06:42:18 +01:00
|
|
|
var repo = data["user"][resouce];
|
2019-02-09 06:36:15 +01:00
|
|
|
|
|
|
|
return ListPayload(
|
|
|
|
cursor: repo["pageInfo"]["endCursor"],
|
|
|
|
items: repo["nodes"],
|
2019-02-09 07:20:21 +01:00
|
|
|
hasMore: repo['pageInfo']['hasNextPage'],
|
2019-02-09 06:36:15 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-02-04 11:32:39 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2019-02-09 07:06:18 +01:00
|
|
|
var title = widget.star ? 'stars' : 'repositories';
|
2019-02-09 06:36:15 +01:00
|
|
|
return ListScaffold(
|
2019-02-09 07:06:18 +01:00
|
|
|
title: Text('$login\'s $title'),
|
2019-02-09 06:36:15 +01:00
|
|
|
onRefresh: () => _queryRepos(),
|
|
|
|
onLoadMore: (cursor) => _queryRepos(cursor),
|
|
|
|
itemBuilder: (payload) => RepoItem(payload),
|
|
|
|
);
|
2019-02-04 11:32:39 +01:00
|
|
|
}
|
|
|
|
}
|