fix: pinnable item

This commit is contained in:
Rongjian Zhang 2019-10-06 15:50:22 +08:00
parent 7de4f1f78c
commit e989ad9715
3 changed files with 35 additions and 66 deletions

View File

@ -18,38 +18,6 @@ class OrganizationScreen extends StatelessWidget {
OrganizationScreen(this.login); OrganizationScreen(this.login);
Iterable<Widget> _buildRepos(payload) {
String title;
List items = [];
var pinnedItems = payload['pinnedItems']['nodes'] as List;
var repositories = payload['pinnableItems']['nodes'] as List;
if (pinnedItems.isNotEmpty) {
title = 'pinned repositories';
items = pinnedItems;
} else if (repositories.isNotEmpty) {
title = 'popular repositories';
items = repositories;
}
items = items
.where((x) => x != null)
.toList(); // TODO: Pinned items may include somethings other than repo
if (items.isEmpty) return [];
return [
CommonStyle.verticalGap,
if (title != null) TableViewHeader(title),
...join(
CommonStyle.border,
items.map((item) {
return RepositoryItem(item);
}).toList(),
)
];
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return RefreshStatefulScaffold( return RefreshStatefulScaffold(
@ -162,7 +130,8 @@ class OrganizationScreen extends StatelessWidget {
), ),
], ],
), ),
..._buildRepos(data), ...buildPinnedItems(
data['pinnedItems']['nodes'], data['pinnableItems']['nodes']),
], ],
); );
}, },

View File

@ -65,38 +65,6 @@ class UserScreen extends StatelessWidget {
return data['user']; return data['user'];
} }
Iterable<Widget> _buildRepos(payload) {
String title;
List items = [];
var pinnedItems = payload['pinnedItems']['nodes'] as List;
var repositories = payload['repositories']['nodes'] as List;
if (pinnedItems.isNotEmpty) {
title = 'pinned repositories';
items = pinnedItems;
} else if (repositories.isNotEmpty) {
title = 'popular repositories';
items = repositories;
}
items = items
.where((x) => x != null)
.toList(); // TODO: Pinned items may include somethings other than repo
if (items.isEmpty) return [];
return [
CommonStyle.verticalGap,
if (title != null) TableViewHeader(title),
...join(
CommonStyle.border,
items.map((item) {
return RepositoryItem(item);
}).toList(),
),
];
}
Widget _buildContributions(List<ContributionsInfo> contributions) { Widget _buildContributions(List<ContributionsInfo> contributions) {
final row = Row( final row = Row(
children: <Widget>[], children: <Widget>[],
@ -260,7 +228,8 @@ class UserScreen extends StatelessWidget {
), ),
], ],
), ),
..._buildRepos(data), ...buildPinnedItems(
data['pinnedItems']['nodes'], data['repositories']['nodes']),
CommonStyle.verticalGap, CommonStyle.verticalGap,
], ],
); );

View File

@ -6,6 +6,8 @@ import 'package:git_touch/models/theme.dart';
import 'package:git_touch/screens/repository.dart'; import 'package:git_touch/screens/repository.dart';
import 'package:git_touch/screens/user.dart'; import 'package:git_touch/screens/user.dart';
import 'package:git_touch/widgets/border_view.dart'; import 'package:git_touch/widgets/border_view.dart';
import 'package:git_touch/widgets/repository_item.dart';
import 'package:git_touch/widgets/table_view.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:primer/primer.dart'; import 'package:primer/primer.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
@ -173,3 +175,32 @@ launchUrl(String url) async {
// TODO: fallback // TODO: fallback
} }
} }
Iterable<Widget> buildPinnedItems(List pinnedItems, List repositories) {
String title;
List items = [];
if (pinnedItems.isNotEmpty) {
title = 'pinned repositories';
items = pinnedItems;
} else if (repositories.isNotEmpty) {
title = 'popular repositories';
items = repositories;
}
items = items
.where((x) => x.isNotEmpty)
.toList(); // TODO: Pinned items may include Gist
if (items.isEmpty) return [];
return [
CommonStyle.verticalGap,
if (title != null) TableViewHeader(title),
...join(
CommonStyle.border,
items.map((item) {
return RepositoryItem(item);
}).toList(),
),
];
}