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

64 lines
2.1 KiB
Dart
Raw Normal View History

2019-02-04 11:32:39 +01:00
import 'package:flutter/material.dart';
2020-01-07 08:07:57 +01:00
import 'package:git_touch/graphql/gh.dart';
2019-09-25 11:06:36 +02:00
import 'package:git_touch/scaffolds/list_stateful.dart';
2019-09-11 13:59:47 +02:00
import 'package:git_touch/widgets/app_bar_title.dart';
2019-09-27 14:52:38 +02:00
import 'package:git_touch/models/auth.dart';
2019-09-08 14:07:35 +02:00
import 'package:provider/provider.dart';
2019-09-23 12:28:33 +02:00
import 'package:git_touch/widgets/repository_item.dart';
2020-01-11 12:25:33 +01:00
import 'package:timeago/timeago.dart' as timeago;
2019-02-04 11:32:39 +01:00
2020-02-07 07:17:05 +01:00
class GhReposScreen extends StatelessWidget {
2019-12-07 15:25:37 +01:00
final String owner;
final String title;
2019-12-07 15:25:37 +01:00
final bool isStar;
2019-02-09 06:36:15 +01:00
2020-02-07 07:17:05 +01:00
GhReposScreen(this.owner)
: title = 'Repositories',
2019-12-07 15:25:37 +01:00
isStar = false;
2020-02-07 07:17:05 +01:00
GhReposScreen.stars(this.owner)
: title = 'Stars',
2019-12-07 15:25:37 +01:00
isStar = true;
2019-02-09 06:36:15 +01:00
2019-02-04 11:32:39 +01:00
@override
Widget build(BuildContext context) {
2020-01-07 08:07:57 +01:00
return ListStatefulScaffold<GhReposRepository, String>(
title: AppBarTitle(title),
fetch: (cursor) async {
2020-10-04 16:10:05 +02:00
final auth = context.read<AuthModel>();
final res = await auth.gqlClient.execute(GhReposQuery(
variables:
GhReposArguments(owner: owner, isStar: isStar, after: cursor)));
final data = res.data.user;
if (isStar) {
return ListPayload(
cursor: data.starredRepositories.pageInfo.endCursor,
items: data.starredRepositories.nodes,
hasMore: data.starredRepositories.pageInfo.hasNextPage,
);
} else {
return ListPayload(
cursor: data.repositories.pageInfo.endCursor,
items: data.repositories.nodes,
hasMore: data.repositories.pageInfo.hasNextPage,
);
}
},
itemBuilder: (v) {
return RepositoryItem.gh(
owner: v.owner.login,
avatarUrl: v.owner.avatarUrl,
name: v.name,
description: v.description,
starCount: v.stargazers.totalCount,
forkCount: v.forks.totalCount,
primaryLanguageName: v.primaryLanguage?.name,
primaryLanguageColor: v.primaryLanguage?.color,
note: 'Updated ${timeago.format(v.updatedAt)}',
isPrivate: v.isPrivate,
isFork: v.isFork,
);
},
);
2019-02-04 11:32:39 +01:00
}
}