1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 04:49:21 +00:00

Can load older posts on user page

This commit is contained in:
Pierre HUBERT 2020-04-16 09:17:10 +02:00
parent c7502e6a04
commit 302e5f22ce
2 changed files with 29 additions and 14 deletions

View File

@ -67,10 +67,9 @@ class PostsHelper {
/// Get the list of posts of a user
Future<PostsList> getUserPosts(int userID, {int from = 0}) async {
final response = await APIRequest(
uri: "posts/get_user",
needLogin: true,
args: {"userID": userID.toString(), "startFrom": from.toString()})
final response = await (APIRequest(uri: "posts/get_user", needLogin: true)
..addInt("userID", userID)
..addInt("startFrom", from == 0 ? 0 : from - 1))
.exec();
if (response.code != 200) return null;

View File

@ -7,6 +7,7 @@ import 'package:comunic/ui/routes/user_access_denied_route.dart';
import 'package:comunic/ui/widgets/network_image_widget.dart';
import 'package:comunic/ui/widgets/post_create_form_widget.dart';
import 'package:comunic/ui/widgets/posts_list_widget.dart';
import 'package:comunic/ui/widgets/scroll_watcher.dart';
import 'package:comunic/utils/conversations_utils.dart';
import 'package:comunic/utils/intl_utils.dart';
import 'package:comunic/utils/ui_utils.dart';
@ -43,8 +44,19 @@ class _UserPageRouteState extends State<UserPageRoute> {
GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
GlobalKey<RefreshIndicatorState>();
// Scroll detection (to load more user posts automatically)
final _postListKey = GlobalKey<PostsListWidgetState>();
ScrollWatcher _scrollWatcher;
_setStatus(_PageStatus s) => setState(() => _status = s);
@override
void initState() {
_scrollWatcher = ScrollWatcher(
onReachBottom: () => _postListKey.currentState.reachedPostsBottom());
super.initState();
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
@ -69,8 +81,8 @@ class _UserPageRouteState extends State<UserPageRoute> {
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (c) => UserAccessDeniedRoute(
userID: widget.userID,
),
userID: widget.userID,
),
),
);
}
@ -88,6 +100,7 @@ class _UserPageRouteState extends State<UserPageRoute> {
child: CustomScrollView(
slivers: <Widget>[_buildHeader(), _buildBody()],
physics: AlwaysScrollableScrollPhysics(),
controller: _scrollWatcher,
),
onRefresh: _getUserInfo,
),
@ -165,12 +178,12 @@ class _UserPageRouteState extends State<UserPageRoute> {
),
PopupMenuButton<_MenuOptions>(
itemBuilder: (c) => [
PopupMenuItem(
child: Text(tr("Friends")),
enabled: _userInfo != null,
value: _MenuOptions.FRIENDS_LIST,
)
],
PopupMenuItem(
child: Text(tr("Friends")),
enabled: _userInfo != null,
value: _MenuOptions.FRIENDS_LIST,
)
],
onSelected: _selectedMenuOption,
),
],
@ -192,7 +205,10 @@ class _UserPageRouteState extends State<UserPageRoute> {
// Posts list
PostsListWidget(
key: _postListKey,
getPostsList: () => _postsHelper.getUserPosts(widget.userID),
getOlder: (from) =>
_postsHelper.getUserPosts(widget.userID, from: from),
showPostsTarget: false,
buildListView: false,
),
@ -208,8 +224,8 @@ class _UserPageRouteState extends State<UserPageRoute> {
Navigator.of(context).push(
MaterialPageRoute(
builder: (c) => OtherUserFriendsListRoute(
user: _userInfo,
),
user: _userInfo,
),
),
);
break;