1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-18 19:22:54 +01:00
git-touch-android-ios-app/lib/screens/gitlab_merge_requests.dart

52 lines
1.8 KiB
Dart
Raw Normal View History

2020-01-28 16:43:47 +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/issue_item.dart';
import 'package:git_touch/widgets/label.dart';
import 'package:provider/provider.dart';
class GitlabMergeRequestsScreen extends StatelessWidget {
final String id;
final String prefix;
GitlabMergeRequestsScreen(this.id, {this.prefix});
2020-01-28 16:43:47 +01:00
Future<ListPayload<GitlabIssue, int>> _query(BuildContext context,
[int page = 1]) async {
2020-01-29 05:32:35 +01:00
final res = await Provider.of<AuthModel>(context).fetchGitlabWithPage(
'/projects/$id/merge_requests?state=opened&page=$page');
2020-01-28 16:43:47 +01:00
return ListPayload(
2020-01-29 05:32:35 +01:00
cursor: res.cursor,
hasMore: res.hasMore,
2020-01-29 06:15:27 +01:00
items: (res.data as List).map((v) => GitlabIssue.fromJson(v)).toList(),
2020-01-28 16:43:47 +01:00
);
}
@override
Widget build(BuildContext context) {
return ListStatefulScaffold<GitlabIssue, int>(
title: AppBarTitle('Merge Requests'),
onRefresh: () => _query(context),
onLoadMore: (cursor) => _query(context, cursor),
itemBuilder: (p) => IssueItem(
isPr: true,
author: p.author.username,
avatarUrl: p.author.avatarUrl,
commentCount: p.userNotesCount,
number: p.iid,
title: p.title,
updatedAt: p.updatedAt,
labels: p.labels.isEmpty
? null
: Wrap(spacing: 4, runSpacing: 4, children: [
for (var label in p.labels)
MyLabel(name: label, cssColor: '#428BCA')
]),
// url: '/gitlab/projects/${p.projectId}/merge_requests/${p.iid}',
url: '$prefix/merge_requests/${p.iid}', // TODO:
2020-01-28 16:43:47 +01:00
),
);
}
}