1
0
mirror of https://github.com/git-touch/git-touch synced 2025-02-14 02:20:42 +01:00

70 lines
2.1 KiB
Dart
Raw Normal View History

2020-01-29 13:23:17 +08:00
import 'package:flutter/material.dart';
2019-11-02 01:48:42 +08:00
import 'package:flutter/widgets.dart';
import 'package:git_touch/models/auth.dart';
2019-12-04 22:00:39 +08:00
import 'package:git_touch/models/gitlab.dart';
2019-11-02 01:48:42 +08:00
import 'package:git_touch/scaffolds/refresh_stateful.dart';
2020-01-29 13:23:17 +08:00
import 'package:git_touch/widgets/action_entry.dart';
2019-11-02 01:48:42 +08:00
import 'package:git_touch/widgets/repository_item.dart';
2020-01-29 13:45:22 +08:00
import 'package:git_touch/widgets/user_header.dart';
2019-11-02 01:48:42 +08:00
import 'package:provider/provider.dart';
2019-12-04 22:00:39 +08:00
import 'package:tuple/tuple.dart';
2019-12-30 20:55:37 +08:00
import 'package:git_touch/utils/utils.dart';
2020-01-29 13:32:40 +08:00
import 'package:timeago/timeago.dart' as timeago;
2019-12-30 20:55:37 +08:00
2019-11-02 01:48:42 +08:00
class GitlabUserScreen extends StatelessWidget {
2019-12-30 20:55:37 +08:00
final int id;
GitlabUserScreen(this.id);
2020-01-29 13:23:17 +08:00
bool get isViewer => id == null;
2019-11-02 01:48:42 +08:00
@override
Widget build(BuildContext context) {
2020-01-31 22:36:58 +08:00
return RefreshStatefulScaffold<Tuple2<GitlabUser, Iterable<GitlabProject>>>(
2020-01-29 13:23:17 +08:00
title: Text(isViewer ? 'Me' : 'User'),
2019-11-02 01:48:42 +08:00
fetchData: () async {
2019-12-04 22:00:39 +08:00
final auth = Provider.of<AuthModel>(context);
2020-01-29 13:23:17 +08:00
final _id = id ?? auth.activeAccount.gitlabId;
2020-01-30 18:57:39 +08:00
final res = await Future.wait([
auth.fetchGitlab('/users/$_id'),
auth.fetchGitlab('/users/$_id/projects'),
]);
return Tuple2(
GitlabUser.fromJson(res[0]),
2020-01-31 22:36:58 +08:00
[for (var v in res[1]) GitlabProject.fromJson(v)],
2020-01-30 18:57:39 +08:00
);
2019-11-02 01:48:42 +08:00
},
2020-01-29 13:23:17 +08:00
action: isViewer
? ActionEntry(
iconData: Icons.settings,
2020-01-31 16:54:01 +08:00
url: '/settings',
2020-01-29 13:23:17 +08:00
)
: null,
2019-11-02 20:54:23 +08:00
bodyBuilder: (data, _) {
2019-12-04 22:00:39 +08:00
final user = data.item1;
final projects = data.item2;
2019-11-02 01:48:42 +08:00
return Column(
children: <Widget>[
2020-01-29 13:45:22 +08:00
UserHeader(
2019-12-04 22:00:39 +08:00
login: user.username,
avatarUrl: user.avatarUrl,
name: user.name,
2020-01-29 13:45:22 +08:00
createdAt: user.createdAt,
bio: user.bio,
2019-11-02 01:48:42 +08:00
),
2020-01-12 14:49:46 +08:00
CommonStyle.border,
2019-11-02 01:48:42 +08:00
Column(
2020-01-29 13:06:55 +08:00
children: <Widget>[
for (var v in projects)
2020-01-29 13:32:40 +08:00
RepositoryItem.gl(
2020-01-31 22:36:58 +08:00
payload: v,
2020-02-01 10:35:55 +08:00
note: 'Updated ${timeago.format(v.lastActivityAt)}',
2020-01-29 13:06:55 +08:00
)
],
2019-11-02 01:48:42 +08:00
)
],
);
},
);
}
}