commenting on a post now works

This commit is contained in:
shilangyu 2020-09-21 13:30:47 +02:00
parent 222f3aedc1
commit 5409cde5d0
2 changed files with 19 additions and 7 deletions

View File

@ -9,6 +9,7 @@ import '../util/extensions/api.dart';
import '../widgets/comment_section.dart';
import '../widgets/post.dart';
import '../widgets/save_post_button.dart';
import '../widgets/write_comment.dart';
class FullPostPage extends HookWidget {
final int id;
@ -29,6 +30,7 @@ class FullPostPage extends HookWidget {
final fullPostSnap = useMemoFuture(() => LemmyApi(instanceUrl)
.v1
.getPost(id: id, auth: accStore.defaultTokenFor(instanceUrl)?.raw));
final newComments = useState(const <CommentView>[]);
// FALLBACK VIEW
@ -59,6 +61,16 @@ class FullPostPage extends HookWidget {
sharePost() => Share.text('Share post', post.apId, 'text/plain');
comment() async {
final newComment = await showDialog<CommentView>(
context: context,
child: WriteComment.toPost(post),
);
if (newComment != null) {
newComments.value = [...newComments.value, newComment];
}
}
return Scaffold(
appBar: AppBar(
leading: BackButton(),
@ -70,12 +82,15 @@ class FullPostPage extends HookWidget {
onPressed: () => Post.showMoreMenu(context, post)),
],
),
floatingActionButton: FloatingActionButton(
onPressed: comment, child: Icon(Icons.comment)),
body: ListView(
physics: const AlwaysScrollableScrollPhysics(),
children: [
Post(post, fullPost: true),
if (fullPostSnap.hasData)
CommentSection(fullPost.comments,
CommentSection(
newComments.value.followedBy(fullPost.comments).toList(),
postCreatorId: fullPost.post.creatorId)
else if (fullPostSnap.hasError)
Padding(

View File

@ -35,12 +35,10 @@ class CommentSection extends HookWidget {
@override
Widget build(BuildContext context) {
final sorting = useState(sortType);
final rawComms = useState(rawComments);
final comms = useState(comments);
void sortComments(CommentSortType sort) {
if (sort != sorting.value && sort != CommentSortType.chat) {
CommentTree.sortList(sort, comms.value);
CommentTree.sortList(sort, comments);
}
sorting.value = sort;
@ -100,14 +98,13 @@ class CommentSection extends HookWidget {
),
)
else if (sorting.value == CommentSortType.chat)
for (final com in rawComms.value)
for (final com in rawComments)
Comment(
CommentTree(com),
postCreatorId: postCreatorId,
)
else
for (final com in comms.value)
Comment(com, postCreatorId: postCreatorId),
for (final com in comments) Comment(com, postCreatorId: postCreatorId),
]);
}
}