mirror of
https://github.com/git-touch/git-touch
synced 2024-12-17 18:59:23 +01:00
feat: repository count
This commit is contained in:
parent
1c5b62430e
commit
42debe9bf3
@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:git_touch/screens/repos.dart';
|
||||||
import 'package:git_touch/screens/users.dart';
|
import 'package:git_touch/screens/users.dart';
|
||||||
import 'package:git_touch/widgets/app_bar_title.dart';
|
import 'package:git_touch/widgets/app_bar_title.dart';
|
||||||
import 'package:git_touch/widgets/entry_item.dart';
|
import 'package:git_touch/widgets/entry_item.dart';
|
||||||
@ -21,13 +22,17 @@ class OrganizationScreen extends StatelessWidget {
|
|||||||
|
|
||||||
Iterable<Widget> _buildRepos(payload) {
|
Iterable<Widget> _buildRepos(payload) {
|
||||||
String title;
|
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';
|
title = 'pinned repositories';
|
||||||
items = payload['pinnedItems']['nodes'] as List;
|
items = pinnedItems;
|
||||||
} else {
|
} else if (repositories.isNotEmpty) {
|
||||||
items = [];
|
title = 'popular repositories';
|
||||||
|
items = repositories;
|
||||||
}
|
}
|
||||||
|
|
||||||
items = items
|
items = items
|
||||||
@ -51,6 +56,7 @@ class OrganizationScreen extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return RefreshScaffold(
|
return RefreshScaffold(
|
||||||
onRefresh: () async {
|
onRefresh: () async {
|
||||||
|
// Use pinnableItems instead of organization here due to token permission
|
||||||
var data = await Provider.of<SettingsModel>(context).query('''
|
var data = await Provider.of<SettingsModel>(context).query('''
|
||||||
{
|
{
|
||||||
organization(login: "$login") {
|
organization(login: "$login") {
|
||||||
@ -61,7 +67,15 @@ class OrganizationScreen extends StatelessWidget {
|
|||||||
email
|
email
|
||||||
websiteUrl
|
websiteUrl
|
||||||
url
|
url
|
||||||
pinnedItems(first: $pageSize) {
|
pinnedItems(first: 6) {
|
||||||
|
nodes {
|
||||||
|
... on Repository {
|
||||||
|
$repoChunk
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pinnableItems(first: 6, types: [REPOSITORY]) {
|
||||||
|
totalCount
|
||||||
nodes {
|
nodes {
|
||||||
... on Repository {
|
... on Repository {
|
||||||
$repoChunk
|
$repoChunk
|
||||||
@ -105,6 +119,11 @@ class OrganizationScreen extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
borderView,
|
borderView,
|
||||||
Row(children: <Widget>[
|
Row(children: <Widget>[
|
||||||
|
EntryItem(
|
||||||
|
count: payload['pinnableItems']['totalCount'],
|
||||||
|
text: 'Repositories',
|
||||||
|
screenBuilder: (context) => ReposScreen(login, org: true),
|
||||||
|
),
|
||||||
EntryItem(
|
EntryItem(
|
||||||
count: payload['membersWithRole']['totalCount'],
|
count: payload['membersWithRole']['totalCount'],
|
||||||
text: 'Members',
|
text: 'Members',
|
||||||
|
@ -6,7 +6,7 @@ import 'package:provider/provider.dart';
|
|||||||
import '../utils/utils.dart';
|
import '../utils/utils.dart';
|
||||||
import '../widgets/repo_item.dart';
|
import '../widgets/repo_item.dart';
|
||||||
|
|
||||||
/// Repos of user
|
// TODO: refactor
|
||||||
class ReposScreen extends StatelessWidget {
|
class ReposScreen extends StatelessWidget {
|
||||||
final String login;
|
final String login;
|
||||||
final bool star;
|
final bool star;
|
||||||
@ -15,7 +15,8 @@ class ReposScreen extends StatelessWidget {
|
|||||||
ReposScreen(this.login, {this.star = false, this.org = false});
|
ReposScreen(this.login, {this.star = false, this.org = false});
|
||||||
|
|
||||||
String get scope => org ? 'organization' : 'user';
|
String get scope => org ? 'organization' : 'user';
|
||||||
String get resource => star ? 'starredRepositories' : 'repositories';
|
String get resource =>
|
||||||
|
org ? 'pinnableItems' : star ? 'starredRepositories' : 'repositories';
|
||||||
String get fieldOrderBy {
|
String get fieldOrderBy {
|
||||||
if (star) {
|
if (star) {
|
||||||
return 'STARRED_AT';
|
return 'STARRED_AT';
|
||||||
@ -27,18 +28,21 @@ class ReposScreen extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<ListPayload> _queryRepos(BuildContext context, [String cursor]) async {
|
Future<ListPayload> _queryRepos(BuildContext context, [String cursor]) async {
|
||||||
|
var filterChunk = org
|
||||||
|
? ', types: [REPOSITORY],'
|
||||||
|
: ', orderBy: {field: $fieldOrderBy, direction: DESC}';
|
||||||
var cursorChunk = cursor == null ? '' : ', after: "$cursor"';
|
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('''
|
var data = await Provider.of<SettingsModel>(context).query('''
|
||||||
{
|
{
|
||||||
$scope(login: "$login") {
|
$scope(login: "$login") {
|
||||||
$resource(first: $pageSize$cursorChunk, orderBy: {field: $fieldOrderBy, direction: DESC}) {
|
$resource(first: $pageSize$cursorChunk$filterChunk) {
|
||||||
pageInfo {
|
pageInfo {
|
||||||
hasNextPage
|
hasNextPage
|
||||||
endCursor
|
endCursor
|
||||||
}
|
}
|
||||||
nodes {
|
nodes {
|
||||||
$repoChunk
|
$contentChunk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,16 +68,17 @@ class UserScreen extends StatelessWidget {
|
|||||||
|
|
||||||
Iterable<Widget> _buildRepos(payload) {
|
Iterable<Widget> _buildRepos(payload) {
|
||||||
String title;
|
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';
|
title = 'pinned repositories';
|
||||||
items = payload['pinnedItems']['nodes'] as List;
|
items = pinnedItems;
|
||||||
} else if ((payload['repositories']['nodes'] as List).isNotEmpty) {
|
} else if (repositories.isNotEmpty) {
|
||||||
title = 'popular repositories';
|
title = 'popular repositories';
|
||||||
items = payload['repositories']['nodes'] as List;
|
items = repositories;
|
||||||
} else {
|
|
||||||
items = [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
items = items
|
items = items
|
||||||
|
Loading…
Reference in New Issue
Block a user