1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-23 21:52:19 +01:00
git-touch-android-ios-app/lib/screens/commits.dart

117 lines
4.0 KiB
Dart
Raw Normal View History

2019-08-30 10:26:56 +02:00
import 'package:flutter/material.dart';
2020-01-07 08:07:57 +01:00
import 'package:git_touch/graphql/gh.dart';
2019-09-27 14:52:38 +02:00
import 'package:git_touch/models/auth.dart';
2020-01-02 14:31:58 +01:00
import 'package:git_touch/models/theme.dart';
2019-09-25 11:06:36 +02:00
import 'package:git_touch/scaffolds/list_stateful.dart';
2019-09-03 08:59:08 +02:00
import 'package:git_touch/utils/utils.dart';
2019-09-11 13:59:47 +02:00
import 'package:git_touch/widgets/app_bar_title.dart';
2019-08-30 10:26:56 +02:00
import 'package:git_touch/widgets/link.dart';
2019-09-08 14:07:35 +02:00
import 'package:provider/provider.dart';
2019-08-30 10:26:56 +02:00
import 'package:timeago/timeago.dart' as timeago;
import 'package:git_touch/widgets/avatar.dart';
2019-12-13 06:13:45 +01:00
final commitsRouter = RouterScreen(
'/:owner/:name/commits',
(context, params) =>
CommitsScreen(params['owner'].first, params['name'].first));
2019-08-30 10:26:56 +02:00
class CommitsScreen extends StatelessWidget {
final String owner;
final String name;
2019-09-23 11:08:51 +02:00
final String branch;
2019-08-30 10:26:56 +02:00
2019-09-23 11:08:51 +02:00
CommitsScreen(this.owner, this.name, {this.branch});
2019-08-30 10:26:56 +02:00
2020-01-07 08:07:57 +01:00
Future<ListPayload<GhCommitsCommit, String>> _query(BuildContext context,
2019-12-13 16:44:49 +01:00
[String cursor]) async {
final res = await Provider.of<AuthModel>(context).gqlClient.execute(
2020-01-07 08:07:57 +01:00
GhCommitsQuery(
variables: GhCommitsArguments(
2019-12-13 16:44:49 +01:00
owner: owner,
name: name,
hasRef: branch != null,
ref: branch ?? '',
after: cursor)));
final ref = res.data.repository.defaultBranchRef ?? res.data.repository.ref;
2020-01-07 08:07:57 +01:00
final history = (ref.target as GhCommitsCommit).history;
2019-08-30 10:26:56 +02:00
return ListPayload(
2019-12-13 16:44:49 +01:00
cursor: history.pageInfo.endCursor,
hasMore: history.pageInfo.hasNextPage,
items: history.nodes,
2019-08-30 10:26:56 +02:00
);
}
2020-01-07 08:07:57 +01:00
Widget _buildStatus(GhCommitsStatusState state) {
2020-01-03 07:47:07 +01:00
const size = 18.0;
2019-09-03 08:59:08 +02:00
switch (state) {
2020-01-07 08:07:57 +01:00
case GhCommitsStatusState.SUCCESS:
2019-11-08 13:23:09 +01:00
return Icon(Octicons.check, color: GithubPalette.open, size: size);
2020-01-07 08:07:57 +01:00
case GhCommitsStatusState.FAILURE:
2019-11-08 13:23:09 +01:00
return Icon(Octicons.x, color: GithubPalette.closed, size: size);
2019-09-03 08:59:08 +02:00
default:
return Container();
}
}
2019-08-30 10:26:56 +02:00
@override
Widget build(BuildContext context) {
2020-01-02 14:31:58 +01:00
final theme = Provider.of<ThemeModel>(context);
2020-01-07 08:07:57 +01:00
return ListStatefulScaffold<GhCommitsCommit, String>(
2019-09-11 13:59:47 +02:00
title: AppBarTitle('Commits'),
2019-08-30 10:26:56 +02:00
onRefresh: () => _query(context),
onLoadMore: (cursor) => _query(context, cursor),
itemBuilder: (payload) {
return Link(
2019-12-13 16:44:49 +01:00
url: payload.url,
2019-08-30 10:26:56 +02:00
child: Container(
2019-10-02 10:09:54 +02:00
padding: CommonStyle.padding,
2019-08-30 10:26:56 +02:00
child: Row(
2019-09-03 08:59:08 +02:00
crossAxisAlignment: CrossAxisAlignment.start,
2019-08-30 10:26:56 +02:00
children: <Widget>[
2020-01-02 14:31:58 +01:00
Avatar(url: payload.author?.avatarUrl),
SizedBox(width: 10),
2019-08-30 10:26:56 +02:00
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
2020-01-02 14:31:58 +01:00
Text(
payload.messageHeadline,
style: TextStyle(
fontSize: 17,
color: theme.palette.text,
),
overflow: TextOverflow.ellipsis,
),
2019-08-30 10:26:56 +02:00
SizedBox(height: 4),
2019-09-03 08:59:08 +02:00
Wrap(
2019-08-30 10:26:56 +02:00
children: <Widget>[
2019-09-03 08:32:17 +02:00
Text(
2020-01-02 14:31:58 +01:00
payload.author?.user?.login ??
payload.author.name,
style: TextStyle(fontSize: 15)),
2019-08-30 10:26:56 +02:00
Text(
2020-01-02 14:31:58 +01:00
' committed ${timeago.format(payload.committedDate)}',
style: TextStyle(
color: theme.palette.secondaryText,
fontSize: 15,
),
),
2020-01-03 07:47:07 +01:00
if (payload.status != null) ...[
SizedBox(width: 4),
_buildStatus(payload.status.state),
],
2019-08-30 10:26:56 +02:00
],
)
],
),
)
],
),
),
);
},
);
}
}