1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-17 02:38:39 +01:00
git-touch-android-ios-app/lib/screens/repositories.dart

83 lines
2.7 KiB
Dart
Raw Normal View History

2019-02-04 11:32:39 +01:00
import 'package:flutter/material.dart';
2019-12-07 15:25:37 +01:00
import 'package:git_touch/graphql/github_repositories.dart';
2019-09-25 11:06:36 +02:00
import 'package:git_touch/scaffolds/list_stateful.dart';
2019-12-07 15:25:37 +01:00
import 'package:git_touch/screens/repository.dart';
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-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';
2019-02-04 11:32:39 +01:00
2019-09-23 12:28:33 +02:00
class RepositoriesScreen 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
2019-12-07 15:25:37 +01:00
RepositoriesScreen(this.owner)
: title = 'Repositories',
2019-12-07 15:25:37 +01:00
isStar = false;
RepositoriesScreen.stars(this.owner)
: title = 'Stars',
2019-12-07 15:25:37 +01:00
isStar = true;
2019-02-09 06:36:15 +01:00
2019-12-07 15:25:37 +01:00
Future<ListPayload<GithubRepositoriesRepository, String>> _query(
BuildContext context,
[String cursor]) async {
final res = await Provider.of<AuthModel>(context).gqlClient.execute(
GithubRepositoriesQuery(
variables: GithubRepositoriesArguments(
owner: owner, isStar: isStar, after: cursor)));
final data = res.data.repositoryOwner;
switch (data.resolveType) {
case 'User':
final user = data as GithubRepositoriesUser;
if (isStar) {
return ListPayload(
cursor: user.starredRepositories.pageInfo.endCursor,
items: user.starredRepositories.nodes,
hasMore: user.starredRepositories.pageInfo.hasNextPage,
);
} else {
return ListPayload(
cursor: user.repositories.pageInfo.endCursor,
items: user.repositories.nodes,
hasMore: user.repositories.pageInfo.hasNextPage,
);
}
break;
case 'Organization':
final org = data as GithubRepositoriesOrganization;
return ListPayload(
cursor: org.pinnableItems.pageInfo.endCursor,
items: org.pinnableItems.nodes,
hasMore: org.pinnableItems.pageInfo.hasNextPage,
);
default:
return null;
2019-02-09 06:36:15 +01:00
}
}
2019-02-04 11:32:39 +01:00
@override
Widget build(BuildContext context) {
2019-12-07 15:25:37 +01:00
return ListStatefulScaffold<GithubRepositoriesRepository, String>(
title: AppBarTitle(title),
onRefresh: () => _query(context),
onLoadMore: (cursor) => _query(context, cursor),
itemBuilder: (item) {
return RepositoryItem.raw(
item.owner.login,
item.owner.avatarUrl,
item.name,
item.description,
Octicons.repo,
item.stargazers.totalCount,
item.forks.totalCount,
item.primaryLanguage?.name,
item.primaryLanguage?.color,
(_) => RepositoryScreen(item.owner.login, item.name),
[],
);
});
2019-02-04 11:32:39 +01:00
}
}