1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-26 07:46:59 +01:00
git-touch-android-ios-app/lib/screens/gitea_user.dart

76 lines
2.5 KiB
Dart
Raw Normal View History

2020-01-29 11:00:48 +01:00
import 'package:flutter/material.dart';
2019-12-04 15:02:22 +01:00
import 'package:flutter/widgets.dart';
import 'package:git_touch/models/auth.dart';
import 'package:git_touch/models/gitea.dart';
import 'package:git_touch/scaffolds/refresh_stateful.dart';
2020-01-11 10:25:01 +01:00
import 'package:git_touch/utils/utils.dart';
2020-01-29 11:00:48 +01:00
import 'package:git_touch/widgets/action_entry.dart';
2019-12-04 15:02:22 +01:00
import 'package:git_touch/widgets/repository_item.dart';
2020-01-29 11:00:48 +01:00
import 'package:git_touch/widgets/user_header.dart';
2019-12-04 15:02:22 +01:00
import 'package:provider/provider.dart';
import 'package:tuple/tuple.dart';
2020-01-29 11:00:48 +01:00
import 'package:timeago/timeago.dart' as timeago;
2019-12-04 15:02:22 +01:00
class GiteaUserScreen extends StatelessWidget {
2020-01-29 10:33:54 +01:00
final String login;
GiteaUserScreen(this.login);
2020-01-29 11:00:48 +01:00
bool get isViewer => login == null;
2019-12-04 15:02:22 +01:00
@override
Widget build(BuildContext context) {
2020-01-29 11:00:48 +01:00
return RefreshStatefulScaffold<Tuple2<GiteaUser, List<GiteaRepository>>>(
title: Text(isViewer ? 'Me' : 'User'),
2019-12-04 15:02:22 +01:00
fetchData: () async {
final auth = Provider.of<AuthModel>(context);
2020-01-29 11:00:48 +01:00
final res = await Future.wait([
auth.fetchGitea(isViewer ? '/user' : '/users/$login'),
auth.fetchGitea(isViewer ? '/user/repos' : '/users/$login/repos'),
2019-12-04 15:02:22 +01:00
]);
2020-01-29 10:33:54 +01:00
return Tuple2(
2020-01-29 11:00:48 +01:00
GiteaUser.fromJson(res[0]),
[for (var v in res[1]) GiteaRepository.fromJson(v)],
2020-01-29 10:33:54 +01:00
);
2019-12-04 15:02:22 +01:00
},
2020-01-29 11:00:48 +01:00
action: isViewer
? ActionEntry(
iconData: Icons.settings,
2020-01-31 09:54:01 +01:00
url: '/settings',
2020-01-29 11:00:48 +01:00
)
: null,
2019-12-04 15:02:22 +01:00
bodyBuilder: (data, _) {
final user = data.item1;
final repos = data.item2;
return Column(
children: <Widget>[
2020-01-29 11:00:48 +01:00
UserHeader(
2019-12-04 15:02:22 +01:00
login: user.login,
avatarUrl: user.avatarUrl,
name: user.fullName,
2020-01-29 11:00:48 +01:00
createdAt: user.created,
bio: '',
2019-12-04 15:02:22 +01:00
),
2020-01-12 07:49:46 +01:00
CommonStyle.border,
2019-12-04 15:02:22 +01:00
Column(
2020-01-29 06:06:55 +01:00
children: <Widget>[
for (var v in repos)
RepositoryItem(
owner: v.owner.login,
avatarUrl: v.owner.avatarUrl,
name: v.name,
description: v.description,
starCount: v.starsCount,
forkCount: v.forksCount,
2020-01-29 11:00:48 +01:00
note: 'Updated ${timeago.format(v.updatedAt)}',
2020-01-30 05:35:11 +01:00
url: '/gitea/${v.owner.login}/${v.name}',
avatarLink: '/gitea/${v.owner.login}',
2020-01-29 06:06:55 +01:00
)
],
2019-12-04 15:02:22 +01:00
)
],
);
},
);
}
}