git-touch-android-ios-app/lib/screens/go_issues.dart

63 lines
2.2 KiB
Dart
Raw Normal View History

2022-09-17 14:35:45 +02:00
import 'package:flutter/widgets.dart';
import 'package:flutter_gen/gen_l10n/S.dart';
2022-10-07 18:55:47 +02:00
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
2021-01-23 15:08:05 +01:00
import 'package:git_touch/models/auth.dart';
import 'package:git_touch/models/gogs.dart';
import 'package:git_touch/scaffolds/list_stateful.dart';
import 'package:git_touch/widgets/action_entry.dart';
2022-09-12 05:46:42 +02:00
import 'package:git_touch/widgets/hex_color_tag.dart';
2021-01-23 15:08:05 +01:00
import 'package:git_touch/widgets/issue_item.dart';
import 'package:provider/provider.dart';
class GoIssuesScreen extends StatelessWidget {
2022-09-21 18:28:21 +02:00
const GoIssuesScreen(this.owner, this.name, {this.isPr = false});
2021-01-23 15:08:05 +01:00
final String owner;
final String name;
final bool isPr;
@override
Widget build(BuildContext context) {
return ListStatefulScaffold<GogsIssue, int>(
2022-10-07 19:06:03 +02:00
title: Text(isPr
2021-05-16 09:16:35 +02:00
? AppLocalizations.of(context)!.pullRequests
: AppLocalizations.of(context)!.issues),
2021-01-23 15:08:05 +01:00
fetch: (page) async {
final type = isPr ? 'pulls' : 'issues';
final res = await context.read<AuthModel>().fetchGogsWithPage(
'/repos/$owner/$name/issues?state=open&type=$type',
page: page);
return ListPayload(
cursor: res.cursor,
hasMore: res.hasMore,
items: (res.data as List).map((v) => GogsIssue.fromJson(v)).toList(),
);
},
actionBuilder: () => ActionEntry(
iconData: isPr ? null : Octicons.plus,
url: isPr
? '/gogs/$owner/$name/pulls/new' // TODO
: '/gogs/$owner/$name/issues/new',
),
itemBuilder: (p) => IssueItem(
2021-05-16 09:16:35 +02:00
author: p.user!.username,
avatarUrl: p.user!.avatarUrl,
2021-01-23 15:08:05 +01:00
commentCount: p.comments,
2022-09-06 18:28:12 +02:00
subtitle: '#${p.number}',
2021-01-23 15:08:05 +01:00
title: p.title,
updatedAt: p.updatedAt,
url: isPr
? 'https://gogs.io' // TODO: PR endpoints are not supported in Gogs, htmlUrl prop non-existent
: '/gogs/$owner/$name/issues/${p.number}',
labels: isPr
? null
2021-05-16 09:16:35 +02:00
: p.labels!.isEmpty
2021-01-23 15:08:05 +01:00
? null
: Wrap(spacing: 4, runSpacing: 4, children: [
2021-05-16 09:16:35 +02:00
for (var label in p.labels!)
2022-09-12 05:46:42 +02:00
HexColorTag(name: label.name!, color: label.color!)
2021-01-23 15:08:05 +01:00
]),
),
);
}
}