mirror of
https://github.com/pd4d10/git-touch.git
synced 2026-04-29 11:03:05 -05:00
feat: extract issue and pull request common widget, add more type
This commit is contained in:
33
lib/widgets/comment_item.dart
Normal file
33
lib/widgets/comment_item.dart
Normal file
@@ -0,0 +1,33 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||
import 'package:git_flux/widgets/widgets.dart';
|
||||
import 'package:git_flux/utils/utils.dart';
|
||||
|
||||
class CommentItem extends StatelessWidget {
|
||||
final Map<String, dynamic> item;
|
||||
|
||||
CommentItem(this.item);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(children: <Widget>[
|
||||
Row(children: <Widget>[
|
||||
Avatar(item['author']['login'], item['author']['avatarUrl']),
|
||||
Padding(padding: EdgeInsets.only(left: 10)),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
UserName(item['author']['login']),
|
||||
Text('opened ' + TimeAgo.formatFromString(item['createdAt'])),
|
||||
],
|
||||
),
|
||||
),
|
||||
]),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 20, top: 10),
|
||||
child: MarkdownBody(data: item['body']),
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -65,6 +65,10 @@ class EventItem extends StatelessWidget {
|
||||
_buildRepo(context),
|
||||
// TextSpan(text: event.payload['comment']['body'])
|
||||
]);
|
||||
case 'ForkEvent':
|
||||
return TextSpan(children: [
|
||||
TextSpan(text: ' forked '),
|
||||
]);
|
||||
default:
|
||||
return TextSpan(
|
||||
text: 'Type ${event.type} Not implement yet',
|
||||
@@ -117,9 +121,10 @@ class EventItem extends StatelessWidget {
|
||||
|
||||
TextSpan _buildIssue(BuildContext context) {
|
||||
int id = event.payload['issue']['number'];
|
||||
String repo = event.repo.name;
|
||||
String name = event.repo.name;
|
||||
var arr = name.split('/');
|
||||
return _buildLink(
|
||||
context, '#' + id.toString(), () => IssueScreen(id, repo));
|
||||
context, '#' + id.toString(), () => IssueScreen(id, arr[0], arr[1]));
|
||||
}
|
||||
|
||||
TextSpan _buildPullRequest(BuildContext context, int id) {
|
||||
@@ -141,6 +146,8 @@ class EventItem extends StatelessWidget {
|
||||
return Octicons.repo_push;
|
||||
case 'WatchEvent':
|
||||
return Octicons.star;
|
||||
case 'ForkEvent':
|
||||
return Octicons.repo_forked;
|
||||
default:
|
||||
return Octicons.octoface;
|
||||
}
|
||||
89
lib/widgets/issue_pull_request.dart
Normal file
89
lib/widgets/issue_pull_request.dart
Normal file
@@ -0,0 +1,89 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:git_flux/widgets/widgets.dart';
|
||||
|
||||
// Widget of issue screen and pull request screen
|
||||
class IssuePullRequestScreen extends StatefulWidget {
|
||||
final int id;
|
||||
final String owner;
|
||||
final String name;
|
||||
final Function init;
|
||||
final Widget extra;
|
||||
|
||||
IssuePullRequestScreen({
|
||||
this.id,
|
||||
this.owner,
|
||||
this.name,
|
||||
this.init,
|
||||
this.extra,
|
||||
});
|
||||
|
||||
@override
|
||||
_IssuePullRequestScreenState createState() => _IssuePullRequestScreenState();
|
||||
}
|
||||
|
||||
class _IssuePullRequestScreenState extends State<IssuePullRequestScreen> {
|
||||
Map<String, dynamic> payload;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
widget.init().then((_payload) {
|
||||
setState(() {
|
||||
payload = _payload;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
get _fullName => widget.owner + '/' + widget.name;
|
||||
|
||||
Widget _buildBody(BuildContext context) {
|
||||
if (payload == null) {
|
||||
return CupertinoActivityIndicator();
|
||||
}
|
||||
|
||||
List items = payload['timeline']['nodes'];
|
||||
|
||||
return Column(children: <Widget>[
|
||||
Container(
|
||||
// padding: EdgeInsets.all(10),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
widget.extra,
|
||||
Text(payload['title'],
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
height: 1.2,
|
||||
)),
|
||||
CommentItem(payload),
|
||||
// ListView.builder(
|
||||
// shrinkWrap: true,
|
||||
// itemCount: comments.length,
|
||||
// itemBuilder: _buildCommentItem,
|
||||
// ),
|
||||
Column(
|
||||
children:
|
||||
items.map((item) => TimelineItem(item, payload)).toList()),
|
||||
],
|
||||
),
|
||||
)
|
||||
]);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
middle: Text(_fullName + ' #' + widget.id.toString()),
|
||||
trailing: Icon(Icons.more_vert, size: 24),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
child: _buildBody(context),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
188
lib/widgets/timeline_item.dart
Normal file
188
lib/widgets/timeline_item.dart
Normal file
@@ -0,0 +1,188 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:git_flux/utils/utils.dart';
|
||||
import 'package:git_flux/widgets/widgets.dart';
|
||||
|
||||
class TimelineItem extends StatelessWidget {
|
||||
final Map<String, dynamic> item;
|
||||
final Map<String, dynamic> payload;
|
||||
|
||||
TimelineItem(this.item, this.payload);
|
||||
|
||||
TextSpan _buildReviewText(BuildContext context, item) {
|
||||
switch (item['state']) {
|
||||
case 'APPROVED':
|
||||
return TextSpan(text: ' approved these changes');
|
||||
case 'COMMENTED':
|
||||
return TextSpan(text: ' commented ');
|
||||
default:
|
||||
return warningSpan;
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildItem({
|
||||
String actor,
|
||||
IconData iconData = Octicons.octoface,
|
||||
int iconColor = Palette.gray,
|
||||
TextSpan textSpan,
|
||||
item,
|
||||
}) {
|
||||
return Row(
|
||||
children: <Widget>[
|
||||
Icon(iconData, color: Color(iconColor), size: 16),
|
||||
Padding(padding: EdgeInsets.only(left: 4)),
|
||||
Expanded(
|
||||
child: RichText(
|
||||
text: TextSpan(style: TextStyle(color: Colors.black), children: [
|
||||
createUserSpan(actor),
|
||||
textSpan,
|
||||
// TextSpan(text: ' ' + TimeAgo.formatFromString(item['createdAt']))
|
||||
]),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildByType(BuildContext context) {
|
||||
switch (item['__typename']) {
|
||||
case 'IssueComment':
|
||||
return CommentItem(item);
|
||||
case 'ReferencedEvent':
|
||||
// TODO: isCrossRepository
|
||||
if (item['commit'] == null) {
|
||||
return Container();
|
||||
}
|
||||
|
||||
return _buildItem(
|
||||
actor: item['actor']['login'],
|
||||
iconData: Octicons.bookmark,
|
||||
textSpan: TextSpan(children: [
|
||||
TextSpan(text: ' referenced this pull request from commit '),
|
||||
TextSpan(text: item['commit']['oid'].substring(0, 8)),
|
||||
]),
|
||||
item: item,
|
||||
);
|
||||
case 'RenamedTitleEvent':
|
||||
return _buildItem(
|
||||
actor: item['actor']['login'],
|
||||
iconData: Octicons.pencil,
|
||||
textSpan: TextSpan(children: [
|
||||
TextSpan(text: ' changed the title '),
|
||||
TextSpan(
|
||||
text: item['previousTitle'],
|
||||
style: TextStyle(decoration: TextDecoration.lineThrough),
|
||||
),
|
||||
TextSpan(text: ' to '),
|
||||
TextSpan(text: item['currentTitle'])
|
||||
]),
|
||||
item: item,
|
||||
);
|
||||
case 'ClosedEvent':
|
||||
return _buildItem(
|
||||
actor: item['actor']['login'],
|
||||
iconData: Octicons.circle_slash,
|
||||
iconColor: Palette.red,
|
||||
textSpan: TextSpan(text: ' closed this '),
|
||||
item: item,
|
||||
);
|
||||
case 'ReopenedEvent':
|
||||
return _buildItem(
|
||||
actor: item['actor']['login'],
|
||||
iconData: Octicons.primitive_dot,
|
||||
iconColor: Palette.green,
|
||||
textSpan: TextSpan(text: ' reopened this '),
|
||||
item: item,
|
||||
);
|
||||
case 'CrossReferencedEvent':
|
||||
return _buildItem(
|
||||
actor: item['actor']['login'],
|
||||
iconData: Octicons.primitive_dot,
|
||||
iconColor: Palette.green,
|
||||
textSpan: TextSpan(
|
||||
text: ' referenced this on #' +
|
||||
item['source']['number'].toString()),
|
||||
item: item,
|
||||
);
|
||||
|
||||
//
|
||||
case 'ReviewRequestedEvent':
|
||||
return _buildItem(
|
||||
iconData: Octicons.eye,
|
||||
actor: payload['author']['login'],
|
||||
textSpan: TextSpan(children: [
|
||||
TextSpan(text: ' requested a review from '),
|
||||
createUserSpan(item['requestedReviewer']['login']),
|
||||
]),
|
||||
item: item,
|
||||
);
|
||||
case 'PullRequestReview':
|
||||
return _buildItem(
|
||||
actor: item['author']['login'],
|
||||
iconColor: 0xff28a745,
|
||||
iconData: Octicons.check,
|
||||
textSpan: _buildReviewText(context, item),
|
||||
item: item,
|
||||
);
|
||||
case 'LabeledEvent':
|
||||
return _buildItem(
|
||||
actor: item['actor']['login'],
|
||||
iconData: Octicons.tag,
|
||||
textSpan: TextSpan(children: [
|
||||
TextSpan(text: ' added the '),
|
||||
TextSpan(text: item['label']['name']),
|
||||
TextSpan(text: 'label'),
|
||||
]),
|
||||
item: item,
|
||||
);
|
||||
case 'MergedEvent':
|
||||
return _buildItem(
|
||||
actor: item['actor']['login'],
|
||||
iconData: Octicons.git_merge,
|
||||
iconColor: 0xff6f42c1,
|
||||
textSpan: TextSpan(children: [
|
||||
TextSpan(text: ' merged commit '),
|
||||
TextSpan(text: item['commit']['oid'].substring(0, 8)),
|
||||
TextSpan(text: ' into '),
|
||||
TextSpan(text: item['mergeRefName']),
|
||||
]),
|
||||
item: item,
|
||||
);
|
||||
case 'HeadRefDeletedEvent':
|
||||
return _buildItem(
|
||||
actor: item['actor']['login'],
|
||||
iconData: Octicons.git_branch,
|
||||
textSpan: TextSpan(children: [
|
||||
TextSpan(text: ' deleted the '),
|
||||
TextSpan(text: item['headRefName']),
|
||||
TextSpan(text: ' branch'),
|
||||
]),
|
||||
item: item,
|
||||
);
|
||||
case 'Commit':
|
||||
return _buildItem(
|
||||
actor: item['author']['user']['login'],
|
||||
iconData: Octicons.git_commit,
|
||||
textSpan: TextSpan(children: [
|
||||
TextSpan(text: ' added commit '),
|
||||
TextSpan(text: item['oid'].substring(0, 8))
|
||||
]),
|
||||
item: item,
|
||||
);
|
||||
default:
|
||||
return warning;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
bottom:
|
||||
BorderSide(color: CupertinoColors.extraLightBackgroundGray))),
|
||||
child: _buildByType(context),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
export 'avatar.dart';
|
||||
export 'event.dart';
|
||||
export 'event_item.dart';
|
||||
export 'user_name.dart';
|
||||
export 'timeline_item.dart';
|
||||
export 'comment_item.dart';
|
||||
export 'issue_pull_request.dart';
|
||||
|
||||
Reference in New Issue
Block a user