2019-02-04 14:38:29 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2019-12-07 16:10:30 +01:00
|
|
|
import 'package:git_touch/graphql/github_users.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-14 11:19:33 +02:00
|
|
|
import 'package:git_touch/widgets/user_item.dart';
|
2019-09-27 14:52:38 +02:00
|
|
|
import 'package:git_touch/models/auth.dart';
|
2019-09-08 14:07:35 +02:00
|
|
|
import 'package:provider/provider.dart';
|
2019-12-07 16:10:30 +01:00
|
|
|
|
|
|
|
enum UsersScreenType {
|
|
|
|
follower,
|
|
|
|
following,
|
|
|
|
member,
|
|
|
|
watch,
|
|
|
|
star,
|
|
|
|
}
|
2019-02-04 14:38:29 +01:00
|
|
|
|
2019-09-13 10:55:27 +02:00
|
|
|
class UsersScreen extends StatelessWidget {
|
2019-12-07 16:10:30 +01:00
|
|
|
final String login;
|
|
|
|
final String repoName;
|
|
|
|
final UsersScreenType type;
|
2019-02-09 07:06:18 +01:00
|
|
|
|
2019-12-07 16:10:30 +01:00
|
|
|
UsersScreen(this.login, this.type, {this.repoName = ''});
|
2019-02-09 07:06:18 +01:00
|
|
|
|
2019-12-07 16:10:30 +01:00
|
|
|
String get _title {
|
|
|
|
switch (type) {
|
|
|
|
case UsersScreenType.follower:
|
|
|
|
return 'Followers';
|
|
|
|
case UsersScreenType.following:
|
|
|
|
return 'Following';
|
|
|
|
case UsersScreenType.member:
|
|
|
|
return 'Members';
|
|
|
|
case UsersScreenType.watch:
|
|
|
|
return 'Watchers';
|
|
|
|
case UsersScreenType.star:
|
|
|
|
return 'Stargazers';
|
|
|
|
default:
|
|
|
|
return null;
|
2019-02-09 07:06:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-07 16:10:30 +01:00
|
|
|
Future<ListPayload<GithubUsersUser, String>> _queryUsers(BuildContext context,
|
|
|
|
[String cursor]) async {
|
|
|
|
final res = await Provider.of<AuthModel>(context).gqlClient.execute(
|
|
|
|
GithubUsersQuery(
|
|
|
|
variables: GithubUsersArguments(
|
|
|
|
login: login,
|
|
|
|
repoName: repoName,
|
|
|
|
isFollowers: type == UsersScreenType.follower,
|
|
|
|
isFollowing: type == UsersScreenType.following,
|
|
|
|
isStar: type == UsersScreenType.star,
|
|
|
|
isWatch: type == UsersScreenType.watch,
|
|
|
|
isMember: type == UsersScreenType.member,
|
|
|
|
after: cursor)));
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case UsersScreenType.follower:
|
|
|
|
final payload = res.data.user.followers;
|
|
|
|
return ListPayload(
|
|
|
|
cursor: payload.pageInfo.endCursor,
|
|
|
|
hasMore: payload.pageInfo.hasNextPage,
|
|
|
|
items: payload.nodes,
|
|
|
|
);
|
|
|
|
case UsersScreenType.following:
|
|
|
|
final payload = res.data.user.following;
|
|
|
|
return ListPayload(
|
|
|
|
cursor: payload.pageInfo.endCursor,
|
|
|
|
hasMore: payload.pageInfo.hasNextPage,
|
|
|
|
items: payload.nodes,
|
|
|
|
);
|
|
|
|
case UsersScreenType.member:
|
|
|
|
final payload = res.data.organization.membersWithRole;
|
|
|
|
return ListPayload(
|
|
|
|
cursor: payload.pageInfo.endCursor,
|
|
|
|
hasMore: payload.pageInfo.hasNextPage,
|
|
|
|
items: payload.nodes,
|
|
|
|
);
|
|
|
|
case UsersScreenType.watch:
|
|
|
|
final payload = res.data.repository.watchers;
|
|
|
|
return ListPayload(
|
|
|
|
cursor: payload.pageInfo.endCursor,
|
|
|
|
hasMore: payload.pageInfo.hasNextPage,
|
|
|
|
items: payload.nodes,
|
|
|
|
);
|
|
|
|
case UsersScreenType.star:
|
|
|
|
final payload = res.data.repository.stargazers;
|
|
|
|
return ListPayload(
|
|
|
|
cursor: payload.pageInfo.endCursor,
|
|
|
|
hasMore: payload.pageInfo.hasNextPage,
|
|
|
|
items: payload.nodes,
|
|
|
|
);
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
2019-02-09 07:06:18 +01:00
|
|
|
}
|
|
|
|
|
2019-02-04 14:38:29 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2019-12-07 16:10:30 +01:00
|
|
|
return ListStatefulScaffold<GithubUsersUser, String>(
|
|
|
|
title: AppBarTitle(_title),
|
2019-09-13 10:55:27 +02:00
|
|
|
onRefresh: () => _queryUsers(context),
|
|
|
|
onLoadMore: (cursor) => _queryUsers(context, cursor),
|
2019-12-07 16:10:30 +01:00
|
|
|
itemBuilder: (payload) {
|
|
|
|
return UserItem(
|
|
|
|
login: payload.login,
|
|
|
|
name: payload.name,
|
|
|
|
avatarUrl: payload.avatarUrl,
|
|
|
|
bio: payload.bio,
|
|
|
|
inUserScreen: true,
|
|
|
|
);
|
|
|
|
},
|
2019-02-09 07:06:18 +01:00
|
|
|
);
|
2019-02-04 14:38:29 +01:00
|
|
|
}
|
|
|
|
}
|