2022-09-20 20:00:03 +02:00
|
|
|
import 'package:antd_mobile/antd_mobile.dart';
|
2019-01-25 13:35:20 +01:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2022-09-17 14:35:45 +02:00
|
|
|
import 'package:flutter/widgets.dart';
|
2022-09-13 19:19:52 +02:00
|
|
|
import 'package:flutter_gen/gen_l10n/S.dart';
|
2022-09-06 18:00:51 +02:00
|
|
|
import 'package:git_touch/graphql/__generated__/github.data.gql.dart';
|
|
|
|
import 'package:git_touch/graphql/__generated__/github.req.gql.dart';
|
2022-09-13 19:19:52 +02:00
|
|
|
import 'package:git_touch/models/auth.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';
|
2022-09-13 19:19:52 +02:00
|
|
|
import 'package:git_touch/widgets/action_button.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';
|
2019-10-06 15:27:00 +02:00
|
|
|
import 'package:git_touch/widgets/entry_item.dart';
|
2022-09-13 19:19:52 +02:00
|
|
|
import 'package:git_touch/widgets/mutation_button.dart';
|
2019-12-06 14:51:33 +01:00
|
|
|
import 'package:git_touch/widgets/repository_item.dart';
|
2020-10-04 16:20:21 +02:00
|
|
|
import 'package:git_touch/widgets/text_with_at.dart';
|
2020-01-29 06:45:22 +01:00
|
|
|
import 'package:git_touch/widgets/user_header.dart';
|
2022-09-20 20:00:03 +02:00
|
|
|
import 'package:go_router/go_router.dart';
|
2019-09-08 14:07:35 +02:00
|
|
|
import 'package:provider/provider.dart';
|
2019-01-27 17:37:44 +01:00
|
|
|
|
2021-01-17 15:08:32 +01:00
|
|
|
class _Repos extends StatelessWidget {
|
2022-09-18 10:21:35 +02:00
|
|
|
_Repos(final Iterable<GRepoParts> pinned, final Iterable<GRepoParts>? repos)
|
2021-01-17 15:08:32 +01:00
|
|
|
: title =
|
|
|
|
pinned.isNotEmpty ? 'pinned repositories' : 'popular repositories',
|
|
|
|
repos = pinned.isNotEmpty ? pinned : repos;
|
2022-09-21 18:28:21 +02:00
|
|
|
final String title;
|
|
|
|
final Iterable<GRepoParts>? repos;
|
2019-12-06 14:51:33 +01:00
|
|
|
|
2021-01-17 15:08:32 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-09-23 19:49:27 +02:00
|
|
|
return AntList(
|
|
|
|
header: Text(title),
|
2022-09-25 17:11:23 +02:00
|
|
|
mode: AntListMode.card,
|
2021-01-17 15:08:32 +01:00
|
|
|
children: [
|
2022-09-25 17:11:23 +02:00
|
|
|
for (final v in repos!) RepositoryItem.gql(v),
|
2021-01-17 15:08:32 +01:00
|
|
|
],
|
|
|
|
);
|
2019-12-06 14:51:33 +01:00
|
|
|
}
|
2021-01-17 15:08:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class _User extends StatelessWidget {
|
2022-09-21 18:28:21 +02:00
|
|
|
const _User(this.p, {this.isViewer = false, this.rightWidgets = const []});
|
2022-09-24 07:22:07 +02:00
|
|
|
final GUserPartsFull p;
|
2021-01-17 15:08:32 +01:00
|
|
|
final bool isViewer;
|
2021-01-31 08:49:28 +01:00
|
|
|
final List<Widget> rightWidgets;
|
2019-12-06 14:51:33 +01:00
|
|
|
|
2021-01-17 15:08:32 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2019-12-06 14:51:33 +01:00
|
|
|
final theme = Provider.of<ThemeModel>(context);
|
2021-01-17 15:08:32 +01:00
|
|
|
|
2019-12-06 14:51:33 +01:00
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: <Widget>[
|
2020-01-29 06:45:22 +01:00
|
|
|
UserHeader(
|
2022-09-24 07:22:07 +02:00
|
|
|
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,
|
2021-01-31 08:49:28 +01:00
|
|
|
rightWidgets: rightWidgets,
|
2020-01-11 14:22:52 +01:00
|
|
|
),
|
2019-12-06 14:51:33 +01:00
|
|
|
CommonStyle.border,
|
2022-09-25 17:11:23 +02:00
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
EntryItem(
|
|
|
|
count: p.sponsors.totalCount,
|
|
|
|
text: 'Sponsors',
|
|
|
|
url: 'https://github.com/sponsors/${p.login}',
|
|
|
|
),
|
|
|
|
EntryItem(
|
|
|
|
count: p.followers.totalCount,
|
|
|
|
text: AppLocalizations.of(context)!.followers,
|
|
|
|
url: '/github/${p.login}?tab=followers',
|
|
|
|
),
|
|
|
|
EntryItem(
|
|
|
|
count: p.following.totalCount,
|
|
|
|
text: AppLocalizations.of(context)!.following,
|
|
|
|
url: '/github/${p.login}?tab=following',
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
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
|
2022-09-24 07:22:07 +02:00
|
|
|
in p.contributionsCollection.contributionCalendar.weeks)
|
2020-10-05 10:47:26 +02:00
|
|
|
[
|
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,
|
2022-09-20 20:00:03 +02:00
|
|
|
AntList(
|
2022-09-25 17:11:23 +02:00
|
|
|
mode: AntListMode.card,
|
2022-09-22 17:37:06 +02:00
|
|
|
children: [
|
2022-09-24 07:22:07 +02:00
|
|
|
if (isNotNullOrEmpty(p.company))
|
2022-09-20 20:00:03 +02:00
|
|
|
AntListItem(
|
|
|
|
prefix: const Icon(Octicons.organization),
|
2022-09-13 19:19:52 +02:00
|
|
|
child: TextWithAt(
|
2022-09-24 07:22:07 +02:00
|
|
|
text: p.company!,
|
2022-09-06 18:28:12 +02:00
|
|
|
linkFactory: (text) => '/github/${text.substring(1)}',
|
2022-09-24 20:46:37 +02:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 17, color: AntTheme.of(context).colorText),
|
2020-01-01 05:55:27 +01:00
|
|
|
oneLine: true,
|
2019-12-06 14:51:33 +01:00
|
|
|
),
|
|
|
|
),
|
2022-09-24 07:22:07 +02:00
|
|
|
if (isNotNullOrEmpty(p.location))
|
2022-09-20 20:00:03 +02:00
|
|
|
AntListItem(
|
|
|
|
prefix: const Icon(Octicons.location),
|
2022-09-24 07:22:07 +02:00
|
|
|
child: Text(p.location!),
|
2022-09-13 19:19:52 +02:00
|
|
|
onClick: () {
|
|
|
|
launchStringUrl(
|
2022-09-24 07:22:07 +02:00
|
|
|
'https://www.google.com/maps/place/${p.location!.replaceAll(RegExp(r'\s+'), '')}');
|
2019-12-06 14:51:33 +01:00
|
|
|
},
|
|
|
|
),
|
2022-09-24 07:22:07 +02:00
|
|
|
if (isNotNullOrEmpty(p.email))
|
2022-09-20 20:00:03 +02:00
|
|
|
AntListItem(
|
|
|
|
prefix: const Icon(Octicons.mail),
|
2022-09-24 07:22:07 +02:00
|
|
|
child: Text(p.email),
|
2022-09-13 19:19:52 +02:00
|
|
|
onClick: () {
|
2022-09-24 07:22:07 +02:00
|
|
|
launchStringUrl('mailto:${p.email}');
|
2019-12-06 14:51:33 +01:00
|
|
|
},
|
|
|
|
),
|
2022-09-24 07:22:07 +02:00
|
|
|
if (isNotNullOrEmpty(p.websiteUrl))
|
2022-09-20 20:00:03 +02:00
|
|
|
AntListItem(
|
|
|
|
prefix: const Icon(Octicons.link),
|
2022-09-24 07:22:07 +02:00
|
|
|
child: Text(p.websiteUrl!),
|
2022-09-13 19:19:52 +02:00
|
|
|
onClick: () {
|
2022-09-24 07:22:07 +02:00
|
|
|
var url = p.websiteUrl!;
|
2019-12-06 14:51:33 +01:00
|
|
|
if (!url.startsWith('http')) {
|
|
|
|
url = 'http://$url';
|
|
|
|
}
|
2022-06-26 08:23:50 +02:00
|
|
|
launchStringUrl(url);
|
2019-12-06 14:51:33 +01:00
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2020-01-01 09:35:50 +01:00
|
|
|
CommonStyle.verticalGap,
|
2022-09-25 17:11:23 +02:00
|
|
|
AntList(
|
|
|
|
mode: AntListMode.card,
|
|
|
|
children: [
|
|
|
|
AntListItem(
|
|
|
|
prefix: const Icon(Octicons.organization),
|
|
|
|
extra: Text(p.organizations.totalCount.toString()),
|
|
|
|
onClick: () {
|
|
|
|
context.push('/github/${p.login}?tab=organizations');
|
|
|
|
},
|
|
|
|
child: Text(AppLocalizations.of(context)!.organizations),
|
|
|
|
),
|
|
|
|
AntListItem(
|
|
|
|
prefix: const Icon(Octicons.repo),
|
|
|
|
extra: Text(p.repositories.totalCount.toString()),
|
|
|
|
onClick: () {
|
|
|
|
context.pushUrl('/github/${p.login}?tab=repositories');
|
|
|
|
},
|
|
|
|
child: Text(AppLocalizations.of(context)!.repositories),
|
|
|
|
),
|
|
|
|
AntListItem(
|
|
|
|
prefix: const Icon(Octicons.star),
|
|
|
|
extra: Text(p.starredRepositories.totalCount.toString()),
|
|
|
|
onClick: () {
|
|
|
|
context.pushUrl('/github/${p.login}?tab=stars');
|
|
|
|
},
|
|
|
|
child: Text(AppLocalizations.of(context)!.stars),
|
|
|
|
),
|
|
|
|
AntListItem(
|
|
|
|
prefix: const Icon(Octicons.book),
|
|
|
|
extra: Text(p.gists.totalCount.toString()),
|
|
|
|
child: Text(AppLocalizations.of(context)!.gists),
|
|
|
|
onClick: () {
|
|
|
|
context.push('/github/${p.login}?tab=gists');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
AntListItem(
|
|
|
|
prefix: const Icon(Octicons.rss),
|
|
|
|
child: Text(AppLocalizations.of(context)!.events),
|
|
|
|
onClick: () {
|
|
|
|
context.push('/github/${p.login}?tab=events');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
CommonStyle.verticalGap,
|
2021-01-17 15:08:32 +01:00
|
|
|
_Repos(
|
2022-09-24 07:22:07 +02:00
|
|
|
p.pinnedItems.nodes!.whereType<GRepoParts>(),
|
|
|
|
p.repositories.nodes,
|
2021-01-17 15:08:32 +01:00
|
|
|
),
|
2019-12-06 14:51:33 +01:00
|
|
|
CommonStyle.verticalGap,
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
2021-01-17 15:08:32 +01:00
|
|
|
}
|
|
|
|
|
2022-09-24 07:22:07 +02:00
|
|
|
class GhViewerScreen extends StatelessWidget {
|
|
|
|
const GhViewerScreen({super.key});
|
|
|
|
|
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);
|
2022-09-18 10:21:35 +02:00
|
|
|
return RefreshStatefulScaffold<GUserPartsFull?>(
|
2020-10-06 14:52:40 +02:00
|
|
|
fetch: () async {
|
2021-01-17 15:08:32 +01:00
|
|
|
final req = GViewerReq();
|
2022-09-24 07:22:07 +02:00
|
|
|
final res = await auth.gqlClient.request(req).first;
|
|
|
|
return res.data?.viewer;
|
2019-03-07 14:10:52 +01:00
|
|
|
},
|
2021-05-16 09:16:35 +02:00
|
|
|
title: AppBarTitle(AppLocalizations.of(context)!.me),
|
2022-09-06 18:28:12 +02:00
|
|
|
action: const ActionEntry(
|
2021-02-14 15:17:22 +01:00
|
|
|
iconData: Ionicons.cog,
|
2021-01-17 15:08:32 +01:00
|
|
|
url: '/settings',
|
|
|
|
),
|
2021-01-31 08:49:28 +01:00
|
|
|
bodyBuilder: (p, _) {
|
2022-09-24 07:22:07 +02:00
|
|
|
if (p == null) return null;
|
2021-01-17 15:08:32 +01:00
|
|
|
return _User(p, isViewer: true);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-24 07:22:07 +02:00
|
|
|
class GhUserScreen extends StatelessWidget {
|
|
|
|
const GhUserScreen(this.login, {super.key});
|
2022-09-21 18:28:21 +02:00
|
|
|
final String login;
|
2021-01-17 15:08:32 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final auth = Provider.of<AuthModel>(context);
|
2021-05-16 09:16:35 +02:00
|
|
|
return RefreshStatefulScaffold<GUserData?>(
|
2021-01-17 15:08:32 +01:00
|
|
|
fetch: () async {
|
|
|
|
final req = GUserReq((b) => b..vars.login = login);
|
2022-09-24 07:22:07 +02:00
|
|
|
final res = await auth.gqlClient.request(req).first;
|
2021-01-17 15:08:32 +01:00
|
|
|
return res.data;
|
|
|
|
},
|
|
|
|
title: AppBarTitle(login),
|
2021-01-31 08:49:28 +01:00
|
|
|
actionBuilder: (payload, _) {
|
2022-09-24 07:22:07 +02:00
|
|
|
final url = payload?.user?.url ?? payload?.organization?.url;
|
|
|
|
if (url == null) return null;
|
|
|
|
|
2021-01-17 15:08:32 +01:00
|
|
|
return ActionButton(
|
|
|
|
title: 'User Actions',
|
2022-09-24 07:22:07 +02:00
|
|
|
items: ActionItem.getUrlActions(url),
|
2021-01-17 15:08:32 +01:00
|
|
|
);
|
|
|
|
},
|
2021-01-31 08:49:28 +01:00
|
|
|
bodyBuilder: (data, setData) {
|
2022-09-24 07:22:07 +02:00
|
|
|
if (data?.user != null) {
|
|
|
|
final p = data!.user!;
|
2021-01-31 08:49:28 +01:00
|
|
|
return _User(
|
|
|
|
p,
|
|
|
|
rightWidgets: [
|
|
|
|
if (p.viewerCanFollow)
|
|
|
|
MutationButton(
|
|
|
|
active: p.viewerIsFollowing,
|
2021-05-30 19:07:31 +02:00
|
|
|
text: p.viewerIsFollowing
|
|
|
|
? AppLocalizations.of(context)!.unfollow
|
2021-05-16 09:16:35 +02:00
|
|
|
: AppLocalizations.of(context)!.follow,
|
2021-01-31 08:49:28 +01:00
|
|
|
onTap: () async {
|
|
|
|
if (p.viewerIsFollowing) {
|
2021-06-14 08:56:42 +02:00
|
|
|
await auth.ghClient.users.unfollowUser(p.login);
|
2021-01-31 08:49:28 +01:00
|
|
|
} else {
|
2021-06-14 08:56:42 +02:00
|
|
|
await auth.ghClient.users.followUser(p.login);
|
2021-01-31 08:49:28 +01:00
|
|
|
}
|
|
|
|
setData(data.rebuild((b) {
|
2022-09-24 07:22:07 +02:00
|
|
|
b.user.viewerIsFollowing = !b.user.viewerIsFollowing!;
|
2021-01-31 08:49:28 +01:00
|
|
|
}));
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
2022-09-24 07:22:07 +02:00
|
|
|
} else if (data?.organization != null) {
|
2022-09-25 19:26:52 +02:00
|
|
|
final p = data!.organization!;
|
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: <Widget>[
|
|
|
|
UserHeader(
|
|
|
|
avatarUrl: p.avatarUrl,
|
|
|
|
name: p.name,
|
|
|
|
login: p.login,
|
|
|
|
createdAt: p.createdAt,
|
|
|
|
bio: p.description,
|
|
|
|
rightWidgets: [
|
|
|
|
MutationButton(
|
|
|
|
active: p.viewerIsFollowing,
|
|
|
|
text: p.viewerIsFollowing
|
|
|
|
? AppLocalizations.of(context)!.unfollow
|
|
|
|
: AppLocalizations.of(context)!.follow,
|
|
|
|
onTap: () async {
|
|
|
|
if (p.viewerIsFollowing) {
|
|
|
|
await auth.ghClient.users.unfollowUser(p.login);
|
|
|
|
} else {
|
|
|
|
await auth.ghClient.users.followUser(p.login);
|
|
|
|
}
|
|
|
|
setData(data.rebuild((b) {
|
|
|
|
b.organization.viewerIsFollowing =
|
|
|
|
!b.organization.viewerIsFollowing!;
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
CommonStyle.border,
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
EntryItem(
|
|
|
|
count: p.sponsors.totalCount,
|
|
|
|
text: 'Sponsors',
|
|
|
|
url: 'https://github.com/sponsors/${p.login}',
|
|
|
|
),
|
|
|
|
EntryItem(
|
|
|
|
count: p.membersWithRole.totalCount,
|
|
|
|
text: AppLocalizations.of(context)!.members,
|
|
|
|
url: '/github/${p.login}?tab=people',
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
AntList(mode: AntListMode.card, children: [
|
|
|
|
if (isNotNullOrEmpty(p.location))
|
|
|
|
AntListItem(
|
|
|
|
prefix: const Icon(Octicons.location),
|
|
|
|
child: Text(p.location!),
|
|
|
|
onClick: () {
|
|
|
|
launchStringUrl(
|
|
|
|
'https://www.google.com/maps/place/${p.location!.replaceAll(RegExp(r'\s+'), '')}');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
if (isNotNullOrEmpty(p.email))
|
|
|
|
AntListItem(
|
|
|
|
prefix: const Icon(Octicons.mail),
|
|
|
|
child: Text(p.email!),
|
|
|
|
onClick: () {
|
|
|
|
launchStringUrl('mailto:${p.email!}');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
if (isNotNullOrEmpty(p.websiteUrl))
|
|
|
|
AntListItem(
|
|
|
|
prefix: const Icon(Octicons.link),
|
|
|
|
child: Text(p.websiteUrl!),
|
|
|
|
onClick: () {
|
|
|
|
var url = p.websiteUrl!;
|
|
|
|
if (!url.startsWith('http')) {
|
|
|
|
url = 'http://$url';
|
|
|
|
}
|
|
|
|
launchStringUrl(url);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
AntList(
|
|
|
|
mode: AntListMode.card,
|
|
|
|
children: [
|
|
|
|
AntListItem(
|
|
|
|
prefix: const Icon(Octicons.repo),
|
|
|
|
extra: Text(p.pinnableItems.totalCount.toString()),
|
|
|
|
child: Text(AppLocalizations.of(context)!.repositories),
|
|
|
|
onClick: () {
|
|
|
|
context.pushUrl('/github/${p.login}?tab=repositories');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
AntListItem(
|
|
|
|
prefix: const Icon(Octicons.rss),
|
|
|
|
child: Text(AppLocalizations.of(context)!.events),
|
|
|
|
onClick: () {
|
|
|
|
context.push('/github/${p.login}?tab=events');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
CommonStyle.verticalGap,
|
|
|
|
_Repos(
|
|
|
|
p.pinnedItems.nodes!.whereType<GRepoParts>(),
|
|
|
|
p.pinnableItems.nodes!.whereType<GRepoParts>(),
|
|
|
|
),
|
|
|
|
CommonStyle.verticalGap,
|
|
|
|
],
|
|
|
|
);
|
2019-12-06 14:51:33 +01:00
|
|
|
}
|
2022-09-24 07:22:07 +02:00
|
|
|
return null; // TODO: not found
|
2019-02-03 16:10:10 +01:00
|
|
|
},
|
2019-02-03 08:50:17 +01:00
|
|
|
);
|
2019-01-25 13:35:20 +01:00
|
|
|
}
|
|
|
|
}
|