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

105 lines
3.4 KiB
Dart
Raw Normal View History

2019-11-01 18:12:17 +01:00
import 'package:flutter/material.dart';
import 'package:git_touch/models/auth.dart';
2019-12-04 15:00:39 +01:00
import 'package:git_touch/models/gitlab.dart';
2019-11-08 11:29:08 +01:00
import 'package:git_touch/models/theme.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) {
final theme = Provider.of<ThemeModel>(context);
return TextSpan(
text: p.author.name,
2020-01-27 08:11:51 +01:00
style: TextStyle(color: theme.palette.primary),
2019-12-30 14:25:02 +01:00
);
}
InlineSpan _buildIssue(BuildContext context, GitlabTodo p) {
final theme = Provider.of<ThemeModel>(context);
return TextSpan(
text: '${p.project.pathWithNamespace}!${p.target.iid}',
2020-01-27 08:11:51 +01:00
style: TextStyle(color: theme.palette.primary),
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-11-08 11:29:08 +01:00
final theme = Provider.of<ThemeModel>(context);
2019-12-04 15:00:39 +01:00
return RefreshStatefulScaffold<Iterable<GitlabTodo>>(
2019-11-01 18:12:17 +01:00
title: Text('Todos'),
2019-12-04 15:00:39 +01:00
fetchData: () async {
final vs = await Provider.of<AuthModel>(context).fetchGitlab('/todos');
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) {
2019-11-01 18:12:17 +01:00
return Link(
url:
2019-12-14 17:08:12 +01: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>[
2019-12-30 14:25:02 +01:00
GitlabAvatar(
url: item.author.avatarUrl, id: item.author.id),
2019-11-01 18:12:17 +01:00
SizedBox(width: 12),
Expanded(
child: Text.rich(
TextSpan(
2019-12-30 14:25:02 +01:00
style: TextStyle(
2020-01-27 08:11:51 +01:00
color: theme.palette.text, 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(),
);
},
);
}
}