mirror of
https://github.com/git-touch/git-touch
synced 2024-12-15 17:59:35 +01:00
feat(gitlab): explore screen
This commit is contained in:
parent
c583257867
commit
62c4c380f8
@ -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/gitlab_explore.dart';
|
||||
import 'package:git_touch/screens/gitlab_project.dart';
|
||||
import 'package:git_touch/screens/gitlab_todos.dart';
|
||||
import 'package:git_touch/screens/gitlab_user.dart';
|
||||
@ -49,7 +50,7 @@ class _HomeState extends State<Home> {
|
||||
case PlatformType.gitlab:
|
||||
switch (index) {
|
||||
case 0:
|
||||
return GitlabTodosScreen();
|
||||
return GitlabExplore();
|
||||
case 1:
|
||||
return GitlabUserScreen(null);
|
||||
}
|
||||
@ -108,12 +109,11 @@ class _HomeState extends State<Home> {
|
||||
case PlatformType.gitlab:
|
||||
return [
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.timeline),
|
||||
title: Text('Todos'),
|
||||
icon: Icon(Icons.explore),
|
||||
title: Text('Explore'),
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.person_outline),
|
||||
activeIcon: Icon(Icons.person),
|
||||
icon: Icon(Icons.person),
|
||||
title: Text('Me'),
|
||||
),
|
||||
];
|
||||
|
@ -98,6 +98,7 @@ class GitlabProject {
|
||||
int openIssuesCount;
|
||||
bool mergeRequestsEnabled;
|
||||
GitlabProjectStatistics statistics;
|
||||
DateTime lastActivityAt;
|
||||
GitlabProject();
|
||||
factory GitlabProject.fromJson(Map<String, dynamic> json) =>
|
||||
_$GitlabProjectFromJson(json);
|
||||
@ -124,6 +125,7 @@ class GitlabProjectStatistics {
|
||||
class GitlabProjectNamespace {
|
||||
int id;
|
||||
String name;
|
||||
String path;
|
||||
GitlabProjectNamespace();
|
||||
|
||||
factory GitlabProjectNamespace.fromJson(Map<String, dynamic> json) =>
|
||||
|
@ -147,7 +147,10 @@ GitlabProject _$GitlabProjectFromJson(Map<String, dynamic> json) {
|
||||
..statistics = json['statistics'] == null
|
||||
? null
|
||||
: GitlabProjectStatistics.fromJson(
|
||||
json['statistics'] as Map<String, dynamic>);
|
||||
json['statistics'] as Map<String, dynamic>)
|
||||
..lastActivityAt = json['last_activity_at'] == null
|
||||
? null
|
||||
: DateTime.parse(json['last_activity_at'] as String);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$GitlabProjectToJson(GitlabProject instance) =>
|
||||
@ -166,6 +169,7 @@ Map<String, dynamic> _$GitlabProjectToJson(GitlabProject instance) =>
|
||||
'open_issues_count': instance.openIssuesCount,
|
||||
'merge_requests_enabled': instance.mergeRequestsEnabled,
|
||||
'statistics': instance.statistics,
|
||||
'last_activity_at': instance.lastActivityAt?.toIso8601String(),
|
||||
};
|
||||
|
||||
GitlabProjectBadge _$GitlabProjectBadgeFromJson(Map<String, dynamic> json) {
|
||||
@ -196,7 +200,8 @@ GitlabProjectNamespace _$GitlabProjectNamespaceFromJson(
|
||||
Map<String, dynamic> json) {
|
||||
return GitlabProjectNamespace()
|
||||
..id = json['id'] as int
|
||||
..name = json['name'] as String;
|
||||
..name = json['name'] as String
|
||||
..path = json['path'] as String;
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$GitlabProjectNamespaceToJson(
|
||||
@ -204,6 +209,7 @@ Map<String, dynamic> _$GitlabProjectNamespaceToJson(
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'name': instance.name,
|
||||
'path': instance.path,
|
||||
};
|
||||
|
||||
GitlabTreeItem _$GitlabTreeItemFromJson(Map<String, dynamic> json) {
|
||||
|
@ -14,7 +14,11 @@ class ListPayload<T, K> {
|
||||
List<T> items;
|
||||
bool hasMore;
|
||||
|
||||
ListPayload({this.items, this.cursor, this.hasMore});
|
||||
ListPayload({
|
||||
@required this.items,
|
||||
@required this.cursor,
|
||||
@required this.hasMore,
|
||||
});
|
||||
}
|
||||
|
||||
// This is a scaffold for infinite scroll screens
|
||||
|
46
lib/screens/gitlab_explore.dart
Normal file
46
lib/screens/gitlab_explore.dart
Normal file
@ -0,0 +1,46 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:git_touch/models/auth.dart';
|
||||
import 'package:git_touch/models/gitlab.dart';
|
||||
import 'package:git_touch/scaffolds/list_stateful.dart';
|
||||
import 'package:git_touch/widgets/app_bar_title.dart';
|
||||
import 'package:git_touch/widgets/repository_item.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:timeago/timeago.dart' as timeago;
|
||||
|
||||
class GitlabExplore extends StatelessWidget {
|
||||
Future<ListPayload<GitlabProject, int>> _query(BuildContext context,
|
||||
[int page = 1]) async {
|
||||
final auth = Provider.of<AuthModel>(context);
|
||||
final res = await auth
|
||||
.fetchGitlabWithPage('/projects?order_by=last_activity_at&page=$page');
|
||||
return ListPayload(
|
||||
cursor: res.cursor,
|
||||
hasMore: res.hasMore,
|
||||
items: <GitlabProject>[
|
||||
for (var v in res.data) GitlabProject.fromJson(v),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListStatefulScaffold<GitlabProject, int>(
|
||||
title: AppBarTitle('Explore'),
|
||||
onRefresh: () => _query(context),
|
||||
onLoadMore: (page) => _query(context, page),
|
||||
itemBuilder: (v) {
|
||||
return RepositoryItem.gl(
|
||||
id: v.id,
|
||||
owner: v.namespace.path,
|
||||
avatarUrl: v.avatarUrl,
|
||||
name: v.name,
|
||||
description: v.description,
|
||||
starCount: v.starCount,
|
||||
forkCount: v.forksCount,
|
||||
note: 'Updated ${timeago.format(v.lastActivityAt)}',
|
||||
visibility: v.visibility,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user