refactor: remove organization option
This commit is contained in:
parent
bbb0bab1bf
commit
f034e4c8ce
|
@ -136,10 +136,7 @@ class _SearchScreenState extends State<SearchScreen> {
|
||||||
case 0:
|
case 0:
|
||||||
return RepositoryItem(data);
|
return RepositoryItem(data);
|
||||||
case 1:
|
case 1:
|
||||||
return UserItem.fromData(
|
return UserItem.fromData(data);
|
||||||
data,
|
|
||||||
isOrganization: data['__typename'] == 'Organization',
|
|
||||||
);
|
|
||||||
case 2:
|
case 2:
|
||||||
default:
|
default:
|
||||||
return IssueItem(
|
return IssueItem(
|
||||||
|
|
|
@ -22,89 +22,83 @@ import 'package:primer/primer.dart';
|
||||||
|
|
||||||
class UserScreen extends StatelessWidget {
|
class UserScreen extends StatelessWidget {
|
||||||
final String login;
|
final String login;
|
||||||
final bool isOrganization;
|
|
||||||
|
|
||||||
UserScreen(this.login, {this.isOrganization = false});
|
UserScreen(this.login);
|
||||||
|
|
||||||
Future queryUser(BuildContext context) async {
|
Future _query(BuildContext context) async {
|
||||||
var _login = login ?? Provider.of<AuthModel>(context).activeAccount.login;
|
var _login = login ?? Provider.of<AuthModel>(context).activeAccount.login;
|
||||||
var data = await Provider.of<AuthModel>(context).query('''
|
var data = await Provider.of<AuthModel>(context).query('''
|
||||||
{
|
{
|
||||||
user(login: "$_login") {
|
repositoryOwner(login: "$_login") {
|
||||||
$userGqlChunk
|
__typename
|
||||||
company
|
... on User {
|
||||||
location
|
$userGqlChunk
|
||||||
email
|
company
|
||||||
websiteUrl
|
location
|
||||||
starredRepositories {
|
email
|
||||||
totalCount
|
websiteUrl
|
||||||
}
|
starredRepositories {
|
||||||
followers {
|
totalCount
|
||||||
totalCount
|
|
||||||
}
|
|
||||||
following {
|
|
||||||
totalCount
|
|
||||||
}
|
|
||||||
repositories(first: 6, ownerAffiliations: OWNER, orderBy: {field: STARGAZERS, direction: DESC}) {
|
|
||||||
totalCount
|
|
||||||
nodes {
|
|
||||||
$repoChunk
|
|
||||||
}
|
}
|
||||||
}
|
followers {
|
||||||
pinnedItems(first: 6) {
|
totalCount
|
||||||
nodes {
|
}
|
||||||
... on Repository {
|
following {
|
||||||
|
totalCount
|
||||||
|
}
|
||||||
|
repositories(first: 6, ownerAffiliations: OWNER, orderBy: {field: STARGAZERS, direction: DESC}) {
|
||||||
|
totalCount
|
||||||
|
nodes {
|
||||||
$repoChunk
|
$repoChunk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
pinnedItems(first: 6) {
|
||||||
viewerCanFollow
|
nodes {
|
||||||
viewerIsFollowing
|
... on Repository {
|
||||||
url
|
$repoChunk
|
||||||
}
|
}
|
||||||
}
|
|
||||||
''');
|
|
||||||
return data['user'];
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
viewerCanFollow
|
||||||
|
viewerIsFollowing
|
||||||
|
url
|
||||||
}
|
}
|
||||||
pinnableItems(first: 6, types: [REPOSITORY]) {
|
... on Organization {
|
||||||
totalCount
|
login
|
||||||
nodes {
|
name
|
||||||
... on Repository {
|
avatarUrl
|
||||||
$repoChunk
|
description
|
||||||
|
location
|
||||||
|
email
|
||||||
|
websiteUrl
|
||||||
|
url
|
||||||
|
pinnedItems(first: 6) {
|
||||||
|
nodes {
|
||||||
|
... on Repository {
|
||||||
|
$repoChunk
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
pinnableItems(first: 6, types: [REPOSITORY]) {
|
||||||
membersWithRole {
|
totalCount
|
||||||
totalCount
|
nodes {
|
||||||
|
... on Repository {
|
||||||
|
$repoChunk
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
membersWithRole {
|
||||||
|
totalCount
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
''');
|
'''); // Use pinnableItems instead of organization here due to token permission
|
||||||
return data['organization'];
|
|
||||||
|
return data['repositoryOwner'];
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<ContributionsInfo>> fetchContributions(
|
Future<List<ContributionsInfo>> _fetchContributions(
|
||||||
BuildContext context) async {
|
BuildContext context) async {
|
||||||
var _login = login ?? Provider.of<AuthModel>(context).activeAccount.login;
|
var _login = login ?? Provider.of<AuthModel>(context).activeAccount.login;
|
||||||
switch (Provider.of<AuthModel>(context).activeAccount.platform) {
|
switch (Provider.of<AuthModel>(context).activeAccount.platform) {
|
||||||
|
@ -123,73 +117,78 @@ class UserScreen extends StatelessWidget {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return RefreshStatefulScaffold(
|
return RefreshStatefulScaffold(
|
||||||
fetchData: () {
|
fetchData: () {
|
||||||
return Future.wait(
|
return Future.wait([
|
||||||
isOrganization
|
_query(context),
|
||||||
? [
|
_fetchContributions(context),
|
||||||
queryOrganization(context),
|
]);
|
||||||
Future.value([].cast<ContributionsInfo>())
|
|
||||||
]
|
|
||||||
: [
|
|
||||||
queryUser(context),
|
|
||||||
fetchContributions(context),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
title: AppBarTitle(isOrganization ? 'Organization' : 'User'),
|
title: AppBarTitle('User'), // TODO:
|
||||||
actionBuilder: (payload) {
|
actionBuilder: (payload) {
|
||||||
var data = payload.data;
|
var data = payload.data;
|
||||||
|
if (data == null)
|
||||||
if (isOrganization) {
|
|
||||||
return ActionButton(
|
return ActionButton(
|
||||||
title: 'Organization Actions',
|
title: "Actions",
|
||||||
items: [
|
items: [],
|
||||||
if (data != null) ...[
|
|
||||||
ActionItem.share(payload.data[0]['url']),
|
|
||||||
ActionItem.launch(payload.data[0]['url']),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
if (login == null) {
|
switch (data[0]['__typename']) {
|
||||||
return ActionEntry(
|
case 'User':
|
||||||
iconData: Icons.settings,
|
if (login == null) {
|
||||||
onTap: () {
|
return ActionEntry(
|
||||||
Provider.of<ThemeModel>(context).pushRoute(
|
iconData: Icons.settings,
|
||||||
context, (_) => SettingsScreen(),
|
onTap: () {
|
||||||
fullscreenDialog: true);
|
Provider.of<ThemeModel>(context).pushRoute(
|
||||||
},
|
context, (_) => SettingsScreen(),
|
||||||
);
|
fullscreenDialog: true);
|
||||||
} else {
|
},
|
||||||
return ActionButton(
|
);
|
||||||
title: 'User Actions',
|
} else {
|
||||||
items: [
|
return ActionButton(
|
||||||
if (data != null && data[0]['viewerCanFollow'])
|
title: 'User Actions',
|
||||||
ActionItem(
|
items: [
|
||||||
text: data[0]['viewerIsFollowing'] ? 'Unfollow' : 'Follow',
|
if (data != null && data[0]['viewerCanFollow'])
|
||||||
onPress: () async {
|
ActionItem(
|
||||||
if (data[0]['viewerIsFollowing']) {
|
text:
|
||||||
await Provider.of<AuthModel>(context)
|
data[0]['viewerIsFollowing'] ? 'Unfollow' : 'Follow',
|
||||||
.deleteWithCredentials('/user/following/$login');
|
onPress: () async {
|
||||||
data[0]['viewerIsFollowing'] = false;
|
if (data[0]['viewerIsFollowing']) {
|
||||||
} else {
|
await Provider.of<AuthModel>(context)
|
||||||
Provider.of<AuthModel>(context)
|
.deleteWithCredentials('/user/following/$login');
|
||||||
.putWithCredentials('/user/following/$login');
|
data[0]['viewerIsFollowing'] = false;
|
||||||
data[0]['viewerIsFollowing'] = true;
|
} else {
|
||||||
}
|
Provider.of<AuthModel>(context)
|
||||||
},
|
.putWithCredentials('/user/following/$login');
|
||||||
),
|
data[0]['viewerIsFollowing'] = true;
|
||||||
if (data != null) ...[
|
}
|
||||||
ActionItem.share(data[0]['url']),
|
},
|
||||||
ActionItem.launch(data[0]['url']),
|
),
|
||||||
|
if (data != null) ...[
|
||||||
|
ActionItem.share(data[0]['url']),
|
||||||
|
ActionItem.launch(data[0]['url']),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'Organization':
|
||||||
|
return ActionButton(
|
||||||
|
title: 'Organization Actions',
|
||||||
|
items: [
|
||||||
|
if (data != null) ...[
|
||||||
|
ActionItem.share(payload.data[0]['url']),
|
||||||
|
ActionItem.launch(payload.data[0]['url']),
|
||||||
|
],
|
||||||
],
|
],
|
||||||
],
|
);
|
||||||
);
|
default:
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
bodyBuilder: (payload) {
|
bodyBuilder: (payload) {
|
||||||
var data = payload.data[0];
|
var data = payload.data[0];
|
||||||
var contributions = payload.data[1];
|
var contributions = payload.data[1];
|
||||||
|
final isOrganization = data['__typename'] == 'Organization';
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
|
|
|
@ -22,8 +22,8 @@ class TextContainsOrganization extends StatelessWidget {
|
||||||
if (chunks[index].isNotEmpty) {
|
if (chunks[index].isNotEmpty) {
|
||||||
spans.add(TextSpan(text: chunks[index]));
|
spans.add(TextSpan(text: chunks[index]));
|
||||||
}
|
}
|
||||||
spans.add(createLinkSpan(context, orgs[index],
|
spans.add(createLinkSpan(
|
||||||
(_) => UserScreen(orgs[index].substring(1), isOrganization: true)));
|
context, orgs[index], (_) => UserScreen(orgs[index].substring(1))));
|
||||||
}
|
}
|
||||||
if (chunks.last.isNotEmpty) {
|
if (chunks.last.isNotEmpty) {
|
||||||
spans.add(TextSpan(text: chunks.last));
|
spans.add(TextSpan(text: chunks.last));
|
||||||
|
|
|
@ -19,7 +19,6 @@ class UserItem extends StatelessWidget {
|
||||||
final String avatarUrl;
|
final String avatarUrl;
|
||||||
final String bio;
|
final String bio;
|
||||||
final bool inUserScreen;
|
final bool inUserScreen;
|
||||||
final bool isOrganization;
|
|
||||||
|
|
||||||
UserItem({
|
UserItem({
|
||||||
this.login,
|
this.login,
|
||||||
|
@ -27,11 +26,9 @@ class UserItem extends StatelessWidget {
|
||||||
this.avatarUrl,
|
this.avatarUrl,
|
||||||
this.bio,
|
this.bio,
|
||||||
this.inUserScreen = false,
|
this.inUserScreen = false,
|
||||||
this.isOrganization = false,
|
|
||||||
});
|
});
|
||||||
UserItem.fromData(
|
UserItem.fromData(
|
||||||
data, {
|
data, {
|
||||||
this.isOrganization = false,
|
|
||||||
this.inUserScreen = false,
|
this.inUserScreen = false,
|
||||||
}) : login = data['login'],
|
}) : login = data['login'],
|
||||||
name = data['name'],
|
name = data['name'],
|
||||||
|
@ -41,9 +38,7 @@ class UserItem extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Link(
|
return Link(
|
||||||
screenBuilder: inUserScreen
|
screenBuilder: inUserScreen ? null : (_) => UserScreen(login),
|
||||||
? null
|
|
||||||
: (_) => UserScreen(login, isOrganization: isOrganization),
|
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: CommonStyle.padding,
|
padding: CommonStyle.padding,
|
||||||
child: Row(
|
child: Row(
|
||||||
|
|
Loading…
Reference in New Issue