2020-10-17 11:35:08 +02:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2022-09-17 14:35:45 +02:00
|
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
import 'package:git_touch/models/auth.dart';
|
2020-10-17 11:35:08 +02:00
|
|
|
import 'package:git_touch/models/gitee.dart';
|
|
|
|
import 'package:git_touch/scaffolds/refresh_stateful.dart';
|
|
|
|
import 'package:git_touch/utils/utils.dart';
|
2022-09-17 14:35:45 +02:00
|
|
|
import 'package:git_touch/widgets/action_button.dart';
|
2020-10-17 11:35:08 +02:00
|
|
|
import 'package:git_touch/widgets/action_entry.dart';
|
|
|
|
import 'package:git_touch/widgets/app_bar_title.dart';
|
|
|
|
import 'package:git_touch/widgets/entry_item.dart';
|
|
|
|
import 'package:git_touch/widgets/repository_item.dart';
|
|
|
|
import 'package:git_touch/widgets/user_header.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:timeago/timeago.dart' as timeago;
|
2022-09-17 14:35:45 +02:00
|
|
|
import 'package:tuple/tuple.dart';
|
2020-10-17 11:35:08 +02:00
|
|
|
|
|
|
|
class GeUserScreen extends StatelessWidget {
|
|
|
|
final String login;
|
|
|
|
final bool isViewer;
|
2022-09-06 18:28:12 +02:00
|
|
|
const GeUserScreen(this.login, {this.isViewer = false});
|
2020-10-17 11:35:08 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final auth = Provider.of<AuthModel>(context);
|
|
|
|
return RefreshStatefulScaffold<Tuple2<GiteeUser, List<GiteeRepo>>>(
|
|
|
|
fetch: () async {
|
|
|
|
final res = await Future.wait([
|
|
|
|
auth.fetchGitee('/users/$login'),
|
|
|
|
auth.fetchGitee('/users/$login/repos?per_page=6'),
|
|
|
|
]);
|
|
|
|
return Tuple2(
|
|
|
|
GiteeUser.fromJson(res[0]),
|
|
|
|
[for (var v in res[1]) GiteeRepo.fromJson(v)],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
title: AppBarTitle(isViewer ? 'Me' : login),
|
|
|
|
action: isViewer
|
2022-09-06 18:28:12 +02:00
|
|
|
? const ActionEntry(
|
2021-02-14 15:17:22 +01:00
|
|
|
iconData: Ionicons.cog,
|
2020-10-17 11:35:08 +02:00
|
|
|
url: '/settings',
|
|
|
|
)
|
|
|
|
: null,
|
|
|
|
actionBuilder: isViewer
|
|
|
|
? null
|
2021-01-31 08:49:28 +01:00
|
|
|
: (p, _) {
|
2020-10-17 11:35:08 +02:00
|
|
|
return ActionButton(
|
|
|
|
title: 'User Actions',
|
|
|
|
items: [...ActionItem.getUrlActions(p.item1.htmlUrl)],
|
|
|
|
);
|
|
|
|
},
|
2021-01-31 08:49:28 +01:00
|
|
|
bodyBuilder: (p, _) {
|
2020-10-17 11:35:08 +02:00
|
|
|
final user = p.item1;
|
|
|
|
final repos = p.item2;
|
|
|
|
|
|
|
|
return Column(
|
|
|
|
children: <Widget>[
|
|
|
|
UserHeader(
|
|
|
|
login: user.login,
|
|
|
|
avatarUrl: user.avatarUrl,
|
|
|
|
name: user.name,
|
|
|
|
createdAt: user.createdAt,
|
|
|
|
isViewer: isViewer,
|
|
|
|
bio: user.bio,
|
|
|
|
),
|
|
|
|
CommonStyle.border,
|
|
|
|
Row(children: [
|
|
|
|
EntryItem(
|
|
|
|
count: user.publicRepos,
|
|
|
|
text: 'Repositories',
|
|
|
|
url: '/gitee/$login?tab=repositories',
|
|
|
|
),
|
|
|
|
EntryItem(
|
|
|
|
count: user.stared,
|
|
|
|
text: 'Stars',
|
|
|
|
url: '/gitee/$login?tab=stars',
|
|
|
|
),
|
|
|
|
EntryItem(
|
|
|
|
count: user.followers,
|
|
|
|
text: 'Followers',
|
|
|
|
url: '/gitee/$login?tab=followers',
|
|
|
|
),
|
|
|
|
EntryItem(
|
|
|
|
count: user.following,
|
|
|
|
text: 'Following',
|
|
|
|
url: '/gitee/$login?tab=following',
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
// TableView(
|
|
|
|
// hasIcon: true,
|
|
|
|
// items: [
|
|
|
|
// TableViewItem(
|
|
|
|
// leftIconData: Octicons.home,
|
|
|
|
// text: Text('Organizations'),
|
2020-10-17 13:06:11 +02:00
|
|
|
// url: '/gitee/$login?tab=organizations',
|
2020-10-17 11:35:08 +02:00
|
|
|
// ),
|
|
|
|
// ],
|
|
|
|
// ),
|
|
|
|
CommonStyle.border,
|
|
|
|
Column(
|
|
|
|
children: <Widget>[
|
|
|
|
for (var v in repos)
|
|
|
|
RepositoryItem(
|
2021-05-16 09:16:35 +02:00
|
|
|
owner: v.namespace!.path,
|
|
|
|
avatarUrl: v.owner!.avatarUrl,
|
2020-10-17 11:35:08 +02:00
|
|
|
name: v.path,
|
|
|
|
description: v.description,
|
|
|
|
starCount: v.stargazersCount,
|
|
|
|
forkCount: v.forksCount,
|
2021-05-16 09:16:35 +02:00
|
|
|
note: 'Updated ${timeago.format(v.updatedAt!)}',
|
|
|
|
url: '/gitee/${v.namespace!.path}/${v.path}',
|
|
|
|
avatarLink: '/gitee/${v.namespace!.path}',
|
2020-10-17 11:35:08 +02:00
|
|
|
// iconData: , TODO:
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|