From 377ad99fb53d78cd03d37067b49dbb5d041545a9 Mon Sep 17 00:00:00 2001 From: shilangyu Date: Mon, 21 Sep 2020 20:19:14 +0200 Subject: [PATCH] limit commenting to logged in users --- lib/pages/full_post.dart | 6 +++++- lib/widgets/comment.dart | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/pages/full_post.dart b/lib/pages/full_post.dart index 03a4ff0..567ef9d 100644 --- a/lib/pages/full_post.dart +++ b/lib/pages/full_post.dart @@ -1,8 +1,10 @@ import 'package:esys_flutter_share/esys_flutter_share.dart'; +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:lemmy_api_client/lemmy_api_client.dart'; +import '../hooks/logged_in_action.dart'; import '../hooks/memo_future.dart'; import '../hooks/stores.dart'; import '../util/extensions/api.dart'; @@ -30,6 +32,7 @@ class FullPostPage extends HookWidget { final fullPostSnap = useMemoFuture(() => LemmyApi(instanceUrl) .v1 .getPost(id: id, auth: accStore.defaultTokenFor(instanceUrl)?.raw)); + final loggedInAction = useLoggedInAction(instanceUrl); final newComments = useState(const []); // FALLBACK VIEW @@ -83,7 +86,8 @@ class FullPostPage extends HookWidget { ], ), floatingActionButton: FloatingActionButton( - onPressed: comment, child: Icon(Icons.comment)), + onPressed: loggedInAction((_) => comment()), + child: Icon(Icons.comment)), body: ListView( physics: const AlwaysScrollableScrollPhysics(), children: [ diff --git a/lib/widgets/comment.dart b/lib/widgets/comment.dart index 1470d58..cf54f15 100644 --- a/lib/widgets/comment.dart +++ b/lib/widgets/comment.dart @@ -1,5 +1,6 @@ import 'package:cached_network_image/cached_network_image.dart'; import 'package:esys_flutter_share/esys_flutter_share.dart'; +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; @@ -271,7 +272,7 @@ class Comment extends HookWidget { _SaveComment(commentTree.comment), _CommentAction( icon: Icons.reply, - onPressed: reply, + onPressed: loggedInAction((_) => reply()), tooltip: 'reply', ), _CommentAction(