From 13783bdb762366917970d3fd9cec51e314c6830b Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Mon, 6 Apr 2020 12:14:00 +0800 Subject: [PATCH] refactor(gh): follow user --- lib/screens/gh_user.dart | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/screens/gh_user.dart b/lib/screens/gh_user.dart index fabaa80..5a63f0c 100644 --- a/lib/screens/gh_user.dart +++ b/lib/screens/gh_user.dart @@ -77,18 +77,17 @@ class GhUserScreen extends StatelessWidget { active: p.viewerIsFollowing, text: p.viewerIsFollowing ? 'Unfollow' : 'Follow', onPressed: () async { - final res = await auth.gqlClient.execute( - GhFollowQuery( - variables: GhFollowArguments( - id: p.id, - flag: !p.viewerIsFollowing, - ), - ), - ); + if (p.viewerIsFollowing) { + await auth.ghClient.users.unfollowUser(p.login); + } else { + // TODO: https://github.com/SpinlockLabs/github.dart/pull/216 + // await auth.ghClient.users.followUser(p.login); + await auth.ghClient.request( + 'PUT', '/user/following/${p.login}', + statusCode: 204); + } setState(() { - p.viewerIsFollowing = - res.data.unfollowUser?.user?.viewerIsFollowing ?? - res.data.followUser.user.viewerIsFollowing; + p.viewerIsFollowing = !p.viewerIsFollowing; }); }, )