1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-17 02:38:39 +01:00
git-touch-android-ios-app/lib/screens/repos.dart
2019-02-09 14:20:21 +08:00

61 lines
1.5 KiB
Dart

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