1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-20 20:13:55 +01:00
git-touch-android-ios-app/lib/screens/gitlab_explore.dart

47 lines
1.5 KiB
Dart
Raw Normal View History

2020-01-29 07:38:27 +01:00
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,
);
},
);
}
}