feat(gl): add starrers screen

closes #48
This commit is contained in:
Rongjian Zhang 2020-04-06 14:48:50 +08:00
parent 57f2ab7967
commit f8f436a382
5 changed files with 74 additions and 0 deletions

View File

@ -201,3 +201,12 @@ class GitlabIssue {
factory GitlabIssue.fromJson(Map<String, dynamic> json) =>
_$GitlabIssueFromJson(json);
}
@JsonSerializable(fieldRename: FieldRename.snake)
class GitlabStarrer {
DateTime starredSince;
GitlabUser user;
GitlabStarrer();
factory GitlabStarrer.fromJson(Map<String, dynamic> json) =>
_$GitlabStarrerFromJson(json);
}

View File

@ -348,3 +348,19 @@ Map<String, dynamic> _$GitlabIssueToJson(GitlabIssue instance) =>
'updated_at': instance.updatedAt?.toIso8601String(),
'labels': instance.labels,
};
GitlabStarrer _$GitlabStarrerFromJson(Map<String, dynamic> json) {
return GitlabStarrer()
..starredSince = json['starred_since'] == null
? null
: DateTime.parse(json['starred_since'] as String)
..user = json['user'] == null
? null
: GitlabUser.fromJson(json['user'] as Map<String, dynamic>);
}
Map<String, dynamic> _$GitlabStarrerToJson(GitlabStarrer instance) =>
<String, dynamic>{
'starred_since': instance.starredSince?.toIso8601String(),
'user': instance.user,
};

View File

@ -7,6 +7,7 @@ import 'package:git_touch/screens/code_theme.dart';
import 'package:git_touch/screens/gh_commits.dart';
import 'package:git_touch/screens/gh_org_repos.dart';
import 'package:git_touch/screens/gl_commit.dart';
import 'package:git_touch/screens/gl_starrers.dart';
import 'package:git_touch/screens/gt_commits.dart';
import 'package:git_touch/screens/gt_issues.dart';
import 'package:git_touch/screens/gt_object.dart';
@ -144,6 +145,7 @@ class GitlabRouter {
GitlabRouter.blob,
GitlabRouter.tree,
GitlabRouter.project,
GitlabRouter.starrers,
GitlabRouter.issues,
GitlabRouter.mergeRequests,
GitlabRouter.commits,
@ -168,6 +170,8 @@ class GitlabRouter {
path: params['path']?.first));
static final project = RouterScreen('/projects/:id',
(context, params) => GlProjectScreen(int.parse(params['id'].first)));
static final starrers = RouterScreen('/projects/:id/starrers',
(context, params) => GlStarrersScreen(int.parse(params['id'].first)));
static final issues = RouterScreen(
'/projects/:id/issues',
(context, params) => GlIssuesScreen(

View File

@ -96,6 +96,7 @@ class GlProjectScreen extends StatelessWidget {
EntryItem(
count: p.starCount,
text: 'Stars',
url: '/gitlab/projects/$id/starrers',
),
EntryItem(
count: p.forksCount,

View File

@ -0,0 +1,44 @@
import 'package:flutter/material.dart';
import 'package:git_touch/models/auth.dart';
import 'package:git_touch/models/gitlab.dart';
import 'package:git_touch/scaffolds/list_stateful.dart';
import 'package:git_touch/widgets/app_bar_title.dart';
import 'package:git_touch/widgets/user_item.dart';
import 'package:provider/provider.dart';
import 'package:timeago/timeago.dart' as timeago;
class GlStarrersScreen extends StatelessWidget {
final int id;
GlStarrersScreen(this.id);
Future<ListPayload<GitlabStarrer, int>> _query(BuildContext context,
[int page = 1]) async {
final auth = Provider.of<AuthModel>(context);
final res =
await auth.fetchGitlabWithPage('/projects/$id/starrers?page=$page');
return ListPayload(
cursor: res.cursor,
hasMore: res.hasMore,
items: <GitlabStarrer>[
for (var v in res.data) GitlabStarrer.fromJson(v),
],
);
}
@override
Widget build(BuildContext context) {
return ListStatefulScaffold<GitlabStarrer, int>(
title: AppBarTitle('Members'),
onRefresh: () => _query(context),
onLoadMore: (page) => _query(context, page),
itemBuilder: (v) {
return UserItem(
avatarUrl: v.user.avatarUrl,
login: v.user.username,
bio: Text('Starred ' + timeago.format(v.starredSince)),
url: '/gitlab/user/${v.user.id}',
);
},
);
}
}