1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-24 14:51:28 +01:00
git-touch-android-ios-app/lib/screens/gitlab_user.dart

86 lines
2.8 KiB
Dart
Raw Normal View History

2020-01-29 06:23:17 +01:00
import 'package:flutter/material.dart';
2019-11-01 18:48:42 +01:00
import 'package:flutter/widgets.dart';
import 'package:git_touch/models/auth.dart';
2019-12-04 15:00:39 +01:00
import 'package:git_touch/models/gitlab.dart';
2020-01-29 06:23:17 +01:00
import 'package:git_touch/models/theme.dart';
2019-11-01 18:48:42 +01:00
import 'package:git_touch/scaffolds/refresh_stateful.dart';
2020-01-29 06:23:17 +01:00
import 'package:git_touch/widgets/action_entry.dart';
2019-11-01 18:48:42 +01:00
import 'package:git_touch/widgets/repository_item.dart';
2020-01-29 06:45:22 +01:00
import 'package:git_touch/widgets/user_header.dart';
2019-11-01 18:48:42 +01:00
import 'package:provider/provider.dart';
2019-12-04 15:00:39 +01:00
import 'package:tuple/tuple.dart';
2019-12-30 13:55:37 +01:00
import 'package:git_touch/utils/utils.dart';
2020-01-29 06:32:40 +01:00
import 'package:timeago/timeago.dart' as timeago;
2019-12-30 13:55:37 +01:00
final gitlabUserRouter = RouterScreen(
2020-01-01 09:51:10 +01:00
'/gitlab/user/:id',
2019-12-30 13:55:37 +01:00
(context, parameters) =>
GitlabUserScreen(int.parse(parameters['id'].first)));
2019-11-01 18:48:42 +01:00
class GitlabUserScreen extends StatelessWidget {
2019-12-30 13:55:37 +01:00
final int id;
GitlabUserScreen(this.id);
2020-01-29 06:23:17 +01:00
bool get isViewer => id == null;
2019-11-01 18:48:42 +01:00
@override
Widget build(BuildContext context) {
2019-12-11 16:09:39 +01:00
return RefreshStatefulScaffold<
Tuple2<GitlabUser, Iterable<GitlabUserProject>>>(
2020-01-29 06:23:17 +01:00
title: Text(isViewer ? 'Me' : 'User'),
2019-11-01 18:48:42 +01:00
fetchData: () async {
2019-12-04 15:00:39 +01:00
final auth = Provider.of<AuthModel>(context);
2020-01-29 06:23:17 +01:00
final _id = id ?? auth.activeAccount.gitlabId;
final v0 = await auth.fetchGitlab('/users/$_id');
2019-12-30 13:55:37 +01:00
final user = GitlabUser.fromJson(v0);
2020-01-29 06:23:17 +01:00
final v1 = await auth.fetchGitlab('/users/$_id/projects');
2019-12-08 13:08:50 +01:00
final projects =
2019-12-11 16:09:39 +01:00
(v1 as List).map((v) => GitlabUserProject.fromJson(v)).toList();
2019-12-04 15:00:39 +01:00
2019-12-08 13:08:50 +01:00
return Tuple2(user, projects);
2019-11-01 18:48:42 +01:00
},
2020-01-29 06:23:17 +01:00
action: isViewer
? ActionEntry(
iconData: Icons.settings,
onTap: () {
final theme = Provider.of<ThemeModel>(context);
theme.push(context, '/settings');
},
)
: null,
2019-11-02 13:54:23 +01:00
bodyBuilder: (data, _) {
2019-12-04 15:00:39 +01:00
final user = data.item1;
final projects = data.item2;
2019-11-01 18:48:42 +01:00
return Column(
children: <Widget>[
2020-01-29 06:45:22 +01:00
UserHeader(
2019-12-04 15:00:39 +01:00
login: user.username,
avatarUrl: user.avatarUrl,
name: user.name,
2020-01-29 06:45:22 +01:00
createdAt: user.createdAt,
bio: user.bio,
2019-11-01 18:48:42 +01:00
),
2020-01-12 07:49:46 +01:00
CommonStyle.border,
2019-11-01 18:48:42 +01:00
Column(
2020-01-29 06:06:55 +01:00
children: <Widget>[
for (var v in projects)
2020-01-29 06:32:40 +01:00
RepositoryItem.gl(
id: v.id,
2020-01-29 06:06:55 +01:00
owner: v.owner.username,
avatarUrl: v.owner.avatarUrl,
name: v.name,
description: v.description,
starCount: v.starCount,
forkCount: v.forksCount,
2020-01-29 06:32:40 +01:00
note: 'Created ${timeago.format(v.createdAt)}',
visibility: v.visibility,
2020-01-29 06:06:55 +01:00
)
],
2019-11-01 18:48:42 +01:00
)
],
);
},
);
}
}