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-03 15:39:00 +02:00
|
|
|
import 'package:primer/primer.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';
|
|
|
|
import '../widgets/link.dart';
|
|
|
|
import '../screens/user.dart';
|
2019-03-09 10:03:33 +01:00
|
|
|
import '../widgets/avatar.dart';
|
2019-02-04 14:38:29 +01:00
|
|
|
|
|
|
|
class UsersScreen extends StatefulWidget {
|
2019-02-09 07:06:18 +01:00
|
|
|
final String login;
|
|
|
|
final bool following;
|
2019-03-10 16:34:34 +01:00
|
|
|
final bool org;
|
2019-02-09 07:06:18 +01:00
|
|
|
|
2019-03-10 16:34:34 +01:00
|
|
|
UsersScreen({
|
|
|
|
@required this.login,
|
|
|
|
this.following = false,
|
|
|
|
this.org = false,
|
|
|
|
});
|
2019-02-09 07:06:18 +01:00
|
|
|
|
2019-02-04 14:38:29 +01:00
|
|
|
@override
|
|
|
|
_UsersScreenState createState() => _UsersScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _UsersScreenState extends State<UsersScreen> {
|
2019-03-10 16:34:34 +01:00
|
|
|
String get login => widget.login;
|
|
|
|
String get scope => widget.org ? 'organization' : 'user';
|
|
|
|
String get resource {
|
|
|
|
if (widget.org) {
|
|
|
|
return 'members';
|
|
|
|
}
|
|
|
|
if (widget.following) {
|
|
|
|
return 'following';
|
|
|
|
}
|
|
|
|
return 'followers';
|
|
|
|
}
|
2019-02-09 07:06:18 +01:00
|
|
|
|
|
|
|
Future<ListPayload> _queryUsers([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 07:06:18 +01:00
|
|
|
{
|
2019-03-10 16:34:34 +01:00
|
|
|
$scope(login: "$login") {
|
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-09 16:50:22 +02:00
|
|
|
url
|
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"],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildItem(payload) {
|
|
|
|
return Link(
|
|
|
|
screenBuilder: (_) => UserScreen(payload['login']),
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.all(10),
|
|
|
|
child: Row(
|
2019-09-03 15:39:00 +02:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2019-02-09 07:06:18 +01:00
|
|
|
children: <Widget>[
|
2019-09-09 16:50:22 +02:00
|
|
|
Avatar(url: payload['avatarUrl'], size: 20),
|
2019-09-03 15:39:00 +02:00
|
|
|
SizedBox(width: 10),
|
|
|
|
DefaultTextStyle(
|
2019-09-09 16:50:22 +02:00
|
|
|
style: TextStyle(color: PrimerColors.gray900, fontSize: 13),
|
2019-09-03 15:39:00 +02:00
|
|
|
child: Expanded(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2019-09-09 16:50:22 +02:00
|
|
|
children: join(SizedBox(height: 6), [
|
|
|
|
Text(
|
|
|
|
payload['name'] ?? payload['login'],
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 16,
|
|
|
|
color: PrimerColors.blue500,
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
),
|
2019-09-03 15:39:00 +02:00
|
|
|
),
|
2019-09-09 16:50:22 +02:00
|
|
|
Text(payload['url'], style: TextStyle(fontSize: 14))
|
2019-09-03 15:39:00 +02:00
|
|
|
]),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
2019-02-09 07:06:18 +01:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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-11 13:59:47 +02:00
|
|
|
title: AppBarTitle(resource),
|
2019-02-09 07:06:18 +01:00
|
|
|
onRefresh: () => _queryUsers(),
|
|
|
|
onLoadMore: (cursor) => _queryUsers(cursor),
|
|
|
|
itemBuilder: _buildItem,
|
|
|
|
);
|
2019-02-04 14:38:29 +01:00
|
|
|
}
|
|
|
|
}
|