2019-01-27 17:37:44 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2019-01-25 13:35:20 +01:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2019-12-07 08:28:43 +01:00
|
|
|
import 'package:git_touch/graphql/github_user.dart';
|
2019-09-28 18:25:14 +02:00
|
|
|
import 'package:git_touch/models/theme.dart';
|
2019-09-25 11:06:36 +02:00
|
|
|
import 'package:git_touch/scaffolds/refresh_stateful.dart';
|
2019-10-06 15:27:00 +02:00
|
|
|
import 'package:git_touch/screens/users.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-10-06 15:27:00 +02:00
|
|
|
import 'package:git_touch/screens/repositories.dart';
|
2020-01-01 08:58:49 +01:00
|
|
|
import 'package:git_touch/widgets/avatar.dart';
|
2019-10-06 15:27:00 +02:00
|
|
|
import 'package:git_touch/widgets/entry_item.dart';
|
2019-12-06 14:51:33 +01:00
|
|
|
import 'package:git_touch/widgets/repository_item.dart';
|
2019-09-04 16:59:33 +02:00
|
|
|
import 'package:git_touch/widgets/table_view.dart';
|
2019-09-27 12:23:47 +02:00
|
|
|
import 'package:git_touch/widgets/text_contains_organization.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-09-30 10:31:07 +02:00
|
|
|
import 'package:git_touch/widgets/action_button.dart';
|
2019-01-27 17:37:44 +01:00
|
|
|
|
2019-12-13 06:13:45 +01:00
|
|
|
final userRouter = RouterScreen(
|
2019-12-13 06:40:05 +01:00
|
|
|
'/:login',
|
|
|
|
(context, parameters) {
|
|
|
|
final login = parameters['login'].first;
|
2019-12-13 15:23:18 +01:00
|
|
|
final tab = parameters['tab']?.first;
|
2019-12-13 06:40:05 +01:00
|
|
|
switch (tab) {
|
|
|
|
case 'followers':
|
|
|
|
return UsersScreen(login, UsersScreenType.follower);
|
|
|
|
case 'following':
|
|
|
|
return UsersScreen(login, UsersScreenType.following);
|
|
|
|
case 'people':
|
|
|
|
return UsersScreen(login, UsersScreenType.member);
|
|
|
|
case 'stars':
|
|
|
|
return RepositoriesScreen.stars(login);
|
|
|
|
case 'repositories':
|
|
|
|
return RepositoriesScreen(login);
|
|
|
|
default:
|
2019-12-13 15:23:18 +01:00
|
|
|
return UserScreen(login);
|
2019-12-13 06:40:05 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
2019-12-13 06:13:45 +01:00
|
|
|
|
2019-09-13 10:55:27 +02:00
|
|
|
class UserScreen extends StatelessWidget {
|
2019-02-07 07:35:19 +01:00
|
|
|
final String login;
|
|
|
|
|
2019-11-02 12:32:52 +01:00
|
|
|
UserScreen(this.login);
|
2019-02-07 07:35:19 +01:00
|
|
|
|
2020-01-01 09:35:50 +01:00
|
|
|
bool get isViewer => login.isEmpty;
|
|
|
|
|
2019-12-07 08:28:43 +01:00
|
|
|
Iterable<Widget> _buildPinnedItems(Iterable<GithubUserRepository> pinnedItems,
|
|
|
|
Iterable<GithubUserRepository> repositories) {
|
2019-12-06 14:51:33 +01:00
|
|
|
String title;
|
2019-12-07 08:28:43 +01:00
|
|
|
Iterable<GithubUserRepository> items = [];
|
2019-12-06 14:51:33 +01:00
|
|
|
|
|
|
|
if (pinnedItems.isNotEmpty) {
|
|
|
|
title = 'pinned repositories';
|
|
|
|
items = pinnedItems;
|
|
|
|
} else if (repositories.isNotEmpty) {
|
|
|
|
title = 'popular repositories';
|
|
|
|
items = repositories;
|
|
|
|
}
|
|
|
|
if (items.isEmpty) return [];
|
|
|
|
|
|
|
|
return [
|
|
|
|
if (title != null) TableViewHeader(title),
|
|
|
|
...join(
|
|
|
|
CommonStyle.border,
|
|
|
|
items.map((item) {
|
|
|
|
return RepositoryItem.github(item);
|
|
|
|
}).toList(),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2020-01-01 08:58:49 +01:00
|
|
|
Widget _buildHeader(BuildContext context, String avatarUrl, String name,
|
2020-01-01 09:35:50 +01:00
|
|
|
String login, DateTime createdAt, String bio) {
|
2020-01-01 08:58:49 +01:00
|
|
|
final theme = Provider.of<ThemeModel>(context);
|
|
|
|
|
|
|
|
return Container(
|
|
|
|
padding: CommonStyle.padding,
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: <Widget>[
|
|
|
|
Row(
|
|
|
|
children: <Widget>[
|
|
|
|
Avatar(url: avatarUrl, size: AvatarSize.large),
|
|
|
|
SizedBox(width: 10),
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
Row(
|
|
|
|
children: <Widget>[
|
|
|
|
if (name != null) ...[
|
|
|
|
Text(
|
|
|
|
name,
|
|
|
|
style: TextStyle(
|
|
|
|
color: theme.palette.primary,
|
|
|
|
fontSize: 19,
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(width: 4),
|
|
|
|
],
|
|
|
|
Text(
|
|
|
|
'($login)',
|
|
|
|
style: TextStyle(
|
|
|
|
color: theme.palette.secondaryText,
|
|
|
|
fontSize: 16,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
SizedBox(height: 6),
|
|
|
|
Row(
|
|
|
|
children: <Widget>[
|
|
|
|
Icon(
|
|
|
|
Octicons.clock,
|
|
|
|
size: 15,
|
|
|
|
color: theme.palette.secondaryText,
|
|
|
|
),
|
|
|
|
SizedBox(width: 4),
|
|
|
|
Text(
|
|
|
|
'Joined on ${dateFormat.format(createdAt)}',
|
|
|
|
style: TextStyle(
|
|
|
|
color: theme.palette.secondaryText,
|
|
|
|
fontSize: 15,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
if (bio != null && bio.isNotEmpty) ...[
|
|
|
|
SizedBox(height: 12),
|
|
|
|
Text(
|
|
|
|
bio,
|
|
|
|
style: TextStyle(
|
|
|
|
color: theme.palette.secondaryText,
|
|
|
|
fontSize: 17,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
]
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-01-01 06:26:20 +01:00
|
|
|
Widget _buildUser(BuildContext context, GithubUserUser user) {
|
2019-12-06 14:51:33 +01:00
|
|
|
final theme = Provider.of<ThemeModel>(context);
|
2019-12-13 06:40:05 +01:00
|
|
|
final login = user.login;
|
2019-12-06 14:51:33 +01:00
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: <Widget>[
|
2020-01-01 09:35:50 +01:00
|
|
|
_buildHeader(context, user.avatarUrl, user.name, user.login,
|
|
|
|
user.createdAt, user.bio),
|
2019-12-06 14:51:33 +01:00
|
|
|
CommonStyle.border,
|
|
|
|
Row(children: [
|
|
|
|
EntryItem(
|
|
|
|
count: user.repositories.totalCount,
|
|
|
|
text: 'Repositories',
|
2019-12-13 06:40:05 +01:00
|
|
|
url: '/$login?tab=repositories',
|
2019-12-06 14:51:33 +01:00
|
|
|
),
|
|
|
|
EntryItem(
|
|
|
|
count: user.starredRepositories.totalCount,
|
|
|
|
text: 'Stars',
|
2019-12-13 06:40:05 +01:00
|
|
|
url: '/$login?tab=stars',
|
2019-12-06 14:51:33 +01:00
|
|
|
),
|
|
|
|
EntryItem(
|
|
|
|
count: user.followers.totalCount,
|
|
|
|
text: 'Followers',
|
2019-12-13 06:40:05 +01:00
|
|
|
url: '/$login?tab=followers',
|
2019-12-06 14:51:33 +01:00
|
|
|
),
|
|
|
|
EntryItem(
|
|
|
|
count: user.following.totalCount,
|
|
|
|
text: 'Following',
|
2019-12-13 06:40:05 +01:00
|
|
|
url: '/$login?tab=following',
|
2019-12-06 14:51:33 +01:00
|
|
|
),
|
|
|
|
]),
|
|
|
|
CommonStyle.verticalGap,
|
2020-01-01 06:26:20 +01:00
|
|
|
Container(
|
|
|
|
color: theme.palette.background,
|
|
|
|
padding: CommonStyle.padding,
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
reverse: true,
|
|
|
|
child: Wrap(
|
|
|
|
spacing: 3,
|
|
|
|
children: user.contributionsCollection.contributionCalendar.weeks
|
|
|
|
.map((week) {
|
|
|
|
return Wrap(
|
|
|
|
direction: Axis.vertical,
|
|
|
|
spacing: 3,
|
|
|
|
children: week.contributionDays.map((day) {
|
|
|
|
var color = convertColor(day.color);
|
|
|
|
if (theme.brightness == Brightness.dark) {
|
|
|
|
color = Color.fromRGBO(0xff - color.red,
|
|
|
|
0xff - color.green, 0xff - color.blue, 1);
|
|
|
|
}
|
|
|
|
return SizedBox(
|
|
|
|
width: 10,
|
|
|
|
height: 10,
|
|
|
|
child: DecoratedBox(
|
|
|
|
decoration: BoxDecoration(color: color),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}).toList(),
|
|
|
|
);
|
|
|
|
}).toList(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2019-12-06 14:51:33 +01:00
|
|
|
CommonStyle.verticalGap,
|
|
|
|
TableView(
|
|
|
|
hasIcon: true,
|
|
|
|
items: [
|
|
|
|
if (isNotNullOrEmpty(user.company))
|
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.organization,
|
|
|
|
text: TextContainsOrganization(
|
|
|
|
user.company,
|
|
|
|
style: TextStyle(fontSize: 16, color: theme.palette.text),
|
2020-01-01 05:55:27 +01:00
|
|
|
oneLine: true,
|
2019-12-06 14:51:33 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
if (isNotNullOrEmpty(user.location))
|
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.location,
|
|
|
|
text: Text(user.location),
|
|
|
|
onTap: () {
|
|
|
|
launchUrl('https://www.google.com/maps/place/' +
|
|
|
|
user.location.replaceAll(RegExp(r'\s+'), ''));
|
|
|
|
},
|
|
|
|
),
|
|
|
|
if (isNotNullOrEmpty(user.email))
|
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.mail,
|
|
|
|
text: Text(user.email),
|
|
|
|
onTap: () {
|
|
|
|
launchUrl('mailto:' + user.email);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
if (isNotNullOrEmpty(user.websiteUrl))
|
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.link,
|
|
|
|
text: Text(user.websiteUrl),
|
|
|
|
onTap: () {
|
|
|
|
var url = user.websiteUrl;
|
|
|
|
if (!url.startsWith('http')) {
|
|
|
|
url = 'http://$url';
|
|
|
|
}
|
|
|
|
launchUrl(url);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2020-01-01 09:35:50 +01:00
|
|
|
CommonStyle.verticalGap,
|
|
|
|
if (isViewer)
|
|
|
|
TableView(
|
|
|
|
hasIcon: true,
|
|
|
|
items: [
|
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.settings,
|
|
|
|
text: Text('Settings'),
|
|
|
|
url: '/settings',
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
else
|
|
|
|
..._buildPinnedItems(
|
|
|
|
user.pinnedItems.nodes
|
|
|
|
.where((n) => n is GithubUserRepository)
|
|
|
|
.cast<GithubUserRepository>(),
|
|
|
|
user.repositories.nodes),
|
2019-12-06 14:51:33 +01:00
|
|
|
CommonStyle.verticalGap,
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-12-07 08:28:43 +01:00
|
|
|
Widget _buildOrganization(
|
|
|
|
BuildContext context, GithubUserOrganization payload) {
|
2019-12-06 14:51:33 +01:00
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: <Widget>[
|
2020-01-01 09:35:50 +01:00
|
|
|
_buildHeader(context, payload.avatarUrl, payload.name, payload.login,
|
2020-01-01 08:58:49 +01:00
|
|
|
payload.createdAt, payload.description),
|
2019-12-06 14:51:33 +01:00
|
|
|
CommonStyle.border,
|
|
|
|
Row(children: [
|
|
|
|
EntryItem(
|
2019-12-07 06:31:54 +01:00
|
|
|
count: payload.pinnableItems.totalCount,
|
2019-12-06 14:51:33 +01:00
|
|
|
text: 'Repositories',
|
2020-01-01 09:35:50 +01:00
|
|
|
url: '/${payload.login}?tab=repositories',
|
2019-12-06 14:51:33 +01:00
|
|
|
),
|
|
|
|
EntryItem(
|
|
|
|
count: payload.membersWithRole.totalCount,
|
|
|
|
text: 'Members',
|
2020-01-01 09:35:50 +01:00
|
|
|
url: '/${payload.login}?tab=people',
|
2019-12-06 14:51:33 +01:00
|
|
|
),
|
|
|
|
]),
|
|
|
|
CommonStyle.verticalGap,
|
|
|
|
TableView(
|
|
|
|
hasIcon: true,
|
|
|
|
items: [
|
|
|
|
if (isNotNullOrEmpty(payload.location))
|
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.location,
|
|
|
|
text: Text(payload.location),
|
|
|
|
onTap: () {
|
|
|
|
launchUrl('https://www.google.com/maps/place/' +
|
|
|
|
payload.location.replaceAll(RegExp(r'\s+'), ''));
|
|
|
|
},
|
|
|
|
),
|
|
|
|
if (isNotNullOrEmpty(payload.email))
|
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.mail,
|
|
|
|
text: Text(payload.email),
|
|
|
|
onTap: () {
|
|
|
|
launchUrl('mailto:' + payload.email);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
if (isNotNullOrEmpty(payload.websiteUrl))
|
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.link,
|
|
|
|
text: Text(payload.websiteUrl),
|
|
|
|
onTap: () {
|
|
|
|
var url = payload.websiteUrl;
|
|
|
|
if (!url.startsWith('http')) {
|
|
|
|
url = 'http://$url';
|
|
|
|
}
|
|
|
|
launchUrl(url);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2020-01-01 09:35:50 +01:00
|
|
|
CommonStyle.verticalGap,
|
2019-12-06 14:51:33 +01:00
|
|
|
..._buildPinnedItems(
|
|
|
|
payload.pinnedItems.nodes
|
2019-12-07 08:28:43 +01:00
|
|
|
.where((n) => n is GithubUserRepository)
|
|
|
|
.cast<GithubUserRepository>(),
|
2019-12-06 14:51:33 +01:00
|
|
|
payload.pinnableItems.nodes
|
2019-12-07 08:28:43 +01:00
|
|
|
.where((n) => n is GithubUserRepository)
|
|
|
|
.cast<GithubUserRepository>(),
|
2019-12-06 14:51:33 +01:00
|
|
|
),
|
|
|
|
CommonStyle.verticalGap,
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-01-25 13:35:20 +01:00
|
|
|
@override
|
2019-01-27 17:37:44 +01:00
|
|
|
Widget build(BuildContext context) {
|
2020-01-01 06:26:20 +01:00
|
|
|
return RefreshStatefulScaffold<GithubUserRepositoryOwner>(
|
2019-12-06 14:51:33 +01:00
|
|
|
fetchData: () async {
|
2020-01-01 06:26:20 +01:00
|
|
|
final data = await Provider.of<AuthModel>(context).gqlClient.execute(
|
2020-01-01 09:35:50 +01:00
|
|
|
GithubUserQuery(
|
|
|
|
variables:
|
|
|
|
GithubUserArguments(login: login, isViewer: isViewer)));
|
|
|
|
return isViewer ? data.data.viewer : data.data.repositoryOwner;
|
2019-03-07 14:10:52 +01:00
|
|
|
},
|
2020-01-01 09:35:50 +01:00
|
|
|
title: AppBarTitle(isViewer ? 'Me' : 'User'), // TODO:
|
2020-01-01 06:26:20 +01:00
|
|
|
actionBuilder: (payload, _) {
|
2019-12-06 14:51:33 +01:00
|
|
|
switch (payload.resolveType) {
|
2019-11-02 12:32:52 +01:00
|
|
|
case 'User':
|
2019-12-07 08:28:43 +01:00
|
|
|
final user = payload as GithubUserUser;
|
2019-12-17 06:34:53 +01:00
|
|
|
return ActionButton(
|
|
|
|
title: 'User Actions',
|
|
|
|
items: [
|
|
|
|
if (user.viewerCanFollow)
|
|
|
|
ActionItem(
|
|
|
|
text: user.viewerIsFollowing ? 'Unfollow' : 'Follow',
|
|
|
|
onPress: (_) async {
|
|
|
|
if (user.viewerIsFollowing) {
|
|
|
|
await Provider.of<AuthModel>(context)
|
2020-01-01 09:35:50 +01:00
|
|
|
.deleteWithCredentials(
|
|
|
|
'/user/following/${user.login}');
|
2019-12-17 06:34:53 +01:00
|
|
|
user.viewerIsFollowing = false;
|
|
|
|
} else {
|
2020-01-01 09:35:50 +01:00
|
|
|
Provider.of<AuthModel>(context).putWithCredentials(
|
|
|
|
'/user/following/${user.login}');
|
2019-12-17 06:34:53 +01:00
|
|
|
user.viewerIsFollowing = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
2020-01-01 06:26:20 +01:00
|
|
|
if (payload != null) ...[
|
2019-12-17 06:34:53 +01:00
|
|
|
ActionItem.share(user.url),
|
|
|
|
ActionItem.launch(user.url),
|
2019-11-02 12:32:52 +01:00
|
|
|
],
|
2019-12-17 06:34:53 +01:00
|
|
|
],
|
|
|
|
);
|
2019-11-02 12:32:52 +01:00
|
|
|
case 'Organization':
|
2019-12-07 08:28:43 +01:00
|
|
|
final organization = payload as GithubUserOrganization;
|
2019-11-02 12:32:52 +01:00
|
|
|
return ActionButton(
|
|
|
|
title: 'Organization Actions',
|
|
|
|
items: [
|
2020-01-01 06:26:20 +01:00
|
|
|
if (payload != null) ...[
|
2019-12-06 14:51:33 +01:00
|
|
|
ActionItem.share(organization.url),
|
|
|
|
ActionItem.launch(organization.url),
|
2019-11-02 12:32:52 +01:00
|
|
|
],
|
2019-09-30 09:46:06 +02:00
|
|
|
],
|
2019-11-02 12:32:52 +01:00
|
|
|
);
|
|
|
|
default:
|
|
|
|
return null;
|
2019-02-10 11:50:40 +01:00
|
|
|
}
|
|
|
|
},
|
2020-01-01 06:26:20 +01:00
|
|
|
bodyBuilder: (payload, _) {
|
2020-01-01 09:35:50 +01:00
|
|
|
if (isViewer) {
|
|
|
|
return _buildUser(context, payload as GithubUserUser);
|
|
|
|
}
|
2019-12-06 14:51:33 +01:00
|
|
|
switch (payload.resolveType) {
|
|
|
|
case 'User':
|
2020-01-01 06:26:20 +01:00
|
|
|
return _buildUser(context, payload as GithubUserUser);
|
2019-12-06 14:51:33 +01:00
|
|
|
case 'Organization':
|
2019-12-07 08:28:43 +01:00
|
|
|
return _buildOrganization(
|
|
|
|
context, payload as GithubUserOrganization);
|
2019-12-06 14:51:33 +01:00
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
2019-02-03 16:10:10 +01:00
|
|
|
},
|
2019-02-03 08:50:17 +01:00
|
|
|
);
|
2019-01-25 13:35:20 +01:00
|
|
|
}
|
|
|
|
}
|