2021-01-06 05:52:58 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:git_touch/models/gitee.dart';
|
|
|
|
import 'package:git_touch/scaffolds/refresh_stateful.dart';
|
|
|
|
import 'package:git_touch/utils/utils.dart';
|
2021-01-09 04:23:52 +01:00
|
|
|
import 'package:git_touch/widgets/action_button.dart';
|
2021-01-06 05:52:58 +01:00
|
|
|
import 'package:git_touch/widgets/action_entry.dart';
|
|
|
|
import 'package:git_touch/widgets/avatar.dart';
|
|
|
|
import 'package:git_touch/widgets/link.dart';
|
|
|
|
import 'package:git_touch/widgets/comment_item.dart';
|
|
|
|
import 'package:primer/primer.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:git_touch/models/auth.dart';
|
|
|
|
import 'package:git_touch/models/theme.dart';
|
|
|
|
import 'package:tuple/tuple.dart';
|
|
|
|
|
|
|
|
class GeIssueScreen extends StatelessWidget {
|
|
|
|
final String owner;
|
|
|
|
final String name;
|
|
|
|
final String number;
|
|
|
|
final bool isPr;
|
|
|
|
|
|
|
|
GeIssueScreen(this.owner, this.name, this.number, {this.isPr: false});
|
|
|
|
|
2021-01-09 04:23:52 +01:00
|
|
|
List<ActionItem> _buildCommentActionItem(
|
|
|
|
BuildContext context, GiteeComment comment) {
|
|
|
|
final auth = context.read<AuthModel>();
|
|
|
|
final theme = context.read<ThemeModel>();
|
|
|
|
return [
|
|
|
|
ActionItem(
|
|
|
|
iconData: Octicons.pencil,
|
|
|
|
text: 'Edit',
|
|
|
|
onTap: (_) {
|
|
|
|
final uri = Uri(
|
|
|
|
path: '/gitee/$owner/$name/issues/$number/comment',
|
|
|
|
queryParameters: {
|
|
|
|
'body': comment.body,
|
|
|
|
'id': comment.id.toString(),
|
|
|
|
},
|
|
|
|
).toString();
|
|
|
|
theme.push(context, uri);
|
|
|
|
}),
|
|
|
|
ActionItem(
|
|
|
|
iconData: Octicons.trashcan,
|
|
|
|
text: 'Delete',
|
|
|
|
onTap: (_) async {
|
|
|
|
await auth.fetchGitee(
|
|
|
|
'/repos/$owner/$name/issues/comments/${comment.id}',
|
|
|
|
requestType: 'DELETE');
|
|
|
|
await theme.push(context, '/gitee/$owner/$name/issues/$number',
|
|
|
|
replace: true);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-01-06 05:52:58 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return RefreshStatefulScaffold<Tuple2<GiteeIssue, List<GiteeComment>>>(
|
|
|
|
title: Text("Issue: #$number"),
|
|
|
|
fetch: () async {
|
|
|
|
final auth = context.read<AuthModel>();
|
|
|
|
final items = await Future.wait([
|
|
|
|
auth.fetchGitee('/repos/$owner/$name/issues/$number'),
|
|
|
|
auth.fetchGitee('/repos/$owner/$name/issues/$number/comments')
|
|
|
|
]);
|
|
|
|
return Tuple2(GiteeIssue.fromJson(items[0]),
|
|
|
|
[for (var v in items[1]) GiteeComment.fromJson(v)]);
|
|
|
|
},
|
|
|
|
actionBuilder: (data, _) => ActionEntry(
|
|
|
|
iconData: Octicons.plus,
|
|
|
|
url: '/gitee/$owner/$name/issues/$number/comment',
|
|
|
|
),
|
|
|
|
bodyBuilder: (data, _) {
|
|
|
|
final issue = data.item1;
|
|
|
|
final comments = data.item2;
|
|
|
|
final theme = context.read<ThemeModel>();
|
|
|
|
return Column(children: <Widget>[
|
|
|
|
Container(
|
|
|
|
padding: CommonStyle.padding,
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
Link(
|
|
|
|
url: '/gitee/$owner/$name',
|
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
|
|
|
Avatar(
|
|
|
|
url: issue.user.avatarUrl,
|
|
|
|
size: AvatarSize.extraSmall,
|
|
|
|
),
|
|
|
|
SizedBox(width: 4),
|
|
|
|
Text(
|
|
|
|
'$owner / $name',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 17,
|
|
|
|
color: theme.palette.secondaryText,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(width: 4),
|
|
|
|
Text(
|
|
|
|
'#$number',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 17,
|
|
|
|
color: theme.palette.tertiaryText,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(height: 8),
|
|
|
|
Text(
|
|
|
|
issue.title,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 20,
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(height: 8),
|
|
|
|
StateLabel(
|
|
|
|
issue.state == 'open'
|
|
|
|
? StateLabelStatus.issueOpened
|
|
|
|
: StateLabelStatus.issueClosed,
|
|
|
|
small: true),
|
|
|
|
SizedBox(height: 16),
|
|
|
|
CommonStyle.border,
|
|
|
|
],
|
|
|
|
)),
|
|
|
|
Column(children: [
|
|
|
|
for (var comment in comments) ...[
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(left: 10),
|
|
|
|
child: CommentItem(
|
2021-01-09 04:23:52 +01:00
|
|
|
avatar: Avatar(
|
|
|
|
url: comment.user.avatarUrl,
|
|
|
|
linkUrl: '/gitee/${comment.user.login}',
|
|
|
|
),
|
|
|
|
createdAt: DateTime.parse(comment.createdAt),
|
|
|
|
body: comment.body,
|
|
|
|
login: comment.user.login,
|
|
|
|
prefix: 'gitee',
|
|
|
|
commentActionItemList:
|
|
|
|
_buildCommentActionItem(context, comment),
|
|
|
|
)),
|
2021-01-06 05:52:58 +01:00
|
|
|
CommonStyle.border,
|
|
|
|
SizedBox(height: 16),
|
|
|
|
],
|
|
|
|
]),
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|