mirror of
https://github.com/git-touch/git-touch
synced 2024-12-24 06:42:07 +01:00
77 lines
2.5 KiB
Dart
77 lines
2.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:git_touch/graphql/gh.dart';
|
|
import 'package:git_touch/models/auth.dart';
|
|
import 'package:git_touch/scaffolds/list_stateful.dart';
|
|
import 'package:git_touch/utils/utils.dart';
|
|
import 'package:git_touch/widgets/app_bar_title.dart';
|
|
import 'package:git_touch/widgets/commit_item.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
final commitsRouter = RouterScreen(
|
|
'/:owner/:name/commits',
|
|
(context, params) =>
|
|
CommitsScreen(params['owner'].first, params['name'].first));
|
|
|
|
class CommitsScreen extends StatelessWidget {
|
|
final String owner;
|
|
final String name;
|
|
final String branch;
|
|
|
|
CommitsScreen(this.owner, this.name, {this.branch});
|
|
|
|
Future<ListPayload<GhCommitsCommit, String>> _query(BuildContext context,
|
|
[String cursor]) async {
|
|
final res = await Provider.of<AuthModel>(context).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,
|
|
);
|
|
}
|
|
|
|
Widget _buildStatus(GhCommitsStatusState state) {
|
|
const size = 18.0;
|
|
switch (state) {
|
|
case GhCommitsStatusState.SUCCESS:
|
|
return Icon(Octicons.check, color: GithubPalette.open, size: size);
|
|
case GhCommitsStatusState.FAILURE:
|
|
return Icon(Octicons.x, color: GithubPalette.closed, size: size);
|
|
default:
|
|
return Container();
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ListStatefulScaffold<GhCommitsCommit, String>(
|
|
title: AppBarTitle('Commits'),
|
|
onRefresh: () => _query(context),
|
|
onLoadMore: (cursor) => _query(context, cursor),
|
|
itemBuilder: (payload) {
|
|
return CommitItem(
|
|
url: payload.url,
|
|
avatarUrl: payload.author?.avatarUrl,
|
|
message: payload.messageHeadline,
|
|
author: payload.author?.user?.login ?? payload.author.name,
|
|
createdAt: payload.committedDate,
|
|
widgets: payload.status == null
|
|
? null
|
|
: [
|
|
SizedBox(width: 4),
|
|
_buildStatus(payload.status.state),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|