1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-15 17:59:35 +01:00

feat(gitea): add repo count in org screen

This commit is contained in:
Rongjian Zhang 2020-10-06 12:05:51 +08:00
parent 2a1b9fe08d
commit f9351533c7

View File

@ -13,11 +13,13 @@ import 'package:provider/provider.dart';
import 'package:timeago/timeago.dart' as timeago; import 'package:timeago/timeago.dart' as timeago;
class GtUserScreenPayload { class GtUserScreenPayload {
GiteaOrg org;
List<GiteaRepository> orgRepos;
int orgRepoCount;
GiteaUser user; GiteaUser user;
List<GiteaRepository> userRepos; List<GiteaRepository> userRepos;
int userRepoCount; int userRepoCount;
List<List<ContributionDay>> userHeatmap; List<List<ContributionDay>> userHeatmap;
GiteaOrg org;
} }
class GtUserScreen extends StatelessWidget { class GtUserScreen extends StatelessWidget {
@ -56,7 +58,7 @@ class GtUserScreen extends StatelessWidget {
final auth = context.read<AuthModel>(); final auth = context.read<AuthModel>();
final res = await Future.wait([ final res = await Future.wait([
auth.fetchGitea('/orgs/$login'), auth.fetchGitea('/orgs/$login'),
auth.fetchGitea('/orgs/$login/repos'), auth.fetchGiteaWithPage('/orgs/$login/repos', limit: 6),
auth.fetchGitea(isViewer ? '/user' : '/users/$login'), auth.fetchGitea(isViewer ? '/user' : '/users/$login'),
auth.fetchGiteaWithPage( auth.fetchGiteaWithPage(
isViewer ? '/user/repos' : '/users/$login/repos', isViewer ? '/user/repos' : '/users/$login/repos',
@ -70,14 +72,19 @@ class GtUserScreen extends StatelessWidget {
if (org['message'] == null) { if (org['message'] == null) {
// org // org
payload.org = GiteaOrg.fromJson(org); payload.org = GiteaOrg.fromJson(org);
final orgReposData = res[3] as DataWithPage;
payload.orgRepos = [
for (var v in orgReposData.data) GiteaRepository.fromJson(v)
];
payload.orgRepoCount = orgReposData.total;
} else { } else {
// user // user
payload.user = GiteaUser.fromJson(res[2]); payload.user = GiteaUser.fromJson(res[2]);
final userRepos = res[3] as DataWithPage; final userRepoData = res[3] as DataWithPage;
payload.userRepos = [ payload.userRepos = [
for (var v in userRepos.data) GiteaRepository.fromJson(v) for (var v in userRepoData.data) GiteaRepository.fromJson(v)
]; ];
payload.userRepoCount = userRepos.total; payload.userRepoCount = userRepoData.total;
payload.userHeatmap = normalizeHeatmap(res[4]); payload.userHeatmap = normalizeHeatmap(res[4]);
} }
return payload; return payload;
@ -152,6 +159,7 @@ class GtUserScreen extends StatelessWidget {
CommonStyle.border, CommonStyle.border,
Row(children: [ Row(children: [
EntryItem( EntryItem(
count: p.orgRepoCount,
text: 'Repositories', text: 'Repositories',
url: '/gitea/$login?tab=orgrepo', url: '/gitea/$login?tab=orgrepo',
), ),
@ -161,6 +169,23 @@ class GtUserScreen extends StatelessWidget {
), ),
]), ]),
CommonStyle.border, CommonStyle.border,
CommonStyle.border,
Column(
children: <Widget>[
for (var v in p.orgRepos)
RepositoryItem(
owner: v.owner.login,
avatarUrl: v.owner.avatarUrl,
name: v.name,
description: v.description,
starCount: v.starsCount,
forkCount: v.forksCount,
note: 'Updated ${timeago.format(v.updatedAt)}',
url: '/gitea/${v.owner.login}/${v.name}',
avatarLink: '/gitea/${v.owner.login}',
)
],
)
], ],
); );
} else { } else {