From aefcf50fd1155daabddd9d85b5b7f638df004fb2 Mon Sep 17 00:00:00 2001 From: krawieck Date: Tue, 29 Sep 2020 10:53:40 +0200 Subject: [PATCH] add infinite comment list --- lib/pages/community.dart | 34 +++++++++++++++---------- lib/pages/instance.dart | 17 +++++++++---- lib/widgets/sortable_infinite_list.dart | 19 +++++++++++++- 3 files changed, 51 insertions(+), 19 deletions(-) diff --git a/lib/pages/community.dart b/lib/pages/community.dart index 78f3e73..4c7bda5 100644 --- a/lib/pages/community.dart +++ b/lib/pages/community.dart @@ -18,8 +18,8 @@ import '../util/text_color.dart'; import '../widgets/badge.dart'; import '../widgets/bottom_modal.dart'; import '../widgets/fullscreenable_image.dart'; -import '../widgets/infinite_post_list.dart'; import '../widgets/markdown_text.dart'; +import '../widgets/sortable_infinite_list.dart'; class CommunityPage extends HookWidget { final CommunityView _community; @@ -209,19 +209,27 @@ class CommunityPage extends HookWidget { body: TabBarView( children: [ InfinitePostList( - fetcher: (page, batchSize, sort) => - LemmyApi(community.instanceUrl).v1.getPosts( - type: PostListingType.community, - sort: sort, - communityId: community.id, - page: page, - // limit: 10, - )), - ListView( - children: [ - Center(child: Text('comments go here')), - ], + fetcher: (page, batchSize, sort) => + LemmyApi(community.instanceUrl).v1.getPosts( + type: PostListingType.community, + sort: sort, + communityId: community.id, + page: page, + limit: 10, + ), ), + InfiniteCommentList( + fetcher: (page, batchSize, sortType) => + LemmyApi(community.instanceUrl).v1.getComments( + communityId: community.id, + auth: accountsStore + .defaultTokenFor(community.instanceUrl) + ?.raw, + type: CommentListingType.community, + sort: sortType, + limit: batchSize, + page: page, + )), _AboutTab( community: community, moderators: fullCommunitySnap.data?.moderators, diff --git a/lib/pages/instance.dart b/lib/pages/instance.dart index 345390d..36e2857 100644 --- a/lib/pages/instance.dart +++ b/lib/pages/instance.dart @@ -38,6 +38,7 @@ class InstancePage extends HookWidget { final theme = Theme.of(context); final siteSnap = useFuture(siteFuture); final colorOnCard = textColorBasedOnBackground(theme.cardColor); + final accStore = useAccountsStore(); if (!siteSnap.hasData) { return Scaffold( @@ -220,13 +221,19 @@ class InstancePage extends HookWidget { // TODO: switch between all and subscribed type: PostListingType.all, sort: sort, + limit: batchSize, page: page, + auth: accStore.defaultTokenFor(instanceUrl)?.raw, + )), + InfiniteCommentList( + fetcher: (page, batchSize, sort) => + LemmyApi(instanceUrl).v1.getComments( + type: CommentListingType.all, + sort: sort, + limit: batchSize, + page: page, + auth: accStore.defaultTokenFor(instanceUrl)?.raw, )), - ListView( - children: [ - Center(child: Text('comments go here')), - ], - ), _AboutTab(site, communitiesFuture: communitiesFuture, instanceUrl: instanceUrl), diff --git a/lib/widgets/sortable_infinite_list.dart b/lib/widgets/sortable_infinite_list.dart index d4f99ab..f729485 100644 --- a/lib/widgets/sortable_infinite_list.dart +++ b/lib/widgets/sortable_infinite_list.dart @@ -1,10 +1,12 @@ import 'package:flutter/material.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; -import 'package:lemmur/widgets/post.dart'; import 'package:lemmy_api_client/lemmy_api_client.dart'; +import '../comment_tree.dart'; import '../hooks/infinite_scroll.dart'; +import 'comment.dart'; import 'infinite_scroll.dart'; +import 'post.dart'; import 'post_list_options.dart'; /// Infinite list of posts @@ -65,3 +67,18 @@ class InfinitePostList extends StatelessWidget { ); } } + +class InfiniteCommentList extends StatelessWidget { + final Future> Function( + int page, int batchSize, SortType sortType) fetcher; + + InfiniteCommentList({this.fetcher}); + + Widget build(BuildContext context) => SortableInfiniteList( + builder: (comment) => Comment( + CommentTree(comment), + postCreatorId: null, + ), + fetcher: fetcher, + ); +}