1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-24 23:01:18 +01:00
git-touch-android-ios-app/lib/screens/gitlab_issue.dart

101 lines
3.3 KiB
Dart
Raw Normal View History

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';
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(
2019-12-14 17:08:12 +01:00
'/projects/:id/issues/:iid',
2019-12-13 06:13:45 +01:00
(context, params) => GitlabIssueScreen(
int.parse(['id'].first), int.parse(params['iid'].first)));
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;
2019-12-04 15:00:39 +01:00
GitlabIssueScreen(this.projectId, this.iid, {this.isMr});
2019-11-01 18:12:17 +01:00
@override
Widget build(BuildContext context) {
2019-12-04 15:00:39 +01:00
return RefreshStatefulScaffold<
Tuple3<GitlabIssue, Iterable<GitlabIssueNote>, List>>(
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)
2019-12-04 15:00:39 +01:00
.fetchGitlab('/projects/$projectId/$type/$iid/notes'),
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(
GitlabIssue.fromJson(items[0]),
(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,
child: Column(
children: <Widget>[
2019-12-04 15:00:39 +01:00
Text(issue.title),
2019-11-01 18:12:17 +01:00
Row(
children: <Widget>[
2019-12-27 08:06:45 +01:00
Avatar(
url: issue.author.avatarUrl,
linkUrl: '/user/${issue.author}',
),
2019-11-01 18:12:17 +01:00
Expanded(
2019-12-04 15:00:39 +01:00
child: Text(issue.description),
2019-11-01 18:12:17 +01:00
),
],
),
2019-12-04 15:00:39 +01:00
Text(timeago.format(DateTime.parse(issue.createdAt)))
2019-11-01 18:12:17 +01:00
],
),
),
CommonStyle.border,
Column(
children: notes.map((note) {
return Container(
padding: CommonStyle.padding,
child: Column(
children: <Widget>[
Row(
children: <Widget>[
2019-12-22 04:11:13 +01:00
Avatar(url: note.author.avatarUrl),
2019-11-01 18:12:17 +01:00
Expanded(
child: Column(
2019-12-04 15:00:39 +01:00
children: <Widget>[Text(note.author.name)],
2019-11-01 18:12:17 +01:00
),
)
],
),
2019-12-04 15:00:39 +01:00
MarkdownView(note.body),
2019-11-01 18:12:17 +01:00
],
),
);
}).toList(),
)
],
);
},
);
}
}