2022-09-17 20:35:45 +08:00
|
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
import 'package:flutter_gen/gen_l10n/S.dart';
|
2022-10-08 00:55:47 +08:00
|
|
|
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
|
2019-09-27 20:52:38 +08:00
|
|
|
import 'package:git_touch/models/auth.dart';
|
2019-09-25 17:06:36 +08:00
|
|
|
import 'package:git_touch/scaffolds/list_stateful.dart';
|
2020-01-28 22:10:44 +08:00
|
|
|
import 'package:git_touch/widgets/commit_item.dart';
|
2022-10-02 00:29:54 +08:00
|
|
|
import 'package:gql_github/commits.data.gql.dart';
|
|
|
|
import 'package:gql_github/commits.req.gql.dart';
|
|
|
|
import 'package:gql_github/schema.schema.gql.dart';
|
2019-09-08 20:07:35 +08:00
|
|
|
import 'package:provider/provider.dart';
|
2019-08-30 16:26:56 +08:00
|
|
|
|
2021-01-17 22:08:32 +08:00
|
|
|
class GhCommits extends StatelessWidget {
|
2022-09-22 00:28:21 +08:00
|
|
|
const GhCommits(this.owner, this.name, {this.branch});
|
2019-08-30 16:26:56 +08:00
|
|
|
final String owner;
|
|
|
|
final String name;
|
2021-05-16 15:16:35 +08:00
|
|
|
final String? branch;
|
2019-08-30 16:26:56 +08:00
|
|
|
|
2021-05-16 15:16:35 +08:00
|
|
|
Widget _buildStatus(GStatusState? state) {
|
2020-01-03 14:47:07 +08:00
|
|
|
const size = 18.0;
|
2019-09-03 14:59:08 +08:00
|
|
|
switch (state) {
|
2021-01-17 22:08:32 +08:00
|
|
|
case GStatusState.SUCCESS:
|
2022-09-17 20:35:45 +08:00
|
|
|
return const Icon(Octicons.check,
|
|
|
|
color: GithubPalette.open, size: size);
|
2021-01-17 22:08:32 +08:00
|
|
|
case GStatusState.FAILURE:
|
2022-09-07 00:28:12 +08:00
|
|
|
return const Icon(Octicons.x, color: GithubPalette.closed, size: size);
|
2019-09-03 14:59:08 +08:00
|
|
|
default:
|
|
|
|
return Container();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-30 16:26:56 +08:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-05-16 15:16:35 +08:00
|
|
|
return ListStatefulScaffold<GCommitsRefCommit_history_nodes, String?>(
|
2022-10-08 01:06:03 +08:00
|
|
|
title: Text(AppLocalizations.of(context)!.commits),
|
2020-10-06 20:52:40 +08:00
|
|
|
fetch: (cursor) async {
|
2021-01-17 22:08:32 +08:00
|
|
|
final req = GCommitsReq((b) {
|
|
|
|
b.vars.owner = owner;
|
|
|
|
b.vars.name = name;
|
|
|
|
b.vars.hasRef = branch != null;
|
|
|
|
b.vars.ref = branch ?? '';
|
|
|
|
b.vars.after = cursor;
|
|
|
|
});
|
2022-10-01 03:49:56 +08:00
|
|
|
final res =
|
2022-10-02 01:26:34 +08:00
|
|
|
await context.read<AuthModel>().ghGqlClient.request(req).first;
|
2021-05-16 15:16:35 +08:00
|
|
|
final ref = res.data!.repository!.defaultBranchRef ??
|
|
|
|
res.data!.repository!.ref!;
|
2021-01-17 22:08:32 +08:00
|
|
|
final history = (ref.target as GCommitsRefCommit).history;
|
2020-10-04 22:10:05 +08:00
|
|
|
return ListPayload(
|
|
|
|
cursor: history.pageInfo.endCursor,
|
|
|
|
hasMore: history.pageInfo.hasNextPage,
|
2021-06-14 01:23:16 +08:00
|
|
|
items: history.nodes ?? [],
|
2020-10-04 22:10:05 +08:00
|
|
|
);
|
|
|
|
},
|
2021-01-17 22:08:32 +08:00
|
|
|
itemBuilder: (p) {
|
|
|
|
final login = p.author?.user?.login;
|
2020-01-28 22:10:44 +08:00
|
|
|
return CommitItem(
|
2022-10-17 15:32:40 +05:30
|
|
|
url: '/github/$owner/$name/commit/${p.oid}',
|
2021-01-17 22:08:32 +08:00
|
|
|
avatarUrl: p.author?.avatarUrl,
|
2020-05-12 21:01:30 +05:30
|
|
|
avatarLink: login == null ? null : '/github/$login',
|
2021-01-17 22:08:32 +08:00
|
|
|
message: p.messageHeadline,
|
2021-05-16 15:16:35 +08:00
|
|
|
author: login ?? p.author!.name,
|
2021-01-17 22:08:32 +08:00
|
|
|
createdAt: p.committedDate,
|
|
|
|
widgets: p.status == null
|
2020-01-28 22:10:44 +08:00
|
|
|
? null
|
|
|
|
: [
|
2022-09-07 00:28:12 +08:00
|
|
|
const SizedBox(width: 4),
|
2021-05-16 15:16:35 +08:00
|
|
|
_buildStatus(p.status!.state),
|
2020-01-28 22:10:44 +08:00
|
|
|
],
|
2019-08-30 16:26:56 +08:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|