feat(gitea): orgs screen
This commit is contained in:
parent
5aa7483c90
commit
336ff4960e
|
@ -3,6 +3,7 @@ import 'package:flutter/cupertino.dart';
|
|||
import 'package:git_touch/models/auth.dart';
|
||||
import 'package:git_touch/models/notification.dart';
|
||||
import 'package:git_touch/models/theme.dart';
|
||||
import 'package:git_touch/screens/gitea_orgs.dart';
|
||||
import 'package:git_touch/screens/gitea_user.dart';
|
||||
import 'package:git_touch/screens/gitlab_explore.dart';
|
||||
import 'package:git_touch/screens/gitlab_groups.dart';
|
||||
|
@ -62,7 +63,7 @@ class _HomeState extends State<Home> {
|
|||
case PlatformType.gitea:
|
||||
switch (index) {
|
||||
case 0:
|
||||
return GiteaUserScreen(null);
|
||||
return GiteaOrgsScreen();
|
||||
case 1:
|
||||
return GiteaUserScreen(null);
|
||||
}
|
||||
|
@ -136,12 +137,8 @@ class _HomeState extends State<Home> {
|
|||
case PlatformType.gitea:
|
||||
return [
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.explore),
|
||||
title: Text('Explore'),
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.explore),
|
||||
title: Text('Groups'),
|
||||
icon: Icon(Icons.group),
|
||||
title: Text('Organizations'),
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.person),
|
||||
|
|
|
@ -14,6 +14,18 @@ class GiteaUser {
|
|||
_$GiteaUserFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable(fieldRename: FieldRename.snake)
|
||||
class GiteaOrg {
|
||||
int id;
|
||||
String username;
|
||||
String fullName;
|
||||
String avatarUrl;
|
||||
String description;
|
||||
GiteaOrg();
|
||||
factory GiteaOrg.fromJson(Map<String, dynamic> json) =>
|
||||
_$GiteaOrgFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable(fieldRename: FieldRename.snake)
|
||||
class GiteaRepository {
|
||||
int id;
|
||||
|
|
|
@ -25,6 +25,23 @@ Map<String, dynamic> _$GiteaUserToJson(GiteaUser instance) => <String, dynamic>{
|
|||
'created': instance.created?.toIso8601String(),
|
||||
};
|
||||
|
||||
GiteaOrg _$GiteaOrgFromJson(Map<String, dynamic> json) {
|
||||
return GiteaOrg()
|
||||
..id = json['id'] as int
|
||||
..username = json['username'] as String
|
||||
..fullName = json['full_name'] as String
|
||||
..avatarUrl = json['avatar_url'] as String
|
||||
..description = json['description'] as String;
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$GiteaOrgToJson(GiteaOrg instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'username': instance.username,
|
||||
'full_name': instance.fullName,
|
||||
'avatar_url': instance.avatarUrl,
|
||||
'description': instance.description,
|
||||
};
|
||||
|
||||
GiteaRepository _$GiteaRepositoryFromJson(Map<String, dynamic> json) {
|
||||
return GiteaRepository()
|
||||
..id = json['id'] as int
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:git_touch/models/auth.dart';
|
||||
import 'package:git_touch/models/gitea.dart';
|
||||
import 'package:git_touch/scaffolds/list_stateful.dart';
|
||||
import 'package:git_touch/widgets/app_bar_title.dart';
|
||||
import 'package:git_touch/widgets/user_item.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class GiteaOrgsScreen extends StatelessWidget {
|
||||
// final String branch; // TODO:
|
||||
Future<ListPayload<GiteaOrg, int>> _query(BuildContext context,
|
||||
[int page = 1]) async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final res = await auth.fetchGiteaWithPage('/orgs?limit=20');
|
||||
return ListPayload(
|
||||
cursor: res.cursor,
|
||||
hasMore: res.hasMore,
|
||||
items: (res.data as List).map((v) => GiteaOrg.fromJson(v)).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListStatefulScaffold<GiteaOrg, int>(
|
||||
title: AppBarTitle('Organizations'),
|
||||
onRefresh: () => _query(context),
|
||||
onLoadMore: (cursor) => _query(context, cursor),
|
||||
itemBuilder: (v) {
|
||||
return UserItem(
|
||||
avatarUrl: v.avatarUrl,
|
||||
login: v.username,
|
||||
bio: Text(v.description ?? ''),
|
||||
url: '',
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
|
@ -23,7 +23,7 @@ class GitlabGroups extends StatelessWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListStatefulScaffold<GitlabGroup, int>(
|
||||
title: AppBarTitle('Explore'),
|
||||
title: AppBarTitle('Groups'),
|
||||
onRefresh: () => _query(context),
|
||||
onLoadMore: (page) => _query(context, page),
|
||||
itemBuilder: (v) {
|
||||
|
|
Loading…
Reference in New Issue