refactor: repo item params
This commit is contained in:
parent
984ec41fec
commit
61a5b3f786
|
@ -2,6 +2,7 @@ import 'package:flutter/widgets.dart';
|
|||
import 'package:git_touch/models/auth.dart';
|
||||
import 'package:git_touch/models/gitea.dart';
|
||||
import 'package:git_touch/scaffolds/refresh_stateful.dart';
|
||||
import 'package:git_touch/utils/utils.dart';
|
||||
import 'package:git_touch/widgets/border_view.dart';
|
||||
import 'package:git_touch/widgets/repository_item.dart';
|
||||
import 'package:git_touch/widgets/user_item.dart';
|
||||
|
@ -41,7 +42,17 @@ class GiteaUserScreen extends StatelessWidget {
|
|||
BorderView(height: 10),
|
||||
Column(
|
||||
children: repos.map((v) {
|
||||
return RepositoryItem.gitea(v);
|
||||
return RepositoryItem(
|
||||
v.owner.login,
|
||||
v.owner.avatarUrl,
|
||||
v.name,
|
||||
v.description,
|
||||
Octicons.repo,
|
||||
v.starsCount,
|
||||
v.forksCount,
|
||||
null,
|
||||
null,
|
||||
);
|
||||
}).toList(),
|
||||
)
|
||||
],
|
||||
|
|
|
@ -58,18 +58,17 @@ class GitlabProjectScreen extends StatelessWidget {
|
|||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
RepositoryItem.raw(
|
||||
data.namespace.name,
|
||||
data.avatarUrl,
|
||||
data.name,
|
||||
data.description,
|
||||
Octicons.repo, // TODO:
|
||||
data.starCount,
|
||||
data.forksCount,
|
||||
data.languages.keys.first,
|
||||
null,
|
||||
[],
|
||||
inRepoScreen: true),
|
||||
RepositoryItem(
|
||||
data.namespace.name,
|
||||
data.avatarUrl,
|
||||
data.name,
|
||||
data.description,
|
||||
Octicons.repo, // TODO:
|
||||
data.starCount,
|
||||
data.forksCount,
|
||||
data.languages.keys.first,
|
||||
null,
|
||||
),
|
||||
CommonStyle.border,
|
||||
Row(
|
||||
children: <Widget>[
|
||||
|
|
|
@ -19,6 +19,19 @@ class GitlabUserScreen extends StatelessWidget {
|
|||
|
||||
GitlabUserScreen(this.id);
|
||||
|
||||
static _getGitlabIcon(String visibility) {
|
||||
switch (visibility) {
|
||||
case 'internal':
|
||||
return FontAwesome.shield;
|
||||
case 'public':
|
||||
return FontAwesome.globe;
|
||||
case 'private':
|
||||
return FontAwesome.lock;
|
||||
default:
|
||||
return Octicons.repo;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RefreshStatefulScaffold<
|
||||
|
@ -48,7 +61,19 @@ class GitlabUserScreen extends StatelessWidget {
|
|||
),
|
||||
BorderView(height: 10),
|
||||
Column(
|
||||
children: projects.map((v) => RepositoryItem.gitlab(v)).toList(),
|
||||
children: projects.map((v) {
|
||||
return RepositoryItem(
|
||||
v.owner.name,
|
||||
v.owner.avatarUrl,
|
||||
v.name,
|
||||
v.description,
|
||||
_getGitlabIcon(v.visibility),
|
||||
v.starCount,
|
||||
v.forksCount,
|
||||
null,
|
||||
null,
|
||||
);
|
||||
}).toList(),
|
||||
)
|
||||
],
|
||||
);
|
||||
|
|
|
@ -62,7 +62,7 @@ class RepositoriesScreen extends StatelessWidget {
|
|||
onRefresh: () => _query(context),
|
||||
onLoadMore: (cursor) => _query(context, cursor),
|
||||
itemBuilder: (item) {
|
||||
return RepositoryItem.raw(
|
||||
return RepositoryItem(
|
||||
item.owner.login,
|
||||
item.owner.avatarUrl,
|
||||
item.name,
|
||||
|
@ -72,7 +72,6 @@ class RepositoriesScreen extends StatelessWidget {
|
|||
item.forks.totalCount,
|
||||
item.primaryLanguage?.name,
|
||||
item.primaryLanguage?.color,
|
||||
[],
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -50,7 +50,25 @@ class _SearchScreenState extends State<SearchScreen> {
|
|||
repository: search(first: $pageSize, type: REPOSITORY, query: "$keyword") {
|
||||
nodes {
|
||||
... on Repository {
|
||||
$repoChunk
|
||||
owner {
|
||||
__typename
|
||||
login
|
||||
avatarUrl
|
||||
}
|
||||
name
|
||||
description
|
||||
isPrivate
|
||||
isFork
|
||||
stargazers {
|
||||
totalCount
|
||||
}
|
||||
forks {
|
||||
totalCount
|
||||
}
|
||||
primaryLanguage {
|
||||
color
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -131,21 +149,41 @@ class _SearchScreenState extends State<SearchScreen> {
|
|||
|
||||
static const tabs = ['Repositories', 'Users', 'Issues'];
|
||||
|
||||
Widget _buildItem(data) {
|
||||
static IconData _buildIconData(p) {
|
||||
if (p['isPrivate']) {
|
||||
return Octicons.lock;
|
||||
}
|
||||
if (p['isFork']) {
|
||||
return Octicons.repo_forked;
|
||||
}
|
||||
return Octicons.repo;
|
||||
}
|
||||
|
||||
Widget _buildItem(p) {
|
||||
switch (_activeTab) {
|
||||
case 0:
|
||||
return RepositoryItem(data);
|
||||
return RepositoryItem(
|
||||
p['owner']['login'],
|
||||
p['owner']['avatarUrl'],
|
||||
p['name'],
|
||||
p['description'],
|
||||
_buildIconData(p),
|
||||
p['stargazers']['totalCount'],
|
||||
p['forks']['totalCount'],
|
||||
p['primaryLanguage'] == null ? null : p['primaryLanguage']['name'],
|
||||
p['primaryLanguage'] == null ? null : p['primaryLanguage']['color'],
|
||||
);
|
||||
case 1:
|
||||
return UserItem(
|
||||
login: data['login'],
|
||||
name: data['name'],
|
||||
avatarUrl: data['avatarUrl'],
|
||||
bio: Text(data['bio'] ?? ''),
|
||||
login: p['login'],
|
||||
name: p['name'],
|
||||
avatarUrl: p['avatarUrl'],
|
||||
bio: Text(p['bio'] ?? ''),
|
||||
);
|
||||
case 2:
|
||||
default:
|
||||
return IssueItem(
|
||||
payload: data, isPullRequest: data['__typename'] == 'PullRequest');
|
||||
payload: p, isPullRequest: p['__typename'] == 'PullRequest');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ class TrendingScreen extends StatelessWidget {
|
|||
switch (activeTab) {
|
||||
case 0:
|
||||
final item = GithubTrendingItem.fromJson(v);
|
||||
return RepositoryItem.raw(
|
||||
return RepositoryItem(
|
||||
item.author,
|
||||
item.avatar,
|
||||
item.name,
|
||||
|
@ -38,7 +38,6 @@ class TrendingScreen extends StatelessWidget {
|
|||
item.forks ?? 0,
|
||||
item.language,
|
||||
item.languageColor,
|
||||
[],
|
||||
);
|
||||
case 1:
|
||||
final item = GithubTrendingUser.fromJson(v);
|
||||
|
|
|
@ -63,8 +63,18 @@ class UserScreen extends StatelessWidget {
|
|||
if (title != null) TableViewHeader(title),
|
||||
...join(
|
||||
CommonStyle.border,
|
||||
items.map((item) {
|
||||
return RepositoryItem.github(item);
|
||||
items.map((v) {
|
||||
return RepositoryItem(
|
||||
v.owner.login,
|
||||
v.owner.avatarUrl,
|
||||
v.name,
|
||||
v.description,
|
||||
Octicons.repo, // TODO:
|
||||
v.stargazers.totalCount,
|
||||
v.forks.totalCount,
|
||||
v.primaryLanguage?.name,
|
||||
v.primaryLanguage?.color,
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
];
|
||||
|
|
|
@ -1,37 +1,11 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:git_touch/graphql/gh.dart'; // FIXME:
|
||||
import 'package:git_touch/models/gitea.dart';
|
||||
import 'package:git_touch/models/gitlab.dart';
|
||||
import 'package:git_touch/models/theme.dart';
|
||||
import 'package:git_touch/widgets/avatar.dart';
|
||||
import 'package:primer/primer.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../utils/utils.dart';
|
||||
import 'link.dart';
|
||||
|
||||
const repoChunk = '''
|
||||
owner {
|
||||
__typename
|
||||
login
|
||||
avatarUrl
|
||||
}
|
||||
name
|
||||
description
|
||||
isPrivate
|
||||
isFork
|
||||
stargazers {
|
||||
totalCount
|
||||
}
|
||||
forks {
|
||||
totalCount
|
||||
}
|
||||
primaryLanguage {
|
||||
color
|
||||
name
|
||||
}
|
||||
''';
|
||||
|
||||
class RepositoryItem extends StatelessWidget {
|
||||
final String owner;
|
||||
final String avatarUrl;
|
||||
|
@ -42,179 +16,75 @@ class RepositoryItem extends StatelessWidget {
|
|||
final int forkCount;
|
||||
final String primaryLanguageName;
|
||||
final String primaryLanguageColor;
|
||||
final bool inRepoScreen;
|
||||
final Iterable<GhRepoRepositoryTopic> topics;
|
||||
|
||||
RepositoryItem.raw(
|
||||
this.owner,
|
||||
this.avatarUrl,
|
||||
this.name,
|
||||
this.description,
|
||||
this.iconData,
|
||||
this.starCount,
|
||||
this.forkCount,
|
||||
this.primaryLanguageName,
|
||||
this.primaryLanguageColor,
|
||||
this.topics,
|
||||
{this.inRepoScreen = false});
|
||||
|
||||
RepositoryItem(payload, {this.inRepoScreen = false})
|
||||
: this.owner = payload['owner']['login'],
|
||||
this.avatarUrl = payload['owner']['avatarUrl'],
|
||||
this.name = payload['name'],
|
||||
this.description = payload['description'],
|
||||
this.iconData = _buildIconData(payload),
|
||||
this.starCount = payload['stargazers']['totalCount'],
|
||||
this.forkCount = payload['forks']['totalCount'],
|
||||
this.primaryLanguageName = payload['primaryLanguage'] == null
|
||||
? null
|
||||
: payload['primaryLanguage']['name'],
|
||||
this.primaryLanguageColor = payload['primaryLanguage'] == null
|
||||
? null
|
||||
: payload['primaryLanguage']['color'],
|
||||
this.topics = [];
|
||||
|
||||
RepositoryItem.github(GhUserRepository payload, {this.inRepoScreen = false})
|
||||
: this.owner = payload.owner.login,
|
||||
this.avatarUrl = payload.owner.avatarUrl,
|
||||
this.name = payload.name,
|
||||
this.description = payload.description,
|
||||
this.iconData = Octicons.repo, // TODO:
|
||||
this.starCount = payload.stargazers.totalCount,
|
||||
this.forkCount = payload.forks.totalCount,
|
||||
this.primaryLanguageName = payload.primaryLanguage?.name,
|
||||
this.primaryLanguageColor = payload.primaryLanguage?.color,
|
||||
this.topics = []; // TODO:
|
||||
// this.topics = payload['repositoryTopics'] == null
|
||||
// ? []
|
||||
// : payload['repositoryTopics']['nodes'];
|
||||
|
||||
static _getGitlabIcon(String visibility) {
|
||||
switch (visibility) {
|
||||
case 'internal':
|
||||
return FontAwesome.shield;
|
||||
case 'public':
|
||||
return FontAwesome.globe;
|
||||
case 'private':
|
||||
return FontAwesome.lock;
|
||||
default:
|
||||
return Octicons.repo;
|
||||
}
|
||||
}
|
||||
|
||||
RepositoryItem.gitlab(GitlabUserProject payload, {this.inRepoScreen = false})
|
||||
: this.owner = payload.owner.name,
|
||||
this.avatarUrl = payload.owner.avatarUrl,
|
||||
this.name = payload.name,
|
||||
this.description = payload.description,
|
||||
this.iconData = _getGitlabIcon(payload.visibility),
|
||||
this.starCount = payload.starCount,
|
||||
this.forkCount = payload.forksCount,
|
||||
this.primaryLanguageName = null,
|
||||
this.primaryLanguageColor = null,
|
||||
this.topics = [];
|
||||
|
||||
RepositoryItem.gitea(GiteaRepository payload, {this.inRepoScreen = false})
|
||||
: this.owner = payload.owner.login,
|
||||
this.avatarUrl = payload.owner.avatarUrl,
|
||||
this.name = payload.name,
|
||||
this.description = payload.description,
|
||||
this.iconData = Octicons.repo,
|
||||
this.starCount = payload.starsCount,
|
||||
this.forkCount = payload.forksCount,
|
||||
this.primaryLanguageName = null,
|
||||
this.primaryLanguageColor = null,
|
||||
this.topics = [];
|
||||
|
||||
static IconData _buildIconData(payload) {
|
||||
if (payload['isPrivate']) {
|
||||
return Octicons.lock;
|
||||
}
|
||||
if (payload['isFork']) {
|
||||
return Octicons.repo_forked;
|
||||
}
|
||||
return Octicons.repo;
|
||||
}
|
||||
RepositoryItem(
|
||||
this.owner,
|
||||
this.avatarUrl,
|
||||
this.name,
|
||||
this.description,
|
||||
this.iconData,
|
||||
this.starCount,
|
||||
this.forkCount,
|
||||
this.primaryLanguageName,
|
||||
this.primaryLanguageColor,
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Provider.of<ThemeModel>(context);
|
||||
|
||||
// TODO: text style inRepoScreen
|
||||
final widget = Container(
|
||||
padding: CommonStyle.padding,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Avatar(url: avatarUrl, size: AvatarSize.small, linkUrl: '/$owner'),
|
||||
SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: join(SizedBox(height: 8), <Widget>[
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Text(
|
||||
owner + ' / ',
|
||||
style: TextStyle(
|
||||
fontSize: 17,
|
||||
color: theme.palette.primary,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
name,
|
||||
return Link(
|
||||
url: '/$owner/$name',
|
||||
child: Container(
|
||||
padding: CommonStyle.padding,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Avatar(url: avatarUrl, size: AvatarSize.small, linkUrl: '/$owner'),
|
||||
SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: join(SizedBox(height: 8), <Widget>[
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Text(
|
||||
owner + ' / ',
|
||||
style: TextStyle(
|
||||
fontSize: 17,
|
||||
color: theme.palette.primary,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
Expanded(
|
||||
child: Text(
|
||||
name,
|
||||
style: TextStyle(
|
||||
fontSize: 17,
|
||||
color: theme.palette.primary,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Icon(iconData,
|
||||
size: 17, color: theme.palette.tertiaryText),
|
||||
],
|
||||
),
|
||||
if (description != null && description.isNotEmpty)
|
||||
Text(
|
||||
description,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
color: theme.palette.secondaryText,
|
||||
fontSize: 15,
|
||||
),
|
||||
),
|
||||
Icon(iconData, size: 17, color: theme.palette.tertiaryText),
|
||||
],
|
||||
),
|
||||
if (description != null && description.isNotEmpty)
|
||||
Text(
|
||||
description,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
color: theme.palette.secondaryText,
|
||||
fontSize: 15,
|
||||
),
|
||||
),
|
||||
if (topics != null && topics.isNotEmpty)
|
||||
// TODO: link
|
||||
Wrap(
|
||||
spacing: 4,
|
||||
runSpacing: 4,
|
||||
children: topics.map((node) {
|
||||
return Container(
|
||||
padding:
|
||||
EdgeInsets.symmetric(vertical: 4, horizontal: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: PrimerColors.blue000,
|
||||
borderRadius: BorderRadius.all(Radius.circular(4)),
|
||||
),
|
||||
child: Text(
|
||||
node.topic.name,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: theme.palette.primary,
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
if (!inRepoScreen)
|
||||
DefaultTextStyle(
|
||||
style: TextStyle(color: theme.palette.text, fontSize: 13),
|
||||
child: Row(
|
||||
|
@ -261,20 +131,12 @@ class RepositoryItem extends StatelessWidget {
|
|||
],
|
||||
),
|
||||
),
|
||||
]),
|
||||
]),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
if (inRepoScreen) {
|
||||
// return Material(child: InkWell(child: widget));
|
||||
return widget;
|
||||
} else {
|
||||
return Link(
|
||||
url: '/$owner/$name',
|
||||
child: widget,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue