git-touch-android-ios-app/lib/screens/gh_commits.dart

71 lines
2.4 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';
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';
2020-01-28 15:10:44 +01:00
import 'package:git_touch/widgets/commit_item.dart';
2019-09-08 14:07:35 +02:00
import 'package:provider/provider.dart';
import '../generated/l10n.dart';
2019-08-30 10:26:56 +02:00
2020-02-07 07:17:05 +01:00
class GhCommitsScreen extends StatelessWidget {
2019-08-30 10:26:56 +02:00
final String owner;
final String name;
2019-09-23 11:08:51 +02:00
final String branch;
2020-02-07 07:17:05 +01:00
GhCommitsScreen(this.owner, this.name, {this.branch});
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-07 08:07:57 +01:00
return ListStatefulScaffold<GhCommitsCommit, String>(
title: AppBarTitle(S.of(context).commits),
fetch: (cursor) async {
2020-10-04 16:10:05 +02:00
final res = await context.read<AuthModel>().gqlClient.execute(
GhCommitsQuery(
variables: GhCommitsArguments(
owner: owner,
name: name,
hasRef: branch != null,
ref: branch ?? '',
after: cursor)));
final ref =
res.data.repository.defaultBranchRef ?? res.data.repository.ref;
final history = (ref.target as GhCommitsCommit).history;
return ListPayload(
cursor: history.pageInfo.endCursor,
hasMore: history.pageInfo.hasNextPage,
items: history.nodes,
);
},
2019-08-30 10:26:56 +02:00
itemBuilder: (payload) {
final login = payload.author?.user?.login;
2020-01-28 15:10:44 +01:00
return CommitItem(
2019-12-13 16:44:49 +01:00
url: payload.url,
2020-01-28 15:10:44 +01:00
avatarUrl: payload.author?.avatarUrl,
avatarLink: login == null ? null : '/github/$login',
2020-01-28 15:10:44 +01:00
message: payload.messageHeadline,
author: login ?? payload.author.name,
2020-01-28 15:10:44 +01:00
createdAt: payload.committedDate,
widgets: payload.status == null
? null
: [
SizedBox(width: 4),
_buildStatus(payload.status.state),
],
2019-08-30 10:26:56 +02:00
);
},
);
}
}