improvement: tweak entries

This commit is contained in:
Rongjian Zhang 2020-01-01 20:59:20 +08:00
parent b5933dd895
commit 12d542c4f3
7 changed files with 67 additions and 88 deletions

View File

@ -77,7 +77,7 @@ class GithubRepositoryRepository extends GithubRepositoryPinnableItem
bool viewerHasStarred;
@override
String projectsResourcePath;
String projectsUrl;
GithubRepositoryUserConnection watchers;
@ -123,7 +123,7 @@ class GithubRepositoryRepository extends GithubRepositoryPinnableItem
hasIssuesEnabled,
url,
viewerHasStarred,
projectsResourcePath,
projectsUrl,
watchers,
issues,
pullRequests,
@ -608,7 +608,7 @@ class GithubRepositoryProjectOwner with EquatableMixin {
String id;
String projectsResourcePath;
String projectsUrl;
GithubRepositoryProjectConnection projects;
@ -616,7 +616,7 @@ class GithubRepositoryProjectOwner with EquatableMixin {
String resolveType;
@override
List<Object> get props => [id, projectsResourcePath, projects, resolveType];
List<Object> get props => [id, projectsUrl, projects, resolveType];
Map<String, dynamic> toJson() => _$GithubRepositoryProjectOwnerToJson(this);
}
@ -904,7 +904,7 @@ class GithubRepositoryQuery
directives: [],
selectionSet: null),
FieldNode(
name: NameNode(value: 'projectsResourcePath'),
name: NameNode(value: 'projectsUrl'),
alias: null,
arguments: [],
directives: [],

View File

@ -48,7 +48,7 @@ GithubRepositoryRepository _$GithubRepositoryRepositoryFromJson(
..hasIssuesEnabled = json['hasIssuesEnabled'] as bool
..url = json['url'] as String
..viewerHasStarred = json['viewerHasStarred'] as bool
..projectsResourcePath = json['projectsResourcePath'] as String
..projectsUrl = json['projectsUrl'] as String
..watchers = json['watchers'] == null
? null
: GithubRepositoryUserConnection.fromJson(
@ -91,7 +91,7 @@ Map<String, dynamic> _$GithubRepositoryRepositoryToJson(
'hasIssuesEnabled': instance.hasIssuesEnabled,
'url': instance.url,
'viewerHasStarred': instance.viewerHasStarred,
'projectsResourcePath': instance.projectsResourcePath,
'projectsUrl': instance.projectsUrl,
'watchers': instance.watchers?.toJson(),
'issues': instance.issues?.toJson(),
'pullRequests': instance.pullRequests?.toJson(),
@ -471,7 +471,7 @@ GithubRepositoryProjectOwner _$GithubRepositoryProjectOwnerFromJson(
Map<String, dynamic> json) {
return GithubRepositoryProjectOwner()
..id = json['id'] as String
..projectsResourcePath = json['projectsResourcePath'] as String
..projectsUrl = json['projectsUrl'] as String
..projects = json['projects'] == null
? null
: GithubRepositoryProjectConnection.fromJson(
@ -483,7 +483,7 @@ Map<String, dynamic> _$GithubRepositoryProjectOwnerToJson(
GithubRepositoryProjectOwner instance) =>
<String, dynamic>{
'id': instance.id,
'projectsResourcePath': instance.projectsResourcePath,
'projectsUrl': instance.projectsUrl,
'projects': instance.projects?.toJson(),
'__typename': instance.resolveType,
};

View File

@ -31,7 +31,7 @@ query(
url
viewerHasStarred
# viewerSubscription # TODO
projectsResourcePath
projectsUrl
watchers {
totalCount
}

View File

@ -382,7 +382,7 @@ class ThemeModel with ChangeNotifier {
);
if (value != null) {
actionItems[value].onPress(context);
actionItems[value].onTap(context);
}
}
}

View File

@ -72,24 +72,11 @@ class RepositoryScreen extends StatelessWidget {
},
actionBuilder: (data, setState) {
final repo = data.item1;
final ref = branch == null ? repo.defaultBranchRef : repo.ref;
return ActionButton(
title: 'Repository Actions',
items: [
ActionItem(
text: repo.viewerHasStarred ? 'Unstar' : 'Star',
onPress: (_) async {
if (repo.viewerHasStarred) {
await Provider.of<AuthModel>(context)
.deleteWithCredentials('/user/starred/$owner/$name');
repo.viewerHasStarred = false;
} else {
await Provider.of<AuthModel>(context)
.putWithCredentials('/user/starred/$owner/$name');
repo.viewerHasStarred = true;
}
setState(() {});
},
),
// TODO:
// ActionItem(
// text: data[0]['viewerSubscription'] == 'SUBSCRIBED'
@ -108,12 +95,25 @@ class RepositoryScreen extends StatelessWidget {
// setState(() {});
// },
// ),
ActionItem(
text:
'Commits (${(ref.target as GithubRepositoryCommit).history?.totalCount})',
url: '/$owner/$name/commits',
),
ActionItem(
text: 'Projects (${repo.projects.totalCount})',
url: repo.projectsUrl,
),
ActionItem(
text: 'Releases (${repo.releases.totalCount})',
url: 'https://github.com/$owner/$name/releases',
),
ActionItem.share(repo.url),
ActionItem.launch(repo.url),
],
);
},
bodyBuilder: (data, _) {
bodyBuilder: (data, setState) {
final repo = data.item1;
final readme = data.item2;
final ref = branch == null ? repo.defaultBranchRef : repo.ref;
@ -150,6 +150,33 @@ class RepositoryScreen extends StatelessWidget {
color: theme.palette.primary,
),
),
Expanded(child: Container()),
CupertinoButton(
onPressed: () async {
if (repo.viewerHasStarred) {
await Provider.of<AuthModel>(context)
.deleteWithCredentials(
'/user/starred/$owner/$name');
repo.viewerHasStarred = false;
} else {
await Provider.of<AuthModel>(context)
.putWithCredentials(
'/user/starred/$owner/$name');
repo.viewerHasStarred = true;
}
setState(() {});
},
borderRadius: BorderRadius.circular(10),
padding: EdgeInsets.symmetric(horizontal: 10),
child: Row(
children: <Widget>[
Icon(Octicons.star, size: 15),
SizedBox(width: 2),
Text(repo.viewerHasStarred ? 'Unstar' : 'Star',
style: TextStyle(fontSize: 15)),
],
),
)
],
),
if (repo.description != null && repo.description.isNotEmpty)
@ -309,32 +336,7 @@ class RepositoryScreen extends StatelessWidget {
Text(numberFormat.format(repo.pullRequests.totalCount)),
url: '/$owner/$name/pulls',
),
TableViewItem(
leftIconData: Octicons.project,
text: Text('Projects'),
rightWidget:
Text(numberFormat.format(repo.projects.totalCount)),
url: 'https://github.com' + repo.projectsResourcePath,
),
],
),
CommonStyle.verticalGap,
TableView(
hasIcon: true,
items: [
if (ref != null) ...[
TableViewItem(
leftIconData: Octicons.history,
text: Text('Commits'),
rightWidget: Text(
numberFormat.format(
(ref.target as GithubRepositoryCommit)
.history
?.totalCount,
),
),
url: '/$owner/$name/commits',
),
if (repo.refs != null)
TableViewItem(
leftIconData: Octicons.git_branch,
@ -365,12 +367,6 @@ class RepositoryScreen extends StatelessWidget {
},
),
],
TableViewItem(
leftIconData: Octicons.tag,
text: Text('Releases'),
rightWidget: Text(repo.releases.totalCount.toString()),
url: repo.url + '/releases',
),
],
),
CommonStyle.verticalGap,

View File

@ -369,7 +369,7 @@ class UserScreen extends StatelessWidget {
if (user.viewerCanFollow)
ActionItem(
text: user.viewerIsFollowing ? 'Unfollow' : 'Follow',
onPress: (_) async {
onTap: (_) async {
if (user.viewerIsFollowing) {
await Provider.of<AuthModel>(context)
.deleteWithCredentials(

View File

@ -7,47 +7,27 @@ import 'package:share/share.dart';
class ActionItem {
String text;
void Function(BuildContext context) onPress;
String url;
void Function(BuildContext context) onTap;
IconData iconData;
ActionItem({
@required this.text,
@required this.onPress,
this.onTap,
this.url,
this.iconData,
});
ActionItem.share(String url)
: text = 'Share',
onPress = ((_) {
onTap = ((_) {
Share.share(url);
});
ActionItem.launch(String url)
: text = 'Open in Browser',
onPress = ((_) {
onTap = ((_) {
launchUrl(url);
});
ActionItem.user(String login)
: text = '@$login',
onPress = ((context) {
Provider.of<ThemeModel>(context).push(context, '/$login');
});
ActionItem.repository(String owner, String name)
: text = '$owner/$name',
onPress = ((context) {
Provider.of<ThemeModel>(context).push(context, '/$owner/$name');
});
ActionItem.issue(String owner, String name, int number)
: text = '$owner/$name #$number',
onPress = ((context) {
Provider.of<ThemeModel>(context)
.push(context, '/$owner/$name/issues/$number');
});
ActionItem.pullRequest(String owner, String name, int number)
: text = '$owner/$name #$number',
onPress = ((context) {
Provider.of<ThemeModel>(context)
.push(context, '/$owner/$name/pulls/$number');
});
}
class ActionButton extends StatelessWidget {
@ -65,7 +45,8 @@ class ActionButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
switch (Provider.of<ThemeModel>(context).theme) {
final theme = Provider.of<ThemeModel>(context);
switch (theme.theme) {
case AppThemeType.cupertino:
return GestureDetector(
child: Icon(iconData, size: 22),
@ -101,7 +82,9 @@ class ActionButton extends StatelessWidget {
);
if (value != null) {
items[value].onPress(context);
if (items[value].onTap != null) items[value].onTap(context);
if (items[value].url != null)
theme.push(context, items[value].url);
}
},
);
@ -118,7 +101,7 @@ class ActionButton extends StatelessWidget {
}).toList();
},
onSelected: (value) {
items[value].onPress(context);
items[value].onTap(context);
},
);
}