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

103 lines
3.4 KiB
Dart
Raw Normal View History

2022-09-24 20:46:37 +02:00
import 'package:antd_mobile/antd_mobile.dart';
2022-09-17 14:35:45 +02:00
import 'package:flutter/widgets.dart';
2019-11-01 18:12:17 +01:00
import 'package:git_touch/models/auth.dart';
2019-12-04 15:00:39 +01:00
import 'package:git_touch/models/gitlab.dart';
2019-11-01 18:12:17 +01:00
import 'package:git_touch/scaffolds/refresh_stateful.dart';
import 'package:git_touch/utils/utils.dart';
import 'package:git_touch/widgets/avatar.dart';
import 'package:git_touch/widgets/link.dart';
import 'package:provider/provider.dart';
2020-02-07 15:26:37 +01:00
class GlTodosScreen extends StatelessWidget {
2019-12-30 14:25:02 +01:00
InlineSpan _buildActor(BuildContext context, GitlabTodo p) {
return TextSpan(
2021-05-16 09:16:35 +02:00
text: p.author!.name,
2022-09-24 20:46:37 +02:00
style: TextStyle(color: AntTheme.of(context).colorPrimary),
2019-12-30 14:25:02 +01:00
);
}
InlineSpan _buildIssue(BuildContext context, GitlabTodo p) {
return TextSpan(
2021-05-16 09:16:35 +02:00
text: '${p.project!.pathWithNamespace}!${p.target!.iid}',
2022-09-24 20:46:37 +02:00
style: TextStyle(color: AntTheme.of(context).colorPrimary),
2019-12-30 14:25:02 +01:00
);
}
Iterable<InlineSpan> _buildItem(BuildContext context, GitlabTodo p) {
switch (p.actionName) {
case 'mentioned':
return [
_buildActor(context, p),
TextSpan(text: ' mentioned you on ${p.targetType} '),
_buildIssue(context, p),
];
case 'build_failed':
return [
TextSpan(text: ' the build failed for ${p.targetType} '),
_buildIssue(context, p),
];
case 'directly_addressed':
return [
_buildActor(context, p),
TextSpan(text: ' directly addressed you ${p.targetType} '),
_buildIssue(context, p),
];
case 'assigned':
return [
_buildActor(context, p),
TextSpan(text: ' directly addressed you ${p.targetType} '),
_buildIssue(context, p),
];
default:
return [
TextSpan(text: ' action type ${p.actionName} not implemented yet')
];
}
}
2019-11-01 18:12:17 +01:00
@override
Widget build(BuildContext context) {
2019-12-04 15:00:39 +01:00
return RefreshStatefulScaffold<Iterable<GitlabTodo>>(
2022-09-06 18:28:12 +02:00
title: const Text('Todos'),
fetch: () async {
2020-10-04 14:37:23 +02:00
final vs = await context.read<AuthModel>().fetchGitlab('/todos');
2019-12-04 15:00:39 +01:00
return (vs as List).map((v) => GitlabTodo.fromJson(v));
2019-11-01 18:12:17 +01:00
},
2019-11-02 13:54:23 +01:00
bodyBuilder: (data, _) {
2019-11-01 18:12:17 +01:00
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
2019-12-04 15:00:39 +01:00
children: data.map((item) {
2021-05-16 09:16:35 +02:00
return LinkWidget(
url:
2021-05-16 09:16:35 +02:00
'/projects/${item.target!.projectId}/${item.targetType == 'MergeRequest' ? 'merge_requests' : 'issue'}/${item.target!.iid}',
2019-11-01 18:12:17 +01:00
child: Container(
padding: CommonStyle.padding,
child: Row(
children: <Widget>[
2021-01-30 08:34:41 +01:00
Avatar(
2021-05-16 09:16:35 +02:00
url: item.author!.avatarUrl,
linkUrl: '/gitlab/user/${item.author!.id}'),
2022-09-06 18:28:12 +02:00
const SizedBox(width: 12),
2019-11-01 18:12:17 +01:00
Expanded(
child: Text.rich(
TextSpan(
2019-12-30 14:25:02 +01:00
style: TextStyle(
2022-09-24 20:46:37 +02:00
color: AntTheme.of(context).colorText,
fontSize: 17),
2019-11-01 18:12:17 +01:00
children: [
2019-12-30 14:25:02 +01:00
..._buildItem(context, item),
2019-11-01 18:12:17 +01:00
],
),
),
),
],
),
),
);
}).toList(),
);
},
);
}
}