add infinite comment list

This commit is contained in:
krawieck 2020-09-29 10:53:40 +02:00
parent 379d2204ae
commit aefcf50fd1
3 changed files with 51 additions and 19 deletions

View File

@ -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,

View File

@ -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),

View File

@ -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<List<CommentView>> Function(
int page, int batchSize, SortType sortType) fetcher;
InfiniteCommentList({this.fetcher});
Widget build(BuildContext context) => SortableInfiniteList<CommentView>(
builder: (comment) => Comment(
CommentTree(comment),
postCreatorId: null,
),
fetcher: fetcher,
);
}