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

fix(gitlab): issue and user

This commit is contained in:
Rongjian Zhang 2020-01-30 18:57:39 +08:00
parent 5d2745cd00
commit 92a33e8fb8
4 changed files with 58 additions and 49 deletions

View File

@ -63,7 +63,7 @@ class GitlabTodoTarget {
String title;
GitlabUser author;
String description;
String createdAt;
DateTime createdAt;
GitlabTodoTarget();
@ -75,9 +75,9 @@ class GitlabTodoTarget {
class GitlabIssueNote {
GitlabUser author;
String body;
bool system;
DateTime createdAt;
GitlabIssueNote();
factory GitlabIssueNote.fromJson(Map<String, dynamic> json) =>
_$GitlabIssueNoteFromJson(json);
}

View File

@ -99,7 +99,9 @@ GitlabTodoTarget _$GitlabTodoTargetFromJson(Map<String, dynamic> json) {
? null
: GitlabUser.fromJson(json['author'] as Map<String, dynamic>)
..description = json['description'] as String
..createdAt = json['created_at'] as String;
..createdAt = json['created_at'] == null
? null
: DateTime.parse(json['created_at'] as String);
}
Map<String, dynamic> _$GitlabTodoTargetToJson(GitlabTodoTarget instance) =>
@ -109,7 +111,7 @@ Map<String, dynamic> _$GitlabTodoTargetToJson(GitlabTodoTarget instance) =>
'title': instance.title,
'author': instance.author,
'description': instance.description,
'created_at': instance.createdAt,
'created_at': instance.createdAt?.toIso8601String(),
};
GitlabIssueNote _$GitlabIssueNoteFromJson(Map<String, dynamic> json) {
@ -117,13 +119,19 @@ GitlabIssueNote _$GitlabIssueNoteFromJson(Map<String, dynamic> json) {
..author = json['author'] == null
? null
: GitlabUser.fromJson(json['author'] as Map<String, dynamic>)
..body = json['body'] as String;
..body = json['body'] as String
..system = json['system'] as bool
..createdAt = json['created_at'] == null
? null
: DateTime.parse(json['created_at'] as String);
}
Map<String, dynamic> _$GitlabIssueNoteToJson(GitlabIssueNote instance) =>
<String, dynamic>{
'author': instance.author,
'body': instance.body,
'system': instance.system,
'created_at': instance.createdAt?.toIso8601String(),
};
GitlabProject _$GitlabProjectFromJson(Map<String, dynamic> json) {

View File

@ -3,6 +3,7 @@ import 'package:git_touch/models/gitlab.dart';
import 'package:git_touch/scaffolds/refresh_stateful.dart';
import 'package:git_touch/utils/utils.dart';
import 'package:git_touch/widgets/avatar.dart';
import 'package:git_touch/widgets/comment_item.dart';
import 'package:git_touch/widgets/markdown_view.dart';
import 'package:provider/provider.dart';
import 'package:git_touch/models/auth.dart';
@ -37,7 +38,7 @@ class GitlabIssueScreen extends StatelessWidget {
Provider.of<AuthModel>(context)
.fetchGitlab('/projects/$projectId/$type/$iid'),
Provider.of<AuthModel>(context)
.fetchGitlab('/projects/$projectId/$type/$iid/notes'),
.fetchGitlab('/projects/$projectId/$type/$iid/notes?sort=asc'),
Provider.of<AuthModel>(context)
.fetchGitlab('/projects/$projectId/$type/$iid/award_emoji'),
]);
@ -56,46 +57,45 @@ class GitlabIssueScreen extends StatelessWidget {
children: <Widget>[
Container(
padding: CommonStyle.padding,
child: Column(
children: <Widget>[
Text(issue.title),
Row(
children: <Widget>[
Avatar(
url: issue.author.avatarUrl,
linkUrl: '/user/${issue.author}',
),
Expanded(
child: Text(issue.description),
),
],
),
Text(timeago.format(DateTime.parse(issue.createdAt)))
],
child: CommentItem(
avatar: Avatar(
url: issue.author.avatarUrl,
linkUrl: '/gitlab/user/${issue.author.id}',
),
createdAt: issue.createdAt,
body: issue.description,
login: issue.author.username,
),
),
CommonStyle.border,
Column(
children: notes.map((note) {
return Container(
padding: CommonStyle.padding,
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Avatar(url: note.author.avatarUrl),
Expanded(
child: Column(
children: <Widget>[Text(note.author.name)],
),
)
],
children: <Widget>[
for (var note in notes)
if (note.system)
Container(
padding: CommonStyle.padding,
child: Text.rich(
TextSpan(children: [
WidgetSpan(child: Avatar(url: note.author.avatarUrl)),
TextSpan(text: note.author.name),
TextSpan(text: note.body),
]),
),
MarkdownView(note.body),
],
),
);
}).toList(),
)
else
Container(
padding: CommonStyle.padding,
child: CommentItem(
avatar: Avatar(
url: note.author.avatarUrl,
linkUrl: '/gitlab/user/${note.author.id}',
),
createdAt: note.createdAt,
body: note.body,
login: note.author.username,
),
)
],
)
],
);

View File

@ -30,13 +30,14 @@ class GitlabUserScreen extends StatelessWidget {
fetchData: () async {
final auth = Provider.of<AuthModel>(context);
final _id = id ?? auth.activeAccount.gitlabId;
final v0 = await auth.fetchGitlab('/users/$_id');
final user = GitlabUser.fromJson(v0);
final v1 = await auth.fetchGitlab('/users/$_id/projects');
final projects =
(v1 as List).map((v) => GitlabUserProject.fromJson(v)).toList();
return Tuple2(user, projects);
final res = await Future.wait([
auth.fetchGitlab('/users/$_id'),
auth.fetchGitlab('/users/$_id/projects'),
]);
return Tuple2(
GitlabUser.fromJson(res[0]),
[for (var v in res[1]) GitlabUserProject.fromJson(v)],
);
},
action: isViewer
? ActionEntry(