mirror of
https://github.com/git-touch/git-touch
synced 2025-01-31 08:04:51 +01:00
feat: add trending developers
This commit is contained in:
parent
09c1ded405
commit
91d6a4b2a3
@ -7,7 +7,7 @@ import '../widgets/error_reload.dart';
|
||||
|
||||
class TabScaffold<T> extends StatefulWidget {
|
||||
final Widget title;
|
||||
final Widget Function(T payload) bodyBuilder;
|
||||
final Widget Function(T payload, int activeTab) bodyBuilder;
|
||||
final Future<T> Function(int activeTab) onRefresh;
|
||||
final List<String> tabs;
|
||||
final Widget Function(T payload) trailingBuilder;
|
||||
@ -73,7 +73,7 @@ class _TabScaffoldState<T> extends State<TabScaffold<T>> {
|
||||
} else if (_payload == null) {
|
||||
return Loading(more: false);
|
||||
} else {
|
||||
return widget.bodyBuilder(_payload);
|
||||
return widget.bodyBuilder(_payload, _activeTab);
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,12 +96,12 @@ class _TabScaffoldState<T> extends State<TabScaffold<T>> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _switch(int selected)async {
|
||||
Future<void> _switch(int selected) async {
|
||||
setState(() {
|
||||
_activeTab = selected;
|
||||
});
|
||||
if (_getPayload(selected) == null) {
|
||||
await _refresh();
|
||||
await _refresh();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -181,15 +181,17 @@ $key: pullRequest(number: ${item.number}) {
|
||||
},
|
||||
),
|
||||
onRefresh: fetchNotifications,
|
||||
bodyBuilder: (groupMap) {
|
||||
return groupMap.isEmpty
|
||||
? EmptyWidget()
|
||||
: Column(children: [
|
||||
Padding(padding: EdgeInsets.only(top: 10)),
|
||||
...groupMap.entries
|
||||
.map((entry) => _buildGroupItem(context, entry, groupMap))
|
||||
.toList()
|
||||
]);
|
||||
bodyBuilder: (groupMap, activeTab) {
|
||||
if (groupMap.isEmpty) return EmptyWidget();
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
Padding(padding: EdgeInsets.only(top: 10)),
|
||||
...groupMap.entries
|
||||
.map((entry) => _buildGroupItem(context, entry, groupMap))
|
||||
.toList()
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -1,53 +1,65 @@
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:git_touch/scaffolds/tab.dart';
|
||||
import 'package:git_touch/utils/utils.dart';
|
||||
import 'package:git_touch/widgets/app_bar_title.dart';
|
||||
import 'package:git_touch/widgets/user_item.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import '../scaffolds/refresh.dart';
|
||||
import 'package:git_touch/widgets/repository_item.dart';
|
||||
|
||||
class TrendingScreen extends StatefulWidget {
|
||||
@override
|
||||
_TrendingScreenState createState() => _TrendingScreenState();
|
||||
}
|
||||
|
||||
class _TrendingScreenState extends State<TrendingScreen> {
|
||||
@override
|
||||
class TrendingScreen extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return RefreshScaffold(
|
||||
return TabScaffold(
|
||||
title: AppBarTitle('Trending'),
|
||||
onRefresh: (_) async {
|
||||
var res = await http.get('https://github-trending-api.now.sh');
|
||||
var items = json.decode(res.body);
|
||||
|
||||
return items.map((item) {
|
||||
return {
|
||||
'owner': {'login': item['author'], 'avatarUrl': item['avatar']},
|
||||
'name': item['name'],
|
||||
'description': item['description'],
|
||||
'stargazers': {
|
||||
'totalCount': item['stars'],
|
||||
},
|
||||
'forks': {
|
||||
'totalCount': item['forks'],
|
||||
},
|
||||
'primaryLanguage': item['language'] == null
|
||||
? null
|
||||
: {
|
||||
'name': item['language'],
|
||||
'color': item['languageColor'],
|
||||
},
|
||||
'isPrivate': false,
|
||||
'isFork': false // TODO:
|
||||
};
|
||||
}).toList();
|
||||
tabs: ['Repositories', 'Users'],
|
||||
onRefresh: (tabIndex) async {
|
||||
var uri = Uri.parse('https://github-trending-api.now.sh')
|
||||
.resolve(tabIndex == 1 ? '/developers' : '/');
|
||||
var res = await http.get(uri);
|
||||
var items = json.decode(res.body) as List;
|
||||
return items;
|
||||
},
|
||||
bodyBuilder: (payload) {
|
||||
bodyBuilder: (payload, activeTab) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: join(
|
||||
borderView,
|
||||
payload.map<Widget>((item) => RepositoryItem(item)).toList(),
|
||||
payload.map<Widget>((item) {
|
||||
switch (activeTab) {
|
||||
case 0:
|
||||
return RepositoryItem({
|
||||
'owner': {
|
||||
'login': item['author'],
|
||||
'avatarUrl': item['avatar']
|
||||
},
|
||||
'name': item['name'],
|
||||
'description': item['description'],
|
||||
'stargazers': {
|
||||
'totalCount': item['stars'],
|
||||
},
|
||||
'forks': {
|
||||
'totalCount': item['forks'],
|
||||
},
|
||||
'primaryLanguage': item['language'] == null
|
||||
? null
|
||||
: {
|
||||
'name': item['language'],
|
||||
'color': item['languageColor'],
|
||||
},
|
||||
'isPrivate': false,
|
||||
'isFork': false // TODO:
|
||||
});
|
||||
case 1:
|
||||
return UserItem(
|
||||
item['username'],
|
||||
name: item['name'],
|
||||
avatarUrl: item['avatar'],
|
||||
bio: '',
|
||||
);
|
||||
default:
|
||||
throw '';
|
||||
}
|
||||
}).toList(),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user