1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-18 19:22:54 +01:00

feat: follow button

This commit is contained in:
Rongjian Zhang 2020-01-11 21:22:52 +08:00
parent 245f19e050
commit 6a94d552e1
2 changed files with 96 additions and 90 deletions

View File

@ -240,10 +240,12 @@ class RepositoryScreen extends StatelessWidget {
), ),
], ],
), ),
CommonStyle.verticalGap, if (repo.languages.edges.isNotEmpty) ...[
if (repo.languages.edges.isNotEmpty) CommonStyle.border,
GestureDetector( CupertinoButton(
onTap: () { padding: EdgeInsets.zero,
minSize: 0,
onPressed: () {
showCupertinoModalPopup( showCupertinoModalPopup(
context: context, context: context,
builder: (context) { builder: (context) {
@ -305,6 +307,7 @@ class RepositoryScreen extends StatelessWidget {
), ),
), ),
), ),
],
TableView( TableView(
hasIcon: true, hasIcon: true,
items: [ items: [
@ -373,7 +376,6 @@ class RepositoryScreen extends StatelessWidget {
], ],
], ],
), ),
CommonStyle.verticalGap,
if (readme != null) if (readme != null)
Container( Container(
padding: CommonStyle.padding, padding: CommonStyle.padding,

View File

@ -15,7 +15,6 @@ import 'package:git_touch/widgets/text_contains_organization.dart';
import 'package:git_touch/models/auth.dart'; import 'package:git_touch/models/auth.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:git_touch/widgets/action_button.dart'; import 'package:git_touch/widgets/action_button.dart';
import 'package:timeago/timeago.dart' as t;
final userRouter = RouterScreen( final userRouter = RouterScreen(
'/:login', '/:login',
@ -84,7 +83,8 @@ class UserScreen extends StatelessWidget {
} }
Widget _buildHeader(BuildContext context, String avatarUrl, String name, Widget _buildHeader(BuildContext context, String avatarUrl, String name,
String login, DateTime createdAt, String bio) { String login, DateTime createdAt, String bio,
{Widget followWidget}) {
final theme = Provider.of<ThemeModel>(context); final theme = Provider.of<ThemeModel>(context);
return Container( return Container(
@ -95,59 +95,51 @@ class UserScreen extends StatelessWidget {
Row( Row(
children: <Widget>[ children: <Widget>[
Avatar(url: avatarUrl, size: AvatarSize.large), Avatar(url: avatarUrl, size: AvatarSize.large),
SizedBox(width: 10), if (followWidget != null) ...[
Expanded( Expanded(child: Container()),
child: Column( followWidget,
mainAxisAlignment: MainAxisAlignment.spaceBetween, ]
crossAxisAlignment: CrossAxisAlignment.start, ],
children: <Widget>[ ),
Row( SizedBox(height: 8),
children: <Widget>[ if (name != null) ...[
if (name != null) ...[ Text(
Text( name,
name, style: TextStyle(
style: TextStyle( color: theme.palette.primary,
color: theme.palette.primary, fontSize: 20,
fontSize: 19, fontWeight: FontWeight.w600,
fontWeight: FontWeight.w500, ),
), ),
), SizedBox(height: 4),
SizedBox(width: 4), ],
], Text(
Text( login,
'($login)', style: TextStyle(
style: TextStyle( color: theme.palette.secondaryText,
color: theme.palette.secondaryText, fontSize: 18,
fontSize: 16, ),
), ),
), SizedBox(height: 8),
], Row(
), children: <Widget>[
SizedBox(height: 6), Icon(
Row( Octicons.clock,
children: <Widget>[ size: 16,
Icon( color: theme.palette.tertiaryText,
Octicons.clock, ),
size: 15, SizedBox(width: 4),
color: theme.palette.secondaryText, Text(
), 'Joined on ${dateFormat.format(createdAt)}',
SizedBox(width: 4), style: TextStyle(
Text( color: theme.palette.tertiaryText,
'Joined on ${dateFormat.format(createdAt)}', fontSize: 16,
style: TextStyle(
color: theme.palette.secondaryText,
fontSize: 15,
),
),
],
),
],
), ),
) ),
], ],
), ),
if (bio != null && bio.isNotEmpty) ...[ if (bio != null && bio.isNotEmpty) ...[
SizedBox(height: 12), SizedBox(height: 10),
Text( Text(
bio, bio,
style: TextStyle( style: TextStyle(
@ -161,14 +153,52 @@ class UserScreen extends StatelessWidget {
); );
} }
Widget _buildUser(BuildContext context, GhUserUser user) { Widget _buildUser(BuildContext context, GhUserUser user,
void Function(void Function()) setState) {
final theme = Provider.of<ThemeModel>(context); final theme = Provider.of<ThemeModel>(context);
final auth = Provider.of<AuthModel>(context);
final login = user.login; final login = user.login;
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[ children: <Widget>[
_buildHeader(context, user.avatarUrl, user.name, user.login, _buildHeader(
user.createdAt, user.bio), context,
user.avatarUrl,
user.name,
user.login,
user.createdAt,
user.bio,
followWidget: user.viewerCanFollow == true
? CupertinoButton(
onPressed: () async {
final res = await auth.gqlClient.execute(
GhFollowQuery(
variables: GhFollowArguments(
id: user.id,
flag: !user.viewerIsFollowing,
),
),
);
setState(() {
user.viewerIsFollowing =
res.data.unfollowUser?.user?.viewerIsFollowing ??
res.data.followUser.user.viewerIsFollowing;
});
},
minSize: 0,
color: theme.palette.primary,
padding: EdgeInsets.symmetric(
horizontal: 12,
vertical: 4,
),
child: Text(
user.viewerIsFollowing ? 'Unfollow' : 'Follow',
style: TextStyle(fontSize: 17),
),
)
: null,
),
CommonStyle.border, CommonStyle.border,
Row(children: [ Row(children: [
EntryItem( EntryItem(
@ -193,8 +223,6 @@ class UserScreen extends StatelessWidget {
), ),
]), ]),
CommonStyle.border, CommonStyle.border,
CommonStyle.verticalGap,
CommonStyle.border,
Container( Container(
color: theme.palette.background, color: theme.palette.background,
padding: CommonStyle.padding, padding: CommonStyle.padding,
@ -228,8 +256,6 @@ class UserScreen extends StatelessWidget {
), ),
), ),
CommonStyle.border, CommonStyle.border,
CommonStyle.verticalGap,
CommonStyle.border,
TableView( TableView(
hasIcon: true, hasIcon: true,
items: [ items: [
@ -320,7 +346,6 @@ class UserScreen extends StatelessWidget {
url: '/${payload.login}?tab=people', url: '/${payload.login}?tab=people',
), ),
]), ]),
CommonStyle.verticalGap,
TableView( TableView(
hasIcon: true, hasIcon: true,
items: [ items: [
@ -386,29 +411,8 @@ class UserScreen extends StatelessWidget {
return ActionButton( return ActionButton(
title: 'User Actions', title: 'User Actions',
items: [ items: [
if (user.viewerCanFollow) ActionItem.share(user.url),
ActionItem( ActionItem.launch(user.url),
text: user.viewerIsFollowing ? 'Unfollow' : 'Follow',
onTap: (_) async {
final res = await auth.gqlClient.execute(
GhFollowQuery(
variables: GhFollowArguments(
id: user.id,
flag: !user.viewerIsFollowing,
),
),
);
setState(() {
user.viewerIsFollowing =
res.data.unfollowUser?.user?.viewerIsFollowing ??
res.data.followUser.user.viewerIsFollowing;
});
},
),
if (payload != null) ...[
ActionItem.share(user.url),
ActionItem.launch(user.url),
],
], ],
); );
case 'Organization': case 'Organization':
@ -426,13 +430,13 @@ class UserScreen extends StatelessWidget {
return null; return null;
} }
}, },
bodyBuilder: (payload, _) { bodyBuilder: (payload, setState) {
if (isViewer) { if (isViewer) {
return _buildUser(context, payload as GhUserUser); return _buildUser(context, payload as GhUserUser, setState);
} }
switch (payload.resolveType) { switch (payload.resolveType) {
case 'User': case 'User':
return _buildUser(context, payload as GhUserUser); return _buildUser(context, payload as GhUserUser, setState);
case 'Organization': case 'Organization':
return _buildOrganization(context, payload as GhUserOrganization); return _buildOrganization(context, payload as GhUserOrganization);
default: default: