mirror of
https://github.com/git-touch/git-touch
synced 2025-01-31 08:04:51 +01:00
fix: users star or watch repo
This commit is contained in:
parent
70f83df1fe
commit
df485edcd4
@ -194,8 +194,8 @@ class _OrganizationScreenState extends State<OrganizationScreen> {
|
|||||||
EntryItem(
|
EntryItem(
|
||||||
count: payload['membersWithRole']['totalCount'],
|
count: payload['membersWithRole']['totalCount'],
|
||||||
text: 'Members',
|
text: 'Members',
|
||||||
screenBuilder: (_) =>
|
screenBuilder: (_) => UsersScreen(
|
||||||
UsersScreen(login: widget.login, org: true),
|
login: widget.login, type: UsersScreenType.orgs),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -180,18 +180,25 @@ class RepoScreen extends StatelessWidget {
|
|||||||
EntryItem(
|
EntryItem(
|
||||||
count: payload['watchers']['totalCount'],
|
count: payload['watchers']['totalCount'],
|
||||||
text: 'Watchers',
|
text: 'Watchers',
|
||||||
screenBuilder: (context) =>
|
screenBuilder: (context) => UsersScreen(
|
||||||
UsersScreen(login: 'pd4d10'), // FIXME:
|
login: owner,
|
||||||
|
name: name,
|
||||||
|
type: UsersScreenType.repoWatchers,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
EntryItem(
|
EntryItem(
|
||||||
count: payload['stargazers']['totalCount'],
|
count: payload['stargazers']['totalCount'],
|
||||||
text: 'Stars',
|
text: 'Stars',
|
||||||
screenBuilder: (context) => UsersScreen(login: 'pd4d10'),
|
screenBuilder: (context) => UsersScreen(
|
||||||
|
login: owner,
|
||||||
|
name: name,
|
||||||
|
type: UsersScreenType.repoStars,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
EntryItem(
|
EntryItem(
|
||||||
count: payload['forks']['totalCount'],
|
count: payload['forks']['totalCount'],
|
||||||
text: 'Forks',
|
text: 'Forks',
|
||||||
screenBuilder: (context) => UsersScreen(login: 'pd4d10'),
|
// screenBuilder: (context) => UsersScreen(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -20,18 +20,13 @@ import '../screens/users.dart';
|
|||||||
import '../screens/settings.dart';
|
import '../screens/settings.dart';
|
||||||
import '../utils/utils.dart';
|
import '../utils/utils.dart';
|
||||||
|
|
||||||
class UserScreen extends StatefulWidget {
|
class UserScreen extends StatelessWidget {
|
||||||
final String login;
|
final String login;
|
||||||
final bool showSettings;
|
final bool showSettings;
|
||||||
|
|
||||||
UserScreen(this.login, {this.showSettings = false});
|
UserScreen(this.login, {this.showSettings = false});
|
||||||
|
|
||||||
_UserScreenState createState() => _UserScreenState();
|
Future query(BuildContext context) async {
|
||||||
}
|
|
||||||
|
|
||||||
class _UserScreenState extends State<UserScreen> {
|
|
||||||
Future query() async {
|
|
||||||
var login = widget.login;
|
|
||||||
var data = await Provider.of<SettingsModel>(context).query('''
|
var data = await Provider.of<SettingsModel>(context).query('''
|
||||||
{
|
{
|
||||||
user(login: "$login") {
|
user(login: "$login") {
|
||||||
@ -161,13 +156,13 @@ class _UserScreenState extends State<UserScreen> {
|
|||||||
return RefreshScaffold(
|
return RefreshScaffold(
|
||||||
onRefresh: () {
|
onRefresh: () {
|
||||||
return Future.wait(
|
return Future.wait(
|
||||||
[query(), getContributions(widget.login)],
|
[query(context), getContributions(login)],
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
title: AppBarTitle('User'),
|
title: AppBarTitle('User'),
|
||||||
trailingBuilder: (data) {
|
trailingBuilder: (data) {
|
||||||
var payload = data[0];
|
var payload = data[0];
|
||||||
if (widget.showSettings) {
|
if (showSettings) {
|
||||||
return Link(
|
return Link(
|
||||||
child: Icon(Icons.settings, size: 24),
|
child: Icon(Icons.settings, size: 24),
|
||||||
screenBuilder: (_) => SettingsScreen(),
|
screenBuilder: (_) => SettingsScreen(),
|
||||||
@ -183,11 +178,11 @@ class _UserScreenState extends State<UserScreen> {
|
|||||||
onPress: () async {
|
onPress: () async {
|
||||||
if (payload['viewerIsFollowing']) {
|
if (payload['viewerIsFollowing']) {
|
||||||
await Provider.of<SettingsModel>(context)
|
await Provider.of<SettingsModel>(context)
|
||||||
.deleteWithCredentials('/user/following/${widget.login}');
|
.deleteWithCredentials('/user/following/$login');
|
||||||
payload['viewerIsFollowing'] = false;
|
payload['viewerIsFollowing'] = false;
|
||||||
} else {
|
} else {
|
||||||
Provider.of<SettingsModel>(context)
|
Provider.of<SettingsModel>(context)
|
||||||
.putWithCredentials('/user/following/${widget.login}');
|
.putWithCredentials('/user/following/$login');
|
||||||
payload['viewerIsFollowing'] = true;
|
payload['viewerIsFollowing'] = true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -234,7 +229,7 @@ class _UserScreenState extends State<UserScreen> {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.end,
|
crossAxisAlignment: CrossAxisAlignment.end,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Text(
|
Text(
|
||||||
payload['name'] ?? widget.login,
|
payload['name'] ?? login,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: PrimerColors.blue500,
|
color: PrimerColors.blue500,
|
||||||
fontSize: 18,
|
fontSize: 18,
|
||||||
@ -243,7 +238,7 @@ class _UserScreenState extends State<UserScreen> {
|
|||||||
),
|
),
|
||||||
SizedBox(width: 8),
|
SizedBox(width: 8),
|
||||||
Text(
|
Text(
|
||||||
widget.login,
|
login,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: PrimerColors.gray700, fontSize: 16),
|
color: PrimerColors.gray700, fontSize: 16),
|
||||||
),
|
),
|
||||||
@ -271,24 +266,25 @@ class _UserScreenState extends State<UserScreen> {
|
|||||||
EntryItem(
|
EntryItem(
|
||||||
count: payload['repositories']['totalCount'],
|
count: payload['repositories']['totalCount'],
|
||||||
text: 'Repositories',
|
text: 'Repositories',
|
||||||
screenBuilder: (context) => ReposScreen(login: widget.login),
|
screenBuilder: (context) => ReposScreen(login: login),
|
||||||
),
|
),
|
||||||
EntryItem(
|
EntryItem(
|
||||||
count: payload['starredRepositories']['totalCount'],
|
count: payload['starredRepositories']['totalCount'],
|
||||||
text: 'Stars',
|
text: 'Stars',
|
||||||
screenBuilder: (context) =>
|
screenBuilder: (context) =>
|
||||||
ReposScreen(login: widget.login, star: true),
|
ReposScreen(login: login, star: true),
|
||||||
),
|
),
|
||||||
EntryItem(
|
EntryItem(
|
||||||
count: payload['followers']['totalCount'],
|
count: payload['followers']['totalCount'],
|
||||||
text: 'Followers',
|
text: 'Followers',
|
||||||
screenBuilder: (context) => UsersScreen(login: widget.login),
|
screenBuilder: (context) => UsersScreen(
|
||||||
|
login: login, type: UsersScreenType.userFollowers),
|
||||||
),
|
),
|
||||||
EntryItem(
|
EntryItem(
|
||||||
count: payload['following']['totalCount'],
|
count: payload['following']['totalCount'],
|
||||||
text: 'Following',
|
text: 'Following',
|
||||||
screenBuilder: (context) =>
|
screenBuilder: (context) => UsersScreen(
|
||||||
UsersScreen(login: widget.login, following: true),
|
login: login, type: UsersScreenType.userFollowing),
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
BorderView(height: 10),
|
BorderView(height: 10),
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:git_touch/widgets/app_bar_title.dart';
|
import 'package:git_touch/widgets/app_bar_title.dart';
|
||||||
import 'package:primer/primer.dart';
|
import 'package:primer/primer.dart';
|
||||||
|
import 'package:tuple/tuple.dart';
|
||||||
import '../scaffolds/list.dart';
|
import '../scaffolds/list.dart';
|
||||||
import 'package:git_touch/models/settings.dart';
|
import 'package:git_touch/models/settings.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
@ -9,40 +10,52 @@ import '../widgets/link.dart';
|
|||||||
import '../screens/user.dart';
|
import '../screens/user.dart';
|
||||||
import '../widgets/avatar.dart';
|
import '../widgets/avatar.dart';
|
||||||
|
|
||||||
class UsersScreen extends StatefulWidget {
|
enum UsersScreenType {
|
||||||
final String login;
|
userFollowing,
|
||||||
final bool following;
|
userFollowers,
|
||||||
final bool org;
|
repoStars,
|
||||||
|
repoWatchers,
|
||||||
UsersScreen({
|
orgs,
|
||||||
@required this.login,
|
|
||||||
this.following = false,
|
|
||||||
this.org = false,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
_UsersScreenState createState() => _UsersScreenState();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class _UsersScreenState extends State<UsersScreen> {
|
class UsersScreen extends StatelessWidget {
|
||||||
String get login => widget.login;
|
final UsersScreenType type;
|
||||||
String get scope => widget.org ? 'organization' : 'user';
|
final String login;
|
||||||
String get resource {
|
final String name;
|
||||||
if (widget.org) {
|
|
||||||
return 'members';
|
UsersScreen({
|
||||||
|
@required this.type,
|
||||||
|
@required this.login,
|
||||||
|
this.name,
|
||||||
|
});
|
||||||
|
|
||||||
|
Tuple3<String, String, String> get queryKeys {
|
||||||
|
switch (type) {
|
||||||
|
case UsersScreenType.userFollowing:
|
||||||
|
return Tuple3('user', 'login: "$login"', 'following');
|
||||||
|
case UsersScreenType.userFollowers:
|
||||||
|
return Tuple3('user', 'login: "$login"', 'followers');
|
||||||
|
case UsersScreenType.repoStars:
|
||||||
|
return Tuple3(
|
||||||
|
'repository', 'owner: "$login", name: "$name"', 'stargazers');
|
||||||
|
case UsersScreenType.repoWatchers:
|
||||||
|
return Tuple3(
|
||||||
|
'repository', 'owner: "$login", name: "$name"', 'watchers');
|
||||||
|
case UsersScreenType.orgs:
|
||||||
|
return Tuple3('', '', ''); // FIXME:
|
||||||
|
default:
|
||||||
|
throw 'Should not be here';
|
||||||
}
|
}
|
||||||
if (widget.following) {
|
|
||||||
return 'following';
|
|
||||||
}
|
|
||||||
return 'followers';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<ListPayload> _queryUsers([String cursor]) async {
|
Future<ListPayload> _queryUsers(BuildContext context, [String cursor]) async {
|
||||||
var cursorChunk = cursor == null ? '' : ', after: "$cursor"';
|
var cursorChunk = cursor == null ? '' : ', after: "$cursor"';
|
||||||
|
var scope = queryKeys.item1;
|
||||||
|
var params = queryKeys.item2;
|
||||||
|
var resource = queryKeys.item3;
|
||||||
var data = await Provider.of<SettingsModel>(context).query('''
|
var data = await Provider.of<SettingsModel>(context).query('''
|
||||||
{
|
{
|
||||||
$scope(login: "$login") {
|
$scope($params) {
|
||||||
$resource(first: $pageSize$cursorChunk) {
|
$resource(first: $pageSize$cursorChunk) {
|
||||||
pageInfo {
|
pageInfo {
|
||||||
hasNextPage
|
hasNextPage
|
||||||
@ -104,9 +117,9 @@ class _UsersScreenState extends State<UsersScreen> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ListScaffold(
|
return ListScaffold(
|
||||||
title: AppBarTitle(resource),
|
title: AppBarTitle('Users'),
|
||||||
onRefresh: () => _queryUsers(),
|
onRefresh: () => _queryUsers(context),
|
||||||
onLoadMore: (cursor) => _queryUsers(cursor),
|
onLoadMore: (cursor) => _queryUsers(context, cursor),
|
||||||
itemBuilder: _buildItem,
|
itemBuilder: _buildItem,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ dependencies:
|
|||||||
provider: ^3.1.0
|
provider: ^3.1.0
|
||||||
seti: ^0.2.0
|
seti: ^0.2.0
|
||||||
filesize: ^1.0.4
|
filesize: ^1.0.4
|
||||||
|
tuple: ^1.0.2
|
||||||
primer:
|
primer:
|
||||||
git:
|
git:
|
||||||
url: git://github.com/pd4d10/primer-flutter
|
url: git://github.com/pd4d10/primer-flutter
|
||||||
|
Loading…
x
Reference in New Issue
Block a user