2019-11-01 18:12:17 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2019-12-04 15:00:39 +01:00
|
|
|
import 'package:git_touch/models/gitlab.dart';
|
2019-11-01 18:12:17 +01:00
|
|
|
import 'package:git_touch/scaffolds/refresh_stateful.dart';
|
|
|
|
import 'package:git_touch/utils/utils.dart';
|
|
|
|
import 'package:git_touch/widgets/avatar.dart';
|
2020-01-30 11:57:39 +01:00
|
|
|
import 'package:git_touch/widgets/comment_item.dart';
|
2019-11-01 18:12:17 +01:00
|
|
|
import 'package:git_touch/widgets/markdown_view.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:git_touch/models/auth.dart';
|
|
|
|
import 'package:timeago/timeago.dart' as timeago;
|
2019-12-04 15:00:39 +01:00
|
|
|
import 'package:tuple/tuple.dart';
|
2019-11-01 18:12:17 +01:00
|
|
|
|
2019-12-13 06:13:45 +01:00
|
|
|
final gitlabIssueRouter = RouterScreen(
|
2020-01-30 10:20:14 +01:00
|
|
|
'/gitlab/projects/:id/issues/:iid',
|
|
|
|
(context, params) {
|
|
|
|
return GitlabIssueScreen(
|
|
|
|
int.parse(params['id'].first),
|
|
|
|
int.parse(params['iid'].first),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
2019-12-13 06:13:45 +01:00
|
|
|
|
2019-11-01 18:12:17 +01:00
|
|
|
class GitlabIssueScreen extends StatelessWidget {
|
|
|
|
final int projectId;
|
2019-12-04 15:00:39 +01:00
|
|
|
final int iid;
|
2019-11-01 18:12:17 +01:00
|
|
|
final bool isMr;
|
|
|
|
|
2020-01-30 10:20:14 +01:00
|
|
|
GitlabIssueScreen(this.projectId, this.iid, {this.isMr = false});
|
2019-11-01 18:12:17 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2019-12-04 15:00:39 +01:00
|
|
|
return RefreshStatefulScaffold<
|
2020-01-28 16:39:26 +01:00
|
|
|
Tuple3<GitlabTodoTarget, Iterable<GitlabIssueNote>, List>>(
|
2019-12-04 15:00:39 +01:00
|
|
|
title: Text('Issue #$iid'),
|
2019-11-01 18:12:17 +01:00
|
|
|
fetchData: () async {
|
|
|
|
final type = isMr ? 'merge_requests' : 'issues';
|
|
|
|
final items = await Future.wait([
|
|
|
|
Provider.of<AuthModel>(context)
|
2019-12-04 15:00:39 +01:00
|
|
|
.fetchGitlab('/projects/$projectId/$type/$iid'),
|
2019-11-01 18:12:17 +01:00
|
|
|
Provider.of<AuthModel>(context)
|
2020-01-30 11:57:39 +01:00
|
|
|
.fetchGitlab('/projects/$projectId/$type/$iid/notes?sort=asc'),
|
2019-11-01 18:12:17 +01:00
|
|
|
Provider.of<AuthModel>(context)
|
2019-12-04 15:00:39 +01:00
|
|
|
.fetchGitlab('/projects/$projectId/$type/$iid/award_emoji'),
|
2019-11-01 18:12:17 +01:00
|
|
|
]);
|
2019-12-04 15:00:39 +01:00
|
|
|
return Tuple3(
|
2020-01-28 16:39:26 +01:00
|
|
|
GitlabTodoTarget.fromJson(items[0]),
|
2019-12-04 15:00:39 +01:00
|
|
|
(items[1] as List).map((v) => GitlabIssueNote.fromJson(v)),
|
|
|
|
items[2] as List,
|
|
|
|
);
|
2019-11-01 18:12:17 +01:00
|
|
|
},
|
2019-11-02 13:54:23 +01:00
|
|
|
bodyBuilder: (data, _) {
|
2019-12-04 15:00:39 +01:00
|
|
|
final issue = data.item1;
|
|
|
|
final notes = data.item2;
|
|
|
|
final emoji = data.item3;
|
2019-11-01 18:12:17 +01:00
|
|
|
|
|
|
|
return Column(
|
|
|
|
children: <Widget>[
|
|
|
|
Container(
|
|
|
|
padding: CommonStyle.padding,
|
2020-01-30 11:57:39 +01:00
|
|
|
child: CommentItem(
|
|
|
|
avatar: Avatar(
|
|
|
|
url: issue.author.avatarUrl,
|
|
|
|
linkUrl: '/gitlab/user/${issue.author.id}',
|
|
|
|
),
|
|
|
|
createdAt: issue.createdAt,
|
|
|
|
body: issue.description,
|
|
|
|
login: issue.author.username,
|
2019-11-01 18:12:17 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
CommonStyle.border,
|
|
|
|
Column(
|
2020-01-30 11:57:39 +01:00
|
|
|
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),
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
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,
|
2019-11-01 18:12:17 +01:00
|
|
|
),
|
2020-01-30 11:57:39 +01:00
|
|
|
)
|
|
|
|
],
|
2019-11-01 18:12:17 +01:00
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|