1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-16 18:28:51 +01:00

feat: repository count

This commit is contained in:
Rongjian Zhang 2019-09-22 01:56:26 +08:00
parent 1c5b62430e
commit 42debe9bf3
3 changed files with 42 additions and 18 deletions

View File

@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:git_touch/screens/repos.dart';
import 'package:git_touch/screens/users.dart';
import 'package:git_touch/widgets/app_bar_title.dart';
import 'package:git_touch/widgets/entry_item.dart';
@ -21,13 +22,17 @@ class OrganizationScreen extends StatelessWidget {
Iterable<Widget> _buildRepos(payload) {
String title;
List items;
List items = [];
if ((payload['pinnedItems']['nodes'] as List).isNotEmpty) {
var pinnedItems = payload['pinnedItems']['nodes'] as List;
var repositories = payload['pinnableItems']['nodes'] as List;
if (pinnedItems.isNotEmpty) {
title = 'pinned repositories';
items = payload['pinnedItems']['nodes'] as List;
} else {
items = [];
items = pinnedItems;
} else if (repositories.isNotEmpty) {
title = 'popular repositories';
items = repositories;
}
items = items
@ -51,6 +56,7 @@ class OrganizationScreen extends StatelessWidget {
Widget build(BuildContext context) {
return RefreshScaffold(
onRefresh: () async {
// Use pinnableItems instead of organization here due to token permission
var data = await Provider.of<SettingsModel>(context).query('''
{
organization(login: "$login") {
@ -61,13 +67,21 @@ class OrganizationScreen extends StatelessWidget {
email
websiteUrl
url
pinnedItems(first: $pageSize) {
pinnedItems(first: 6) {
nodes {
... on Repository {
$repoChunk
}
}
}
pinnableItems(first: 6, types: [REPOSITORY]) {
totalCount
nodes {
... on Repository {
$repoChunk
}
}
}
membersWithRole {
totalCount
}
@ -105,6 +119,11 @@ class OrganizationScreen extends StatelessWidget {
),
borderView,
Row(children: <Widget>[
EntryItem(
count: payload['pinnableItems']['totalCount'],
text: 'Repositories',
screenBuilder: (context) => ReposScreen(login, org: true),
),
EntryItem(
count: payload['membersWithRole']['totalCount'],
text: 'Members',

View File

@ -6,7 +6,7 @@ import 'package:provider/provider.dart';
import '../utils/utils.dart';
import '../widgets/repo_item.dart';
/// Repos of user
// TODO: refactor
class ReposScreen extends StatelessWidget {
final String login;
final bool star;
@ -15,7 +15,8 @@ class ReposScreen extends StatelessWidget {
ReposScreen(this.login, {this.star = false, this.org = false});
String get scope => org ? 'organization' : 'user';
String get resource => star ? 'starredRepositories' : 'repositories';
String get resource =>
org ? 'pinnableItems' : star ? 'starredRepositories' : 'repositories';
String get fieldOrderBy {
if (star) {
return 'STARRED_AT';
@ -27,18 +28,21 @@ class ReposScreen extends StatelessWidget {
}
Future<ListPayload> _queryRepos(BuildContext context, [String cursor]) async {
var filterChunk = org
? ', types: [REPOSITORY],'
: ', orderBy: {field: $fieldOrderBy, direction: DESC}';
var cursorChunk = cursor == null ? '' : ', after: "$cursor"';
// FIXME: organization scope not work due to permissions
var contentChunk = org ? '''... on Repository { $repoChunk }''' : repoChunk;
var data = await Provider.of<SettingsModel>(context).query('''
{
$scope(login: "$login") {
$resource(first: $pageSize$cursorChunk, orderBy: {field: $fieldOrderBy, direction: DESC}) {
$resource(first: $pageSize$cursorChunk$filterChunk) {
pageInfo {
hasNextPage
endCursor
}
nodes {
$repoChunk
$contentChunk
}
}
}

View File

@ -68,16 +68,17 @@ class UserScreen extends StatelessWidget {
Iterable<Widget> _buildRepos(payload) {
String title;
List items;
List items = [];
if ((payload['pinnedItems']['nodes'] as List).isNotEmpty) {
var pinnedItems = payload['pinnedItems']['nodes'] as List;
var repositories = payload['repositories']['nodes'] as List;
if (pinnedItems.isNotEmpty) {
title = 'pinned repositories';
items = payload['pinnedItems']['nodes'] as List;
} else if ((payload['repositories']['nodes'] as List).isNotEmpty) {
items = pinnedItems;
} else if (repositories.isNotEmpty) {
title = 'popular repositories';
items = payload['repositories']['nodes'] as List;
} else {
items = [];
items = repositories;
}
items = items