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

78 lines
2.2 KiB
Dart
Raw Normal View History

2019-02-04 11:32:39 +01:00
import 'package:flutter/material.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-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';
2019-09-23 12:28:33 +02:00
import 'package:git_touch/widgets/repository_item.dart';
2019-02-04 11:32:39 +01:00
2019-09-23 12:28:33 +02:00
class RepositoriesScreen extends StatelessWidget {
2019-02-09 06:36:15 +01:00
final String login;
final String title;
final String scope;
final String resource;
final String extra0;
final String extra1;
final String extra2;
2019-02-09 06:36:15 +01:00
RepositoriesScreen(this.login)
: title = 'Repositories',
scope = 'user',
resource = 'repositories',
extra0 = 'orderBy: {field: UPDATED_AT, direction: DESC}',
extra1 = '',
extra2 = '';
RepositoriesScreen.stars(this.login)
: title = 'Stars',
scope = 'user',
resource = 'starredRepositories',
extra0 = 'orderBy: {field: STARRED_AT, direction: DESC}',
extra1 = '',
extra2 = '';
RepositoriesScreen.ofOrganization(this.login)
: title = 'Repositories',
scope = 'organization',
resource = 'pinnableItems',
extra0 = 'types: [REPOSITORY]',
extra1 = '... on Repository {',
extra2 = '}';
2019-02-09 06:36:15 +01:00
2019-09-21 19:02:14 +02:00
Future<ListPayload> _queryRepos(BuildContext context, [String cursor]) async {
2019-02-09 06:36:15 +01:00
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, $extra0) {
2019-02-09 06:36:15 +01:00
pageInfo {
hasNextPage
endCursor
}
nodes {
$extra1
$repoChunk
$extra2
2019-02-09 06:36:15 +01:00
}
}
}
}
''');
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-09-25 11:06:36 +02:00
return ListStatefulScaffold(
title: AppBarTitle(title),
2019-09-21 19:02:14 +02:00
onRefresh: () => _queryRepos(context),
onLoadMore: (cursor) => _queryRepos(context, cursor),
2019-09-23 12:28:33 +02:00
itemBuilder: (payload) => RepositoryItem(payload),
2019-02-09 06:36:15 +01:00
);
2019-02-04 11:32:39 +01:00
}
}