mirror of
https://github.com/git-touch/git-touch
synced 2025-03-05 11:48:02 +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/auth.dart';
|
||||||
import 'package:git_touch/models/notification.dart';
|
import 'package:git_touch/models/notification.dart';
|
||||||
import 'package:git_touch/models/theme.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_project.dart';
|
||||||
import 'package:git_touch/screens/gitlab_todos.dart';
|
import 'package:git_touch/screens/gitlab_todos.dart';
|
||||||
import 'package:git_touch/screens/gitlab_user.dart';
|
import 'package:git_touch/screens/gitlab_user.dart';
|
||||||
@ -49,7 +50,7 @@ class _HomeState extends State<Home> {
|
|||||||
case PlatformType.gitlab:
|
case PlatformType.gitlab:
|
||||||
switch (index) {
|
switch (index) {
|
||||||
case 0:
|
case 0:
|
||||||
return GitlabTodosScreen();
|
return GitlabExplore();
|
||||||
case 1:
|
case 1:
|
||||||
return GitlabUserScreen(null);
|
return GitlabUserScreen(null);
|
||||||
}
|
}
|
||||||
@ -108,12 +109,11 @@ class _HomeState extends State<Home> {
|
|||||||
case PlatformType.gitlab:
|
case PlatformType.gitlab:
|
||||||
return [
|
return [
|
||||||
BottomNavigationBarItem(
|
BottomNavigationBarItem(
|
||||||
icon: Icon(Icons.timeline),
|
icon: Icon(Icons.explore),
|
||||||
title: Text('Todos'),
|
title: Text('Explore'),
|
||||||
),
|
),
|
||||||
BottomNavigationBarItem(
|
BottomNavigationBarItem(
|
||||||
icon: Icon(Icons.person_outline),
|
icon: Icon(Icons.person),
|
||||||
activeIcon: Icon(Icons.person),
|
|
||||||
title: Text('Me'),
|
title: Text('Me'),
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
@ -98,6 +98,7 @@ class GitlabProject {
|
|||||||
int openIssuesCount;
|
int openIssuesCount;
|
||||||
bool mergeRequestsEnabled;
|
bool mergeRequestsEnabled;
|
||||||
GitlabProjectStatistics statistics;
|
GitlabProjectStatistics statistics;
|
||||||
|
DateTime lastActivityAt;
|
||||||
GitlabProject();
|
GitlabProject();
|
||||||
factory GitlabProject.fromJson(Map<String, dynamic> json) =>
|
factory GitlabProject.fromJson(Map<String, dynamic> json) =>
|
||||||
_$GitlabProjectFromJson(json);
|
_$GitlabProjectFromJson(json);
|
||||||
@ -124,6 +125,7 @@ class GitlabProjectStatistics {
|
|||||||
class GitlabProjectNamespace {
|
class GitlabProjectNamespace {
|
||||||
int id;
|
int id;
|
||||||
String name;
|
String name;
|
||||||
|
String path;
|
||||||
GitlabProjectNamespace();
|
GitlabProjectNamespace();
|
||||||
|
|
||||||
factory GitlabProjectNamespace.fromJson(Map<String, dynamic> json) =>
|
factory GitlabProjectNamespace.fromJson(Map<String, dynamic> json) =>
|
||||||
|
@ -147,7 +147,10 @@ GitlabProject _$GitlabProjectFromJson(Map<String, dynamic> json) {
|
|||||||
..statistics = json['statistics'] == null
|
..statistics = json['statistics'] == null
|
||||||
? null
|
? null
|
||||||
: GitlabProjectStatistics.fromJson(
|
: 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) =>
|
Map<String, dynamic> _$GitlabProjectToJson(GitlabProject instance) =>
|
||||||
@ -166,6 +169,7 @@ Map<String, dynamic> _$GitlabProjectToJson(GitlabProject instance) =>
|
|||||||
'open_issues_count': instance.openIssuesCount,
|
'open_issues_count': instance.openIssuesCount,
|
||||||
'merge_requests_enabled': instance.mergeRequestsEnabled,
|
'merge_requests_enabled': instance.mergeRequestsEnabled,
|
||||||
'statistics': instance.statistics,
|
'statistics': instance.statistics,
|
||||||
|
'last_activity_at': instance.lastActivityAt?.toIso8601String(),
|
||||||
};
|
};
|
||||||
|
|
||||||
GitlabProjectBadge _$GitlabProjectBadgeFromJson(Map<String, dynamic> json) {
|
GitlabProjectBadge _$GitlabProjectBadgeFromJson(Map<String, dynamic> json) {
|
||||||
@ -196,7 +200,8 @@ GitlabProjectNamespace _$GitlabProjectNamespaceFromJson(
|
|||||||
Map<String, dynamic> json) {
|
Map<String, dynamic> json) {
|
||||||
return GitlabProjectNamespace()
|
return GitlabProjectNamespace()
|
||||||
..id = json['id'] as int
|
..id = json['id'] as int
|
||||||
..name = json['name'] as String;
|
..name = json['name'] as String
|
||||||
|
..path = json['path'] as String;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> _$GitlabProjectNamespaceToJson(
|
Map<String, dynamic> _$GitlabProjectNamespaceToJson(
|
||||||
@ -204,6 +209,7 @@ Map<String, dynamic> _$GitlabProjectNamespaceToJson(
|
|||||||
<String, dynamic>{
|
<String, dynamic>{
|
||||||
'id': instance.id,
|
'id': instance.id,
|
||||||
'name': instance.name,
|
'name': instance.name,
|
||||||
|
'path': instance.path,
|
||||||
};
|
};
|
||||||
|
|
||||||
GitlabTreeItem _$GitlabTreeItemFromJson(Map<String, dynamic> json) {
|
GitlabTreeItem _$GitlabTreeItemFromJson(Map<String, dynamic> json) {
|
||||||
|
@ -14,7 +14,11 @@ class ListPayload<T, K> {
|
|||||||
List<T> items;
|
List<T> items;
|
||||||
bool hasMore;
|
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
|
// 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…
x
Reference in New Issue
Block a user