diff --git a/lib/screens/commits.dart b/lib/screens/commits.dart new file mode 100644 index 0000000..f966021 --- /dev/null +++ b/lib/screens/commits.dart @@ -0,0 +1,106 @@ +import 'package:flutter/material.dart'; +import 'package:git_touch/widgets/link.dart'; +import 'package:timeago/timeago.dart' as timeago; +import 'package:git_touch/providers/settings.dart'; +import 'package:git_touch/scaffolds/list.dart'; +import 'package:git_touch/widgets/avatar.dart'; +import 'package:primer/primer.dart'; + +class CommitsScreen extends StatelessWidget { + final String owner; + final String name; + + CommitsScreen(this.owner, this.name); + + Future _query(BuildContext context, [String cursor]) async { + var params = 'first: 30'; + if (cursor != null) { + params += ', after: "$cursor"'; + } + var data = await SettingsProvider.of(context).query(''' +{ + repository(owner: "$owner", name: "$name") { + ref(qualifiedName: "master") { + target { + ... on Commit { + history($params) { + pageInfo { + hasNextPage + endCursor + } + nodes { + oid + messageHeadline + committedDate + author { + email + avatarUrl + user { + login + } + } + } + } + } + } + } + } +} + '''); + + var history = data["repository"]['ref']['target']['history']; + + return ListPayload( + cursor: history["pageInfo"]["endCursor"], + hasMore: history['pageInfo']['hasNextPage'], + items: history["nodes"], + ); + } + + @override + Widget build(BuildContext context) { + return ListScaffold( + title: Text('Commits'), + onRefresh: () => _query(context), + onLoadMore: (cursor) => _query(context, cursor), + itemBuilder: (payload) { + return Link( + url: 'https://github.com/$owner/$name/commit/' + payload['oid'], + child: Container( + padding: EdgeInsets.all(12), + child: Row( + children: [ + Avatar(url: payload['author']['avatarUrl']), + SizedBox(width: 8), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(payload['messageHeadline'], + style: TextStyle( + fontWeight: FontWeight.w500, fontSize: 14)), + SizedBox(height: 4), + Row( + children: [ + Text(payload['author']['user']['login'], + style: TextStyle( + fontWeight: FontWeight.w500, fontSize: 14)), + Text( + ' committed ' + + timeago.format( + DateTime.parse(payload['committedDate'])), + style: TextStyle( + color: PrimerColors.gray600, fontSize: 14)), + ], + ) + ], + ), + ) + ], + ), + ), + ); + }, + ); + } +} diff --git a/lib/screens/repo.dart b/lib/screens/repo.dart index 64c0f20..2a7f610 100644 --- a/lib/screens/repo.dart +++ b/lib/screens/repo.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter_markdown/flutter_markdown.dart'; +import 'package:git_touch/screens/commits.dart'; import 'package:git_touch/screens/object.dart'; import 'package:share/share.dart'; import 'package:url_launcher/url_launcher.dart'; @@ -62,6 +63,13 @@ class _RepoScreenState extends State { url defaultBranchRef { name + target { + ... on Commit { + history { + totalCount + } + } + } } viewerHasStarred viewerSubscription @@ -192,10 +200,11 @@ class _RepoScreenState extends State { ), ), EntryItem( + count: payload['defaultBranchRef']['target']['history'] + ['totalCount'], text: 'Commits', - url: payload['url'] + - '/commits/' + - payload['defaultBranchRef']['name'], + screenBuilder: (context) => + CommitsScreen(widget.owner, widget.name), ), ], ), diff --git a/pubspec.yaml b/pubspec.yaml index f7067e8..6a87e97 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -31,6 +31,7 @@ dependencies: flutter_svg: ^0.13.0 launch_review: ^2.0.0 flutter_highlight: ^0.2.1 + timeago: ^2.0.18 primer: git: url: git://github.com/pd4d10/primer-flutter