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';
|
2020-01-07 08:07:57 +01:00
|
|
|
import 'package:git_touch/graphql/gh.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/utils/utils.dart';
|
2020-01-27 07:43:10 +01: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';
|
2020-10-05 10:07:07 +02:00
|
|
|
import 'package:git_touch/widgets/contribution.dart';
|
2020-01-12 07:49:46 +01:00
|
|
|
import 'package:git_touch/widgets/mutation_button.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';
|
2020-10-04 16:20:21 +02:00
|
|
|
import 'package:git_touch/widgets/text_with_at.dart';
|
2019-09-27 14:52:38 +02:00
|
|
|
import 'package:git_touch/models/auth.dart';
|
2020-01-29 06:45:22 +01:00
|
|
|
import 'package:git_touch/widgets/user_header.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';
|
2021-01-05 10:25:19 +01:00
|
|
|
import '../generated/l10n.dart';
|
2019-01-27 17:37:44 +01:00
|
|
|
|
2020-02-07 07:17:05 +01:00
|
|
|
class GhUserScreen extends StatelessWidget {
|
2019-02-07 07:35:19 +01:00
|
|
|
final String login;
|
2020-02-07 07:17:05 +01:00
|
|
|
GhUserScreen(this.login);
|
2020-01-29 11:00:48 +01:00
|
|
|
bool get isViewer => login == null;
|
2020-01-01 09:35:50 +01:00
|
|
|
|
2020-01-07 08:07:57 +01:00
|
|
|
Iterable<Widget> _buildPinnedItems(Iterable<GhUserRepository> pinnedItems,
|
|
|
|
Iterable<GhUserRepository> repositories) {
|
2019-12-06 14:51:33 +01:00
|
|
|
String title;
|
2020-01-07 08:07:57 +01:00
|
|
|
Iterable<GhUserRepository> 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,
|
2020-01-11 10:25:01 +01:00
|
|
|
items.map((v) {
|
2020-01-11 12:52:17 +01:00
|
|
|
return RepositoryItem.gh(
|
2020-01-29 06:06:55 +01:00
|
|
|
owner: v.owner.login,
|
|
|
|
avatarUrl: v.owner.avatarUrl,
|
|
|
|
name: v.name,
|
|
|
|
description: v.description,
|
|
|
|
starCount: v.stargazers.totalCount,
|
|
|
|
forkCount: v.forks.totalCount,
|
|
|
|
primaryLanguageName: v.primaryLanguage?.name,
|
|
|
|
primaryLanguageColor: v.primaryLanguage?.color,
|
2020-01-11 12:52:17 +01:00
|
|
|
isPrivate: v.isPrivate,
|
|
|
|
isFork: v.isFork,
|
2020-01-11 10:25:01 +01:00
|
|
|
);
|
2019-12-06 14:51:33 +01:00
|
|
|
}).toList(),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2020-01-12 07:49:46 +01:00
|
|
|
Widget _buildUser(BuildContext context, GhUserUser p,
|
2020-01-11 14:22:52 +01:00
|
|
|
void Function(void Function()) setState) {
|
2019-12-06 14:51:33 +01:00
|
|
|
final theme = Provider.of<ThemeModel>(context);
|
2020-01-11 14:22:52 +01:00
|
|
|
final auth = Provider.of<AuthModel>(context);
|
2020-01-12 07:49:46 +01:00
|
|
|
final login = p.login;
|
2019-12-06 14:51:33 +01:00
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: <Widget>[
|
2020-01-29 06:45:22 +01:00
|
|
|
UserHeader(
|
|
|
|
avatarUrl: p.avatarUrl,
|
|
|
|
name: p.name,
|
|
|
|
login: p.login,
|
|
|
|
createdAt: p.createdAt,
|
|
|
|
bio: p.bio,
|
2020-10-08 11:09:50 +02:00
|
|
|
isViewer: isViewer,
|
|
|
|
rightWidgets: [
|
|
|
|
if (p.viewerCanFollow)
|
|
|
|
MutationButton(
|
|
|
|
active: p.viewerIsFollowing,
|
2021-01-05 10:25:19 +01:00
|
|
|
text: p.viewerIsFollowing
|
|
|
|
? S.of(context).unfollow
|
|
|
|
: S.of(context).follow,
|
2020-10-08 11:09:50 +02:00
|
|
|
onTap: () async {
|
|
|
|
if (p.viewerIsFollowing) {
|
|
|
|
await auth.ghClient.users.unfollowUser(p.login);
|
|
|
|
} else {
|
|
|
|
await auth.ghClient.users.followUser(p.login);
|
|
|
|
}
|
|
|
|
setState(() {
|
|
|
|
p.viewerIsFollowing = !p.viewerIsFollowing;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
2020-01-11 14:22:52 +01:00
|
|
|
),
|
2019-12-06 14:51:33 +01:00
|
|
|
CommonStyle.border,
|
|
|
|
Row(children: [
|
|
|
|
EntryItem(
|
2020-01-12 07:49:46 +01:00
|
|
|
count: p.repositories.totalCount,
|
2021-01-05 10:25:19 +01:00
|
|
|
text: S.of(context).repositories,
|
2020-05-12 17:31:30 +02:00
|
|
|
url: '/github/$login?tab=repositories',
|
2019-12-06 14:51:33 +01:00
|
|
|
),
|
|
|
|
EntryItem(
|
2020-01-12 07:49:46 +01:00
|
|
|
count: p.starredRepositories.totalCount,
|
2021-01-05 10:25:19 +01:00
|
|
|
text: S.of(context).stars,
|
2020-05-12 17:31:30 +02:00
|
|
|
url: '/github/$login?tab=stars',
|
2019-12-06 14:51:33 +01:00
|
|
|
),
|
|
|
|
EntryItem(
|
2020-01-12 07:49:46 +01:00
|
|
|
count: p.followers.totalCount,
|
2021-01-05 10:25:19 +01:00
|
|
|
text: S.of(context).followers,
|
2020-05-12 17:31:30 +02:00
|
|
|
url: '/github/$login?tab=followers',
|
2019-12-06 14:51:33 +01:00
|
|
|
),
|
|
|
|
EntryItem(
|
2020-01-12 07:49:46 +01:00
|
|
|
count: p.following.totalCount,
|
2021-01-05 10:25:19 +01:00
|
|
|
text: S.of(context).following,
|
2020-05-12 17:31:30 +02:00
|
|
|
url: '/github/$login?tab=following',
|
2019-12-06 14:51:33 +01:00
|
|
|
),
|
|
|
|
]),
|
2020-01-02 06:56:50 +01:00
|
|
|
CommonStyle.border,
|
2020-10-05 10:07:07 +02:00
|
|
|
ContributionWidget(
|
2020-10-05 10:47:26 +02:00
|
|
|
weeks: [
|
|
|
|
for (final week
|
|
|
|
in p.contributionsCollection.contributionCalendar.weeks)
|
|
|
|
[
|
2020-11-01 17:26:49 +01:00
|
|
|
// https://github.com/git-touch/git-touch/issues/122
|
2020-10-05 10:47:26 +02:00
|
|
|
for (final day in week.contributionDays)
|
2020-12-12 18:01:42 +01:00
|
|
|
ContributionDay(hexColor: day.color)
|
2020-10-05 10:47:26 +02:00
|
|
|
]
|
|
|
|
],
|
2020-01-01 06:26:20 +01:00
|
|
|
),
|
2020-01-02 06:56:50 +01:00
|
|
|
CommonStyle.border,
|
2019-12-06 14:51:33 +01:00
|
|
|
TableView(
|
|
|
|
hasIcon: true,
|
|
|
|
items: [
|
2020-05-14 07:28:12 +02:00
|
|
|
TableViewItem(
|
2020-10-04 15:04:23 +02:00
|
|
|
leftIconData: Icons.rss_feed,
|
2021-01-05 10:25:19 +01:00
|
|
|
text: Text(S.of(context).events),
|
2020-10-04 15:04:23 +02:00
|
|
|
url: '/github/$login?tab=events',
|
|
|
|
),
|
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.book,
|
2021-01-05 10:25:19 +01:00
|
|
|
text: Text(S.of(context).gists),
|
2020-10-04 15:04:23 +02:00
|
|
|
url: '/github/$login?tab=gists',
|
|
|
|
),
|
2020-04-28 18:59:01 +02:00
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.home,
|
2021-01-05 10:25:19 +01:00
|
|
|
text: Text(S.of(context).organizations),
|
2020-05-12 17:31:30 +02:00
|
|
|
url: '/github/$login?tab=organizations',
|
2020-04-28 18:59:01 +02:00
|
|
|
),
|
2020-01-12 07:49:46 +01:00
|
|
|
if (isNotNullOrEmpty(p.company))
|
2019-12-06 14:51:33 +01:00
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.organization,
|
2020-10-04 16:20:21 +02:00
|
|
|
text: TextWithAt(
|
|
|
|
text: p.company,
|
|
|
|
linkFactory: (text) => '/github/' + text.substring(1),
|
2020-01-27 08:11:51 +01:00
|
|
|
style: TextStyle(fontSize: 17, color: theme.palette.text),
|
2020-01-01 05:55:27 +01:00
|
|
|
oneLine: true,
|
2019-12-06 14:51:33 +01:00
|
|
|
),
|
|
|
|
),
|
2020-01-12 07:49:46 +01:00
|
|
|
if (isNotNullOrEmpty(p.location))
|
2019-12-06 14:51:33 +01:00
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.location,
|
2020-01-12 07:49:46 +01:00
|
|
|
text: Text(p.location),
|
2019-12-06 14:51:33 +01:00
|
|
|
onTap: () {
|
|
|
|
launchUrl('https://www.google.com/maps/place/' +
|
2020-01-12 07:49:46 +01:00
|
|
|
p.location.replaceAll(RegExp(r'\s+'), ''));
|
2019-12-06 14:51:33 +01:00
|
|
|
},
|
|
|
|
),
|
2020-01-12 07:49:46 +01:00
|
|
|
if (isNotNullOrEmpty(p.email))
|
2019-12-06 14:51:33 +01:00
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.mail,
|
2020-01-12 07:49:46 +01:00
|
|
|
text: Text(p.email),
|
2019-12-06 14:51:33 +01:00
|
|
|
onTap: () {
|
2020-01-12 07:49:46 +01:00
|
|
|
launchUrl('mailto:' + p.email);
|
2019-12-06 14:51:33 +01:00
|
|
|
},
|
|
|
|
),
|
2020-01-12 07:49:46 +01:00
|
|
|
if (isNotNullOrEmpty(p.websiteUrl))
|
2019-12-06 14:51:33 +01:00
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.link,
|
2020-01-12 07:49:46 +01:00
|
|
|
text: Text(p.websiteUrl),
|
2019-12-06 14:51:33 +01:00
|
|
|
onTap: () {
|
2020-01-12 07:49:46 +01:00
|
|
|
var url = p.websiteUrl;
|
2019-12-06 14:51:33 +01:00
|
|
|
if (!url.startsWith('http')) {
|
|
|
|
url = 'http://$url';
|
|
|
|
}
|
|
|
|
launchUrl(url);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2020-01-01 09:35:50 +01:00
|
|
|
CommonStyle.verticalGap,
|
2020-01-27 07:43:10 +01:00
|
|
|
// if (isViewer)
|
|
|
|
// TableView(
|
|
|
|
// hasIcon: true,
|
|
|
|
// items: [
|
|
|
|
// TableViewItem(
|
|
|
|
// leftIconData: Icons.settings,
|
|
|
|
// text: Text('Settings'),
|
|
|
|
// url: '/settings',
|
|
|
|
// ),
|
|
|
|
// TableViewItem(
|
|
|
|
// leftIconData: Icons.info_outline,
|
|
|
|
// text: Text('About'),
|
|
|
|
// url: '/about',
|
|
|
|
// ),
|
|
|
|
// ],
|
|
|
|
// )
|
|
|
|
// else
|
|
|
|
..._buildPinnedItems(
|
|
|
|
p.pinnedItems.nodes
|
|
|
|
.where((n) => n is GhUserRepository)
|
|
|
|
.cast<GhUserRepository>(),
|
|
|
|
p.repositories.nodes),
|
2019-12-06 14:51:33 +01:00
|
|
|
CommonStyle.verticalGap,
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-01-12 07:49:46 +01:00
|
|
|
Widget _buildOrganization(BuildContext context, GhUserOrganization p) {
|
2019-12-06 14:51:33 +01:00
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: <Widget>[
|
2020-01-29 06:45:22 +01:00
|
|
|
UserHeader(
|
|
|
|
avatarUrl: p.avatarUrl,
|
|
|
|
name: p.name,
|
|
|
|
login: p.login,
|
|
|
|
createdAt: p.createdAt,
|
|
|
|
bio: p.description,
|
|
|
|
),
|
2019-12-06 14:51:33 +01:00
|
|
|
CommonStyle.border,
|
|
|
|
Row(children: [
|
|
|
|
EntryItem(
|
2020-01-12 07:49:46 +01:00
|
|
|
count: p.pinnableItems.totalCount,
|
2021-01-05 10:25:19 +01:00
|
|
|
text: S.of(context).repositories,
|
2020-05-12 17:31:30 +02:00
|
|
|
url: '/github/${p.login}?tab=orgrepo',
|
2019-12-06 14:51:33 +01:00
|
|
|
),
|
|
|
|
EntryItem(
|
2020-01-12 07:49:46 +01:00
|
|
|
count: p.membersWithRole.totalCount,
|
2021-01-05 10:25:19 +01:00
|
|
|
text: S.of(context).members,
|
2020-05-12 17:31:30 +02:00
|
|
|
url: '/github/${p.login}?tab=people',
|
2019-12-06 14:51:33 +01:00
|
|
|
),
|
|
|
|
]),
|
|
|
|
TableView(
|
|
|
|
hasIcon: true,
|
|
|
|
items: [
|
2020-10-04 15:04:23 +02:00
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Icons.rss_feed,
|
2021-01-05 10:25:19 +01:00
|
|
|
text: Text(S.of(context).events),
|
2020-10-04 15:04:23 +02:00
|
|
|
url: '/github/$login?tab=events',
|
|
|
|
),
|
2020-01-12 07:49:46 +01:00
|
|
|
if (isNotNullOrEmpty(p.location))
|
2019-12-06 14:51:33 +01:00
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.location,
|
2020-01-12 07:49:46 +01:00
|
|
|
text: Text(p.location),
|
2019-12-06 14:51:33 +01:00
|
|
|
onTap: () {
|
|
|
|
launchUrl('https://www.google.com/maps/place/' +
|
2020-01-12 07:49:46 +01:00
|
|
|
p.location.replaceAll(RegExp(r'\s+'), ''));
|
2019-12-06 14:51:33 +01:00
|
|
|
},
|
|
|
|
),
|
2020-01-12 07:49:46 +01:00
|
|
|
if (isNotNullOrEmpty(p.email))
|
2019-12-06 14:51:33 +01:00
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.mail,
|
2020-01-12 07:49:46 +01:00
|
|
|
text: Text(p.email),
|
2019-12-06 14:51:33 +01:00
|
|
|
onTap: () {
|
2020-01-12 07:49:46 +01:00
|
|
|
launchUrl('mailto:' + p.email);
|
2019-12-06 14:51:33 +01:00
|
|
|
},
|
|
|
|
),
|
2020-01-12 07:49:46 +01:00
|
|
|
if (isNotNullOrEmpty(p.websiteUrl))
|
2019-12-06 14:51:33 +01:00
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.link,
|
2020-01-12 07:49:46 +01:00
|
|
|
text: Text(p.websiteUrl),
|
2019-12-06 14:51:33 +01:00
|
|
|
onTap: () {
|
2020-01-12 07:49:46 +01:00
|
|
|
var url = p.websiteUrl;
|
2019-12-06 14:51:33 +01:00
|
|
|
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(
|
2020-01-12 07:49:46 +01:00
|
|
|
p.pinnedItems.nodes
|
2020-01-07 08:07:57 +01:00
|
|
|
.where((n) => n is GhUserRepository)
|
|
|
|
.cast<GhUserRepository>(),
|
2020-01-12 07:49:46 +01:00
|
|
|
p.pinnableItems.nodes
|
2020-01-07 08:07:57 +01:00
|
|
|
.where((n) => n is GhUserRepository)
|
|
|
|
.cast<GhUserRepository>(),
|
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-07 08:32:48 +01:00
|
|
|
final auth = Provider.of<AuthModel>(context);
|
2020-01-07 08:07:57 +01:00
|
|
|
return RefreshStatefulScaffold<GhUserRepositoryOwner>(
|
2020-10-06 14:52:40 +02:00
|
|
|
fetch: () async {
|
2020-01-07 08:32:48 +01:00
|
|
|
final data = await auth.gqlClient.execute(GhUserQuery(
|
2020-01-29 11:00:48 +01:00
|
|
|
variables:
|
|
|
|
GhUserArguments(login: login ?? '', isViewer: isViewer)));
|
2020-01-01 09:35:50 +01:00
|
|
|
return isViewer ? data.data.viewer : data.data.repositoryOwner;
|
2019-03-07 14:10:52 +01:00
|
|
|
},
|
2021-01-05 10:25:19 +01:00
|
|
|
title: AppBarTitle(isViewer ? S.of(context).me : login),
|
2020-01-27 07:43:10 +01:00
|
|
|
action: isViewer
|
|
|
|
? ActionEntry(
|
|
|
|
iconData: Icons.settings,
|
2020-01-31 09:54:01 +01:00
|
|
|
url: '/settings',
|
2020-01-27 07:43:10 +01:00
|
|
|
)
|
|
|
|
: null,
|
|
|
|
actionBuilder: isViewer
|
|
|
|
? null
|
|
|
|
: (payload, setState) {
|
|
|
|
switch (payload.resolveType) {
|
|
|
|
case 'User':
|
|
|
|
final user = payload as GhUserUser;
|
|
|
|
return ActionButton(
|
|
|
|
title: 'User Actions',
|
|
|
|
items: [...ActionItem.getUrlActions(user.url)],
|
|
|
|
);
|
|
|
|
case 'Organization':
|
|
|
|
final organization = payload as GhUserOrganization;
|
|
|
|
return ActionButton(
|
|
|
|
title: 'Organization Actions',
|
|
|
|
items: [
|
|
|
|
...ActionItem.getUrlActions(organization.url),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
2020-01-11 14:22:52 +01:00
|
|
|
bodyBuilder: (payload, setState) {
|
2020-01-01 09:35:50 +01:00
|
|
|
if (isViewer) {
|
2020-01-11 14:22:52 +01:00
|
|
|
return _buildUser(context, payload as GhUserUser, setState);
|
2020-01-01 09:35:50 +01:00
|
|
|
}
|
2019-12-06 14:51:33 +01:00
|
|
|
switch (payload.resolveType) {
|
|
|
|
case 'User':
|
2020-01-11 14:22:52 +01:00
|
|
|
return _buildUser(context, payload as GhUserUser, setState);
|
2019-12-06 14:51:33 +01:00
|
|
|
case 'Organization':
|
2020-01-07 08:07:57 +01:00
|
|
|
return _buildOrganization(context, payload as GhUserOrganization);
|
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
|
|
|
}
|
|
|
|
}
|