1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-17 18:59:23 +01:00
git-touch-android-ios-app/lib/screens/users.dart

85 lines
2.3 KiB
Dart
Raw Normal View History

2019-02-04 14:38:29 +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-09-14 11:19:33 +02:00
import 'package:git_touch/widgets/user_item.dart';
import '../scaffolds/list.dart';
2019-09-08 14:07:35 +02:00
import 'package:git_touch/models/settings.dart';
import 'package:provider/provider.dart';
import '../utils/utils.dart';
2019-02-04 14:38:29 +01:00
2019-09-13 10:55:27 +02:00
class UsersScreen extends StatelessWidget {
2019-09-23 15:25:18 +02:00
final String scope;
final String params;
final String resource;
2019-09-23 15:47:58 +02:00
final String title;
2019-09-23 15:25:18 +02:00
UsersScreen.followers(String login)
: scope = 'user',
params = 'login: "$login"',
2019-09-23 15:47:58 +02:00
resource = 'followers',
title = 'Followers';
2019-09-23 15:25:18 +02:00
UsersScreen.following(String login)
: scope = 'user',
params = 'login: "$login"',
2019-09-23 15:47:58 +02:00
resource = 'following',
title = 'Following';
2019-09-23 15:25:18 +02:00
UsersScreen.stars(String owner, String name)
: scope = 'repository',
params = 'owner: "$owner", name: "$name"',
2019-09-23 15:47:58 +02:00
resource = 'stargazers',
title = 'Stargazers';
2019-09-23 15:25:18 +02:00
UsersScreen.watchers(String owner, String name)
: scope = 'repository',
params = 'owner: "$owner", name: "$name"',
2019-09-23 15:47:58 +02:00
resource = 'watchers',
title = 'Watchers';
2019-09-23 15:25:18 +02:00
UsersScreen.members(String login)
: scope = 'organization',
params = 'login: "$login"',
2019-09-23 15:47:58 +02:00
resource = 'membersWithRole',
title = 'Members';
2019-09-13 10:55:27 +02:00
Future<ListPayload> _queryUsers(BuildContext context, [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-09-13 10:55:27 +02:00
$scope($params) {
$resource(first: $pageSize$cursorChunk) {
pageInfo {
hasNextPage
endCursor
}
nodes {
name
login
avatarUrl
2019-09-14 11:19:33 +02:00
bio
}
}
}
}
''');
2019-03-10 16:34:34 +01:00
var repo = data[scope][resource];
return ListPayload(
cursor: repo["pageInfo"]["endCursor"],
2019-02-09 07:20:21 +01:00
hasMore: repo['pageInfo']['hasNextPage'],
items: repo["nodes"],
);
}
2019-02-04 14:38:29 +01:00
@override
Widget build(BuildContext context) {
return ListScaffold(
2019-09-23 15:47:58 +02:00
title: AppBarTitle(title),
2019-09-13 10:55:27 +02:00
onRefresh: () => _queryUsers(context),
onLoadMore: (cursor) => _queryUsers(context, cursor),
2019-09-14 20:05:34 +02:00
itemBuilder: (payload) => UserItem(
payload['login'],
name: payload['name'],
avatarUrl: payload['avatarUrl'],
bio: payload['bio'],
),
);
2019-02-04 14:38:29 +01:00
}
}