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

156 lines
4.7 KiB
Dart
Raw Normal View History

2019-02-04 14:38:29 +01:00
import 'package:flutter/material.dart';
2020-01-07 08:07:57 +01:00
import 'package:git_touch/graphql/gh.dart';
import 'package:git_touch/models/theme.dart';
2019-09-25 11:06:36 +02:00
import 'package:git_touch/scaffolds/list_stateful.dart';
import 'package:git_touch/utils/utils.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
2020-02-07 07:17:05 +01:00
class GhUsersScreen extends StatelessWidget {
2019-12-07 16:10:30 +01:00
final String login;
final String repoName;
final UsersScreenType type;
2020-02-07 07:17:05 +01:00
GhUsersScreen(this.login, this.type, {this.repoName = ''});
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;
}
}
Widget _buildBio(BuildContext context, String company, String location,
DateTime createdAt) {
final theme = Provider.of<ThemeModel>(context);
if (company != null && company.isNotEmpty) {
return Row(
children: <Widget>[
Icon(
Octicons.organization,
size: 15,
2020-01-27 08:11:51 +01:00
color: theme.palette.secondaryText,
),
SizedBox(width: 4),
2020-04-05 16:32:42 +02:00
Expanded(child: Text(company, overflow: TextOverflow.ellipsis)),
],
);
}
if (location != null && location.isNotEmpty) {
return Row(
children: <Widget>[
Icon(
Octicons.location,
size: 15,
2020-01-27 08:11:51 +01:00
color: theme.palette.secondaryText,
),
SizedBox(width: 4),
2020-04-05 16:32:42 +02:00
Expanded(child: Text(location, overflow: TextOverflow.ellipsis)),
],
);
}
return Row(
children: <Widget>[
Icon(
Octicons.clock,
size: 15,
2020-01-27 08:11:51 +01:00
color: theme.palette.secondaryText,
),
SizedBox(width: 4),
2020-04-05 16:32:42 +02:00
Expanded(
child: Text('Joined on ${dateFormat.format(createdAt)}',
overflow: TextOverflow.ellipsis)),
],
);
}
2019-02-04 14:38:29 +01:00
@override
Widget build(BuildContext context) {
2020-01-07 08:07:57 +01:00
return ListStatefulScaffold<GhUsersUser, String>(
2019-12-07 16:10:30 +01:00
title: AppBarTitle(_title),
fetch: (cursor) async {
2020-10-04 16:10:05 +02:00
final auth = context.read<AuthModel>();
final res = await auth.gqlClient.execute(GhUsersQuery(
variables: GhUsersArguments(
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-12-07 16:10:30 +01:00
itemBuilder: (payload) {
2020-10-08 09:55:26 +02:00
return UserItem.github(
2019-12-07 16:10:30 +01:00
login: payload.login,
2020-10-08 09:55:26 +02:00
name: payload.name,
2019-12-07 16:10:30 +01:00
avatarUrl: payload.avatarUrl,
bio: _buildBio(
context, payload.company, payload.location, payload.createdAt),
2019-12-07 16:10:30 +01:00
);
},
);
2019-02-04 14:38:29 +01:00
}
}