lemmur-app-android/lib/pages/saved_page.dart

71 lines
2.0 KiB
Dart
Raw Normal View History

2021-02-09 19:25:17 +01:00
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
2021-04-05 20:14:39 +02:00
import 'package:lemmy_api_client/v3.dart';
2021-02-09 19:25:17 +01:00
2021-02-09 20:39:45 +01:00
import '../hooks/stores.dart';
2021-03-01 14:21:45 +01:00
import '../l10n/l10n.dart';
2021-02-09 20:39:45 +01:00
import '../widgets/sortable_infinite_list.dart';
2021-02-09 19:25:17 +01:00
/// 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();
if (accountStore.hasNoAccount) {
Scaffold(
appBar: AppBar(),
body: const Center(
child: Text('no account found'),
),
);
}
2021-02-09 19:25:17 +01:00
return DefaultTabController(
length: 2,
child: Scaffold(
appBar: AppBar(
title: Text(L10n.of(context).saved),
2021-03-01 14:21:45 +01:00
bottom: TabBar(
2021-02-09 19:25:17 +01:00
tabs: [
Tab(text: L10n.of(context).posts),
Tab(text: L10n.of(context).comments),
2021-02-09 19:25:17 +01:00
],
),
),
body: TabBarView(
children: [
InfinitePostList(
fetcher: (page, batchSize, sortType) =>
LemmyApiV3(accountStore.defaultInstanceHost!).run(
2021-04-05 20:14:39 +02:00
GetPosts(
type: PostListingType.all,
sort: sortType,
savedOnly: true,
page: page,
limit: batchSize,
2021-04-11 18:27:22 +02:00
auth: accountStore.defaultUserData!.jwt.raw,
2021-04-05 20:14:39 +02:00
),
),
2021-02-09 19:25:17 +01:00
),
InfiniteCommentList(
fetcher: (page, batchSize, sortType) =>
LemmyApiV3(accountStore.defaultInstanceHost!).run(
2021-04-05 20:14:39 +02:00
GetComments(
type: CommentListingType.all,
sort: sortType,
savedOnly: true,
page: page,
limit: batchSize,
2021-04-11 18:27:22 +02:00
auth: accountStore.defaultUserData!.jwt.raw,
2021-04-05 20:14:39 +02:00
),
),
2021-02-09 19:25:17 +01:00
),
],
),
),
);
}
}