2019-02-04 11:32:39 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2019-09-11 13:59:47 +02:00
|
|
|
import 'package:git_touch/widgets/app_bar_title.dart';
|
2019-02-09 06:36:15 +01:00
|
|
|
import '../scaffolds/list.dart';
|
2019-09-08 14:07:35 +02:00
|
|
|
import 'package:git_touch/models/settings.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
2019-02-09 06:36:15 +01:00
|
|
|
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-03-10 16:34:34 +01:00
|
|
|
final bool org;
|
2019-02-09 06:36:15 +01:00
|
|
|
|
2019-03-10 16:34:34 +01:00
|
|
|
ReposScreen({this.login, this.star = false, this.org = 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-03-10 16:34:34 +01:00
|
|
|
String get login => widget.login;
|
|
|
|
String get scope => widget.org ? 'organization' : 'user';
|
|
|
|
String get resource => widget.star ? 'starredRepositories' : 'repositories';
|
|
|
|
String get fieldOrderBy {
|
|
|
|
if (widget.star) {
|
|
|
|
return 'STARRED_AT';
|
|
|
|
}
|
|
|
|
if (widget.org) {
|
|
|
|
return 'PUSHED_AT';
|
|
|
|
}
|
|
|
|
return 'UPDATED_AT';
|
|
|
|
}
|
2019-02-09 06:36:15 +01:00
|
|
|
|
|
|
|
Future<ListPayload> _queryRepos([String cursor]) async {
|
|
|
|
var cursorChunk = cursor == null ? '' : ', after: "$cursor"';
|
2019-09-08 14:07:35 +02:00
|
|
|
var data = await Provider.of<SettingsModel>(context).query('''
|
2019-02-09 06:36:15 +01:00
|
|
|
{
|
2019-03-10 16:34:34 +01:00
|
|
|
$scope(login: "$login") {
|
|
|
|
$resource(first: $pageSize$cursorChunk, orderBy: {field: $fieldOrderBy, direction: DESC}) {
|
2019-02-09 06:36:15 +01:00
|
|
|
pageInfo {
|
|
|
|
hasNextPage
|
|
|
|
endCursor
|
|
|
|
}
|
|
|
|
nodes {
|
|
|
|
$repoChunk
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
''');
|
2019-03-10 16:34:34 +01:00
|
|
|
var repo = data[scope][resource];
|
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 06:36:15 +01:00
|
|
|
return ListScaffold(
|
2019-09-11 13:59:47 +02:00
|
|
|
title: AppBarTitle(widget.star ? 'Stars' : 'Repositories'),
|
2019-02-09 06:36:15 +01:00
|
|
|
onRefresh: () => _queryRepos(),
|
|
|
|
onLoadMore: (cursor) => _queryRepos(cursor),
|
2019-09-09 16:50:22 +02:00
|
|
|
itemBuilder: (payload) => RepoItem(payload),
|
2019-02-09 06:36:15 +01:00
|
|
|
);
|
2019-02-04 11:32:39 +01:00
|
|
|
}
|
|
|
|
}
|