2022-09-24 20:46:37 +02:00
|
|
|
import 'package:antd_mobile/antd_mobile.dart';
|
2022-09-17 14:35:45 +02:00
|
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
import 'package:git_touch/models/auth.dart';
|
2021-01-06 05:52:58 +01:00
|
|
|
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/comment_item.dart';
|
2022-09-17 14:35:45 +02:00
|
|
|
import 'package:git_touch/widgets/link.dart';
|
2021-01-06 05:52:58 +01:00
|
|
|
import 'package:primer/primer.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:tuple/tuple.dart';
|
|
|
|
|
|
|
|
class GeIssueScreen extends StatelessWidget {
|
2022-09-21 18:28:21 +02:00
|
|
|
const GeIssueScreen(this.owner, this.name, this.number, {this.isPr = false});
|
2021-01-06 05:52:58 +01:00
|
|
|
final String owner;
|
|
|
|
final String name;
|
|
|
|
final String number;
|
|
|
|
final bool isPr;
|
|
|
|
|
2021-01-09 04:23:52 +01:00
|
|
|
List<ActionItem> _buildCommentActionItem(
|
|
|
|
BuildContext context, GiteeComment comment) {
|
|
|
|
final auth = context.read<AuthModel>();
|
|
|
|
return [
|
|
|
|
ActionItem(
|
2022-09-17 15:57:43 +02:00
|
|
|
text: 'Edit',
|
|
|
|
onTap: (_) {
|
|
|
|
final uri = Uri(
|
|
|
|
path: '/gitee/$owner/$name/issues/$number/comment',
|
|
|
|
queryParameters: {
|
|
|
|
'body': comment.body,
|
|
|
|
'id': comment.id.toString(),
|
|
|
|
},
|
|
|
|
).toString();
|
2022-09-22 19:50:45 +02:00
|
|
|
context.pushUrl(uri);
|
2022-09-17 15:57:43 +02:00
|
|
|
},
|
|
|
|
),
|
2021-01-09 04:23:52 +01:00
|
|
|
ActionItem(
|
|
|
|
text: 'Delete',
|
|
|
|
onTap: (_) async {
|
|
|
|
await auth.fetchGitee(
|
|
|
|
'/repos/$owner/$name/issues/comments/${comment.id}',
|
|
|
|
requestType: 'DELETE');
|
2022-09-22 19:50:45 +02:00
|
|
|
await context.pushUrl('/gitee/$owner/$name/issues/$number',
|
2021-01-09 04:23:52 +01:00
|
|
|
replace: true);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-01-06 05:52:58 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return RefreshStatefulScaffold<Tuple2<GiteeIssue, List<GiteeComment>>>(
|
2022-09-18 19:02:57 +02:00
|
|
|
title: Text('Issue: #$number'),
|
2021-01-06 05:52:58 +01:00
|
|
|
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;
|
|
|
|
return Column(children: <Widget>[
|
|
|
|
Container(
|
|
|
|
padding: CommonStyle.padding,
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
2021-05-16 09:16:35 +02:00
|
|
|
LinkWidget(
|
2021-01-06 05:52:58 +01:00
|
|
|
url: '/gitee/$owner/$name',
|
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
|
|
|
Avatar(
|
2021-05-16 09:16:35 +02:00
|
|
|
url: issue.user!.avatarUrl,
|
2021-01-06 05:52:58 +01:00
|
|
|
size: AvatarSize.extraSmall,
|
|
|
|
),
|
2022-09-06 18:28:12 +02:00
|
|
|
const SizedBox(width: 4),
|
2021-01-06 05:52:58 +01:00
|
|
|
Text(
|
|
|
|
'$owner / $name',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 17,
|
2022-09-24 20:46:37 +02:00
|
|
|
color: AntTheme.of(context).colorTextSecondary,
|
2021-01-06 05:52:58 +01:00
|
|
|
),
|
|
|
|
),
|
2022-09-06 18:28:12 +02:00
|
|
|
const SizedBox(width: 4),
|
2021-01-06 05:52:58 +01:00
|
|
|
Text(
|
|
|
|
'#$number',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 17,
|
2022-09-24 20:46:37 +02:00
|
|
|
color: AntTheme.of(context).colorWeak,
|
2021-01-06 05:52:58 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2022-09-06 18:28:12 +02:00
|
|
|
const SizedBox(height: 8),
|
2021-01-06 05:52:58 +01:00
|
|
|
Text(
|
2021-05-16 09:16:35 +02:00
|
|
|
issue.title!,
|
2022-09-06 18:28:12 +02:00
|
|
|
style: const TextStyle(
|
2021-01-06 05:52:58 +01:00
|
|
|
fontSize: 20,
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
),
|
|
|
|
),
|
2022-09-06 18:28:12 +02:00
|
|
|
const SizedBox(height: 8),
|
2021-01-06 05:52:58 +01:00
|
|
|
StateLabel(
|
|
|
|
issue.state == 'open'
|
|
|
|
? StateLabelStatus.issueOpened
|
|
|
|
: StateLabelStatus.issueClosed,
|
|
|
|
small: true),
|
2022-09-06 18:28:12 +02:00
|
|
|
const SizedBox(height: 16),
|
2021-01-06 05:52:58 +01:00
|
|
|
CommonStyle.border,
|
|
|
|
],
|
|
|
|
)),
|
|
|
|
Column(children: [
|
|
|
|
for (var comment in comments) ...[
|
|
|
|
Padding(
|
2022-09-06 18:28:12 +02:00
|
|
|
padding: const EdgeInsets.only(left: 10),
|
2021-01-06 05:52:58 +01:00
|
|
|
child: CommentItem(
|
2021-01-09 04:23:52 +01:00
|
|
|
avatar: Avatar(
|
2021-05-16 09:16:35 +02:00
|
|
|
url: comment.user!.avatarUrl,
|
|
|
|
linkUrl: '/gitee/${comment.user!.login}',
|
2021-01-09 04:23:52 +01:00
|
|
|
),
|
2021-05-16 09:16:35 +02:00
|
|
|
createdAt: DateTime.parse(comment.createdAt!),
|
2021-01-09 04:23:52 +01:00
|
|
|
body: comment.body,
|
2021-05-16 09:16:35 +02:00
|
|
|
login: comment.user!.login,
|
2021-01-09 04:23:52 +01:00
|
|
|
prefix: 'gitee',
|
|
|
|
commentActionItemList:
|
|
|
|
_buildCommentActionItem(context, comment),
|
|
|
|
)),
|
2021-01-06 05:52:58 +01:00
|
|
|
CommonStyle.border,
|
2022-09-06 18:28:12 +02:00
|
|
|
const SizedBox(height: 16),
|
2021-01-06 05:52:58 +01:00
|
|
|
],
|
|
|
|
]),
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|