Add saved page

This commit is contained in:
shilangyu 2021-02-09 19:25:17 +01:00
parent ebf46a073b
commit 2b95ea5f0f
2 changed files with 69 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import '../hooks/stores.dart';
import '../util/goto.dart';
import '../widgets/radio_picker.dart';
import '../widgets/user_profile.dart';
import 'saved/saved_page.dart';
import 'settings.dart';
/// Profile page for a logged in user. The difference between this and
@ -51,6 +52,10 @@ class UserProfileTab extends HookWidget {
return Scaffold(
extendBodyBehindAppBar: true,
appBar: AppBar(
leading: IconButton(
onPressed: () => goTo(context, (context) => SavedPage()),
icon: const Icon(Icons.bookmark),
),
title: RadioPicker<String>(
title: 'account',
values: accountsStore.loggedInInstances

View File

@ -0,0 +1,64 @@
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:lemmy_api_client/v2.dart';
import '../../hooks/stores.dart';
import '../../widgets/sortable_infinite_list.dart';
/// Page with saved posts/comments. Fetches such saved data from the default user
/// Assumes there is at least one logged in user
class SavedPage extends HookWidget {
@override
Widget build(BuildContext context) {
final accountStore = useAccountsStore();
return DefaultTabController(
length: 2,
child: Scaffold(
appBar: AppBar(
title: const Text('Saved'),
bottom: const TabBar(
tabs: [
Tab(text: 'Posts'),
Tab(text: 'Comments'),
],
),
),
body: TabBarView(
children: [
InfinitePostList(
fetcher: (page, batchSize, sortType) =>
LemmyApiV2(accountStore.defaultInstanceHost)
.run(
GetUserDetails(
userId: accountStore.defaultToken.payload.id,
sort: sortType,
savedOnly: true,
page: page,
limit: batchSize,
auth: accountStore.defaultToken.raw,
),
)
.then((value) => value.posts),
),
InfiniteCommentList(
fetcher: (page, batchSize, sortType) =>
LemmyApiV2(accountStore.defaultInstanceHost)
.run(
GetUserDetails(
userId: accountStore.defaultToken.payload.id,
sort: sortType,
savedOnly: true,
page: page,
limit: batchSize,
auth: accountStore.defaultToken.raw,
),
)
.then((value) => value.comments),
),
],
),
),
);
}
}