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';
|
2019-02-09 07:06:18 +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 07:06:18 +01:00
|
|
|
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-02-09 07:06:18 +01:00
|
|
|
|
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-02-09 07:06:18 +01:00
|
|
|
|
2019-09-13 10:55:27 +02:00
|
|
|
Future<ListPayload> _queryUsers(BuildContext context, [String cursor]) async {
|
2019-02-09 07:06:18 +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 07:06:18 +01:00
|
|
|
{
|
2019-09-13 10:55:27 +02:00
|
|
|
$scope($params) {
|
2019-02-09 07:06:18 +01:00
|
|
|
$resource(first: $pageSize$cursorChunk) {
|
|
|
|
pageInfo {
|
|
|
|
hasNextPage
|
|
|
|
endCursor
|
|
|
|
}
|
|
|
|
nodes {
|
2019-09-03 15:39:00 +02:00
|
|
|
name
|
2019-02-09 07:06:18 +01:00
|
|
|
login
|
|
|
|
avatarUrl
|
2019-09-14 11:19:33 +02:00
|
|
|
bio
|
2019-02-09 07:06:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
''');
|
2019-03-10 16:34:34 +01:00
|
|
|
var repo = data[scope][resource];
|
2019-02-09 07:06:18 +01:00
|
|
|
|
|
|
|
return ListPayload(
|
|
|
|
cursor: repo["pageInfo"]["endCursor"],
|
2019-02-09 07:20:21 +01:00
|
|
|
hasMore: repo['pageInfo']['hasNextPage'],
|
2019-02-09 07:06:18 +01:00
|
|
|
items: repo["nodes"],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-02-04 14:38:29 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2019-02-09 07:06:18 +01:00
|
|
|
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-09 07:06:18 +01:00
|
|
|
);
|
2019-02-04 14:38:29 +01:00
|
|
|
}
|
|
|
|
}
|