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-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/settings.dart';
|
|
|
|
import 'package:git_touch/screens/users.dart';
|
|
|
|
import 'package:git_touch/utils/utils.dart';
|
2019-09-28 18:25:14 +02:00
|
|
|
import 'package:git_touch/widgets/action_entry.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';
|
|
|
|
import 'package:git_touch/widgets/entry_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-10-06 14:25:07 +02:00
|
|
|
import 'package:git_touch/widgets/user_contributions.dart';
|
2019-09-14 11:19:33 +02:00
|
|
|
import 'package:git_touch/widgets/user_item.dart';
|
2019-03-07 14:10:52 +01:00
|
|
|
import 'package:github_contributions/github_contributions.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-23 12:28:33 +02:00
|
|
|
import 'package:git_touch/widgets/repository_item.dart';
|
2019-09-30 10:31:07 +02:00
|
|
|
import 'package:git_touch/widgets/action_button.dart';
|
2019-10-06 15:27:00 +02:00
|
|
|
import 'package:primer/primer.dart';
|
2019-01-27 17:37:44 +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-10-06 15:27:00 +02:00
|
|
|
final bool isOrganization;
|
2019-02-07 07:35:19 +01:00
|
|
|
|
2019-10-06 15:27:00 +02:00
|
|
|
UserScreen(this.login, {this.isOrganization = false});
|
2019-02-07 07:35:19 +01:00
|
|
|
|
2019-10-06 15:27:00 +02:00
|
|
|
Future queryUser(BuildContext context) async {
|
2019-10-06 14:25:07 +02:00
|
|
|
var _login = login ?? Provider.of<AuthModel>(context).activeAccount.login;
|
2019-09-27 14:52:38 +02:00
|
|
|
var data = await Provider.of<AuthModel>(context).query('''
|
2019-01-27 17:37:44 +01:00
|
|
|
{
|
2019-10-06 14:25:07 +02:00
|
|
|
user(login: "$_login") {
|
2019-09-27 15:02:55 +02:00
|
|
|
$userGqlChunk
|
2019-02-08 12:34:07 +01:00
|
|
|
company
|
|
|
|
location
|
2019-09-04 16:59:33 +02:00
|
|
|
email
|
|
|
|
websiteUrl
|
2019-01-27 17:37:44 +01:00
|
|
|
starredRepositories {
|
|
|
|
totalCount
|
|
|
|
}
|
|
|
|
followers {
|
|
|
|
totalCount
|
|
|
|
}
|
|
|
|
following {
|
|
|
|
totalCount
|
|
|
|
}
|
2019-09-14 12:26:32 +02:00
|
|
|
repositories(first: 6, ownerAffiliations: OWNER, orderBy: {field: STARGAZERS, direction: DESC}) {
|
2019-02-03 08:50:17 +01:00
|
|
|
totalCount
|
|
|
|
nodes {
|
2019-02-04 11:32:39 +01:00
|
|
|
$repoChunk
|
2019-02-03 08:50:17 +01:00
|
|
|
}
|
|
|
|
}
|
2019-09-14 12:26:32 +02:00
|
|
|
pinnedItems(first: 6) {
|
2019-02-03 08:50:17 +01:00
|
|
|
nodes {
|
2019-09-03 10:35:13 +02:00
|
|
|
... on Repository {
|
|
|
|
$repoChunk
|
|
|
|
}
|
2019-02-03 08:50:17 +01:00
|
|
|
}
|
|
|
|
}
|
2019-02-10 11:50:40 +01:00
|
|
|
viewerCanFollow
|
|
|
|
viewerIsFollowing
|
|
|
|
url
|
2019-01-27 17:37:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
''');
|
2019-02-07 07:35:19 +01:00
|
|
|
return data['user'];
|
2019-02-06 15:28:04 +01:00
|
|
|
}
|
2019-02-04 11:32:39 +01:00
|
|
|
|
2019-10-06 15:27:00 +02:00
|
|
|
Future queryOrganization(BuildContext context) async {
|
|
|
|
// Use pinnableItems instead of organization here due to token permission
|
|
|
|
var data = await Provider.of<AuthModel>(context).query('''
|
|
|
|
{
|
|
|
|
organization(login: "$login") {
|
|
|
|
login
|
|
|
|
name
|
|
|
|
avatarUrl
|
|
|
|
description
|
|
|
|
location
|
|
|
|
email
|
|
|
|
websiteUrl
|
|
|
|
url
|
|
|
|
pinnedItems(first: 6) {
|
|
|
|
nodes {
|
|
|
|
... on Repository {
|
|
|
|
$repoChunk
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pinnableItems(first: 6, types: [REPOSITORY]) {
|
|
|
|
totalCount
|
|
|
|
nodes {
|
|
|
|
... on Repository {
|
|
|
|
$repoChunk
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
membersWithRole {
|
|
|
|
totalCount
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
''');
|
|
|
|
return data['organization'];
|
|
|
|
}
|
|
|
|
|
2019-10-06 14:25:07 +02:00
|
|
|
Future<List<ContributionsInfo>> fetchContributions(
|
|
|
|
BuildContext context) async {
|
|
|
|
var _login = login ?? Provider.of<AuthModel>(context).activeAccount.login;
|
|
|
|
switch (Provider.of<AuthModel>(context).activeAccount.platform) {
|
|
|
|
case PlatformType.gitlab:
|
|
|
|
return [];
|
|
|
|
default:
|
|
|
|
try {
|
|
|
|
return await getContributions(_login);
|
|
|
|
} catch (err) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
2019-09-11 11:30:03 +02:00
|
|
|
}
|
|
|
|
|
2019-01-25 13:35:20 +01:00
|
|
|
@override
|
2019-01-27 17:37:44 +01:00
|
|
|
Widget build(BuildContext context) {
|
2019-09-25 11:06:36 +02:00
|
|
|
return RefreshStatefulScaffold(
|
2019-09-30 11:13:12 +02:00
|
|
|
fetchData: () {
|
2019-03-07 14:10:52 +01:00
|
|
|
return Future.wait(
|
2019-10-06 15:27:00 +02:00
|
|
|
isOrganization
|
|
|
|
? [
|
|
|
|
queryOrganization(context),
|
|
|
|
Future.value([].cast<ContributionsInfo>())
|
|
|
|
]
|
|
|
|
: [
|
|
|
|
queryUser(context),
|
|
|
|
fetchContributions(context),
|
|
|
|
],
|
2019-03-07 14:10:52 +01:00
|
|
|
);
|
|
|
|
},
|
2019-10-06 15:27:00 +02:00
|
|
|
title: AppBarTitle(isOrganization ? 'Organization' : 'User'),
|
2019-09-30 11:13:12 +02:00
|
|
|
actionBuilder: (payload) {
|
|
|
|
var data = payload.data;
|
2019-10-06 15:27:00 +02:00
|
|
|
|
|
|
|
if (isOrganization) {
|
|
|
|
return ActionButton(
|
|
|
|
title: 'Organization Actions',
|
|
|
|
items: [
|
|
|
|
if (data != null) ...[
|
|
|
|
ActionItem.share(payload.data[0]['url']),
|
|
|
|
ActionItem.launch(payload.data[0]['url']),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-10-06 14:25:07 +02:00
|
|
|
if (login == null) {
|
2019-09-28 18:25:14 +02:00
|
|
|
return ActionEntry(
|
|
|
|
iconData: Icons.settings,
|
|
|
|
onTap: () {
|
|
|
|
Provider.of<ThemeModel>(context).pushRoute(
|
|
|
|
context, (_) => SettingsScreen(),
|
|
|
|
fullscreenDialog: true);
|
|
|
|
},
|
2019-02-10 11:50:40 +01:00
|
|
|
);
|
|
|
|
} else {
|
2019-09-25 15:41:44 +02:00
|
|
|
return ActionButton(
|
|
|
|
title: 'User Actions',
|
2019-09-30 09:46:06 +02:00
|
|
|
items: [
|
2019-09-25 15:41:44 +02:00
|
|
|
if (data != null && data[0]['viewerCanFollow'])
|
2019-09-30 09:46:06 +02:00
|
|
|
ActionItem(
|
2019-09-25 15:41:44 +02:00
|
|
|
text: data[0]['viewerIsFollowing'] ? 'Unfollow' : 'Follow',
|
|
|
|
onPress: () async {
|
|
|
|
if (data[0]['viewerIsFollowing']) {
|
2019-09-27 14:52:38 +02:00
|
|
|
await Provider.of<AuthModel>(context)
|
2019-09-25 15:41:44 +02:00
|
|
|
.deleteWithCredentials('/user/following/$login');
|
|
|
|
data[0]['viewerIsFollowing'] = false;
|
|
|
|
} else {
|
2019-09-27 14:52:38 +02:00
|
|
|
Provider.of<AuthModel>(context)
|
2019-09-25 15:41:44 +02:00
|
|
|
.putWithCredentials('/user/following/$login');
|
|
|
|
data[0]['viewerIsFollowing'] = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
2019-09-30 09:46:06 +02:00
|
|
|
if (data != null) ...[
|
|
|
|
ActionItem.share(data[0]['url']),
|
|
|
|
ActionItem.launch(data[0]['url']),
|
|
|
|
],
|
2019-09-25 15:41:44 +02:00
|
|
|
],
|
|
|
|
);
|
2019-02-10 11:50:40 +01:00
|
|
|
}
|
|
|
|
},
|
2019-09-30 11:13:12 +02:00
|
|
|
bodyBuilder: (payload) {
|
|
|
|
var data = payload.data[0];
|
2019-10-06 15:27:00 +02:00
|
|
|
var contributions = payload.data[1];
|
2019-02-03 16:10:10 +01:00
|
|
|
return Column(
|
2019-09-05 11:58:14 +02:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
2019-02-03 16:10:10 +01:00
|
|
|
children: <Widget>[
|
2019-10-06 15:27:00 +02:00
|
|
|
UserItem(
|
|
|
|
login: data['login'],
|
|
|
|
name: data['name'],
|
|
|
|
avatarUrl: data['avatarUrl'],
|
|
|
|
bio: isOrganization ? data['description'] : data['bio'],
|
|
|
|
inUserScreen: true,
|
|
|
|
),
|
2019-10-02 10:09:54 +02:00
|
|
|
CommonStyle.border,
|
2019-10-06 15:27:00 +02:00
|
|
|
Row(children: [
|
|
|
|
if (isOrganization) ...[
|
|
|
|
EntryItem(
|
|
|
|
count: data['pinnableItems']['totalCount'],
|
|
|
|
text: 'Repositories',
|
|
|
|
screenBuilder: (context) =>
|
|
|
|
RepositoriesScreen.ofOrganization(data['login']),
|
|
|
|
),
|
|
|
|
EntryItem(
|
|
|
|
count: data['membersWithRole']['totalCount'],
|
|
|
|
text: 'Members',
|
|
|
|
screenBuilder: (context) =>
|
|
|
|
UsersScreen.members(data['login']),
|
|
|
|
),
|
|
|
|
] else ...[
|
|
|
|
EntryItem(
|
|
|
|
count: data['repositories']['totalCount'],
|
|
|
|
text: 'Repositories',
|
|
|
|
screenBuilder: (context) => RepositoriesScreen(data['login']),
|
|
|
|
),
|
|
|
|
EntryItem(
|
|
|
|
count: data['starredRepositories']['totalCount'],
|
|
|
|
text: 'Stars',
|
|
|
|
screenBuilder: (context) =>
|
|
|
|
RepositoriesScreen.stars(data['login']),
|
|
|
|
),
|
|
|
|
EntryItem(
|
|
|
|
count: data['followers']['totalCount'],
|
|
|
|
text: 'Followers',
|
|
|
|
screenBuilder: (context) =>
|
|
|
|
UsersScreen.followers(data['login']),
|
|
|
|
),
|
|
|
|
EntryItem(
|
|
|
|
count: data['following']['totalCount'],
|
|
|
|
text: 'Following',
|
|
|
|
screenBuilder: (context) =>
|
|
|
|
UsersScreen.following(data['login']),
|
|
|
|
),
|
|
|
|
]
|
2019-09-05 11:58:14 +02:00
|
|
|
]),
|
2019-10-02 10:09:54 +02:00
|
|
|
CommonStyle.verticalGap,
|
2019-10-06 14:25:07 +02:00
|
|
|
if (contributions.isNotEmpty) ...[
|
|
|
|
UserContributions(contributions),
|
|
|
|
CommonStyle.verticalGap,
|
|
|
|
],
|
2019-09-15 09:08:09 +02:00
|
|
|
TableView(
|
|
|
|
hasIcon: true,
|
|
|
|
items: [
|
2019-10-06 15:27:00 +02:00
|
|
|
if (!isOrganization && isNotNullOrEmpty(data['company']))
|
2019-09-15 09:08:09 +02:00
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.organization,
|
2019-09-30 11:13:12 +02:00
|
|
|
text: TextContainsOrganization(data['company'],
|
2019-09-27 12:23:47 +02:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 16, color: PrimerColors.gray900),
|
|
|
|
overflow: TextOverflow.ellipsis),
|
2019-09-15 09:08:09 +02:00
|
|
|
),
|
2019-09-30 11:13:12 +02:00
|
|
|
if (isNotNullOrEmpty(data['location']))
|
2019-09-15 09:08:09 +02:00
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.location,
|
2019-09-30 11:13:12 +02:00
|
|
|
text: Text(data['location']),
|
2019-09-15 09:08:09 +02:00
|
|
|
onTap: () {
|
2019-09-29 07:32:53 +02:00
|
|
|
launchUrl('https://www.google.com/maps/place/' +
|
2019-09-30 11:13:12 +02:00
|
|
|
(data['location'] as String)
|
2019-09-15 09:08:09 +02:00
|
|
|
.replaceAll(RegExp(r'\s+'), ''));
|
|
|
|
},
|
|
|
|
),
|
2019-09-30 11:13:12 +02:00
|
|
|
if (isNotNullOrEmpty(data['email']))
|
2019-09-15 09:08:09 +02:00
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.mail,
|
2019-09-30 11:13:12 +02:00
|
|
|
text: Text(data['email']),
|
2019-09-15 09:08:09 +02:00
|
|
|
onTap: () {
|
2019-09-30 11:13:12 +02:00
|
|
|
launchUrl('mailto:' + data['email']);
|
2019-09-15 09:08:09 +02:00
|
|
|
},
|
|
|
|
),
|
2019-09-30 11:13:12 +02:00
|
|
|
if (isNotNullOrEmpty(data['websiteUrl']))
|
2019-09-15 09:08:09 +02:00
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.link,
|
2019-09-30 11:13:12 +02:00
|
|
|
text: Text(data['websiteUrl']),
|
2019-09-15 09:08:09 +02:00
|
|
|
onTap: () {
|
2019-09-30 11:13:12 +02:00
|
|
|
var url = data['websiteUrl'] as String;
|
2019-09-15 09:08:09 +02:00
|
|
|
if (!url.startsWith('http')) {
|
|
|
|
url = 'http://$url';
|
|
|
|
}
|
2019-09-29 07:32:53 +02:00
|
|
|
launchUrl(url);
|
2019-09-15 09:08:09 +02:00
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2019-10-06 09:50:22 +02:00
|
|
|
...buildPinnedItems(
|
2019-10-06 15:27:00 +02:00
|
|
|
data['pinnedItems']['nodes'],
|
|
|
|
data[isOrganization ? 'pinnableItems' : 'repositories']
|
|
|
|
['nodes']),
|
2019-10-02 10:09:54 +02:00
|
|
|
CommonStyle.verticalGap,
|
2019-02-03 16:10:10 +01:00
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
2019-02-03 08:50:17 +01:00
|
|
|
);
|
2019-01-25 13:35:20 +01:00
|
|
|
}
|
|
|
|
}
|