From 2b95ea5f0f747ed52475667b64486e64a4eb4705 Mon Sep 17 00:00:00 2001 From: shilangyu Date: Tue, 9 Feb 2021 19:25:17 +0100 Subject: [PATCH] Add saved page --- lib/pages/profile_tab.dart | 5 +++ lib/pages/saved/saved_page.dart | 64 +++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 lib/pages/saved/saved_page.dart diff --git a/lib/pages/profile_tab.dart b/lib/pages/profile_tab.dart index 02eefd1..b8c49ee 100644 --- a/lib/pages/profile_tab.dart +++ b/lib/pages/profile_tab.dart @@ -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( title: 'account', values: accountsStore.loggedInInstances diff --git a/lib/pages/saved/saved_page.dart b/lib/pages/saved/saved_page.dart new file mode 100644 index 0000000..5188ce1 --- /dev/null +++ b/lib/pages/saved/saved_page.dart @@ -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), + ), + ], + ), + ), + ); + } +}