mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-25 22:39:22 +00:00
Display user posts
This commit is contained in:
parent
f374215c0c
commit
dd1a130436
@ -59,6 +59,28 @@ 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()
|
||||||
|
}
|
||||||
|
).exec();
|
||||||
|
|
||||||
|
if (response.code != 200) return null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Parse & return the list of posts
|
||||||
|
return PostsList()..addAll(response.getArray().map((f) => _apiToPost(f)));
|
||||||
|
} catch (e) {
|
||||||
|
print(e.toString());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Update a post content
|
/// Update a post content
|
||||||
Future<bool> updateContent(int id, String newContent) async {
|
Future<bool> updateContent(int id, String newContent) async {
|
||||||
return (await APIRequest(
|
return (await APIRequest(
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
|
import 'package:comunic/helpers/posts_helper.dart';
|
||||||
import 'package:comunic/helpers/users_helper.dart';
|
import 'package:comunic/helpers/users_helper.dart';
|
||||||
import 'package:comunic/models/advanced_user_info.dart';
|
import 'package:comunic/models/advanced_user_info.dart';
|
||||||
import 'package:comunic/ui/widgets/network_image_widget.dart';
|
import 'package:comunic/ui/widgets/network_image_widget.dart';
|
||||||
|
import 'package:comunic/ui/widgets/posts_list_widget.dart';
|
||||||
import 'package:comunic/utils/intl_utils.dart';
|
import 'package:comunic/utils/intl_utils.dart';
|
||||||
import 'package:comunic/utils/ui_utils.dart';
|
import 'package:comunic/utils/ui_utils.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@ -25,6 +27,7 @@ class UserPageRoute extends StatefulWidget {
|
|||||||
class _UserPageRouteState extends State<UserPageRoute> {
|
class _UserPageRouteState extends State<UserPageRoute> {
|
||||||
// Helpers
|
// Helpers
|
||||||
final usersHelper = UsersHelper();
|
final usersHelper = UsersHelper();
|
||||||
|
final PostsHelper _postsHelper = PostsHelper();
|
||||||
|
|
||||||
// Objects members
|
// Objects members
|
||||||
final double _appBarHeight = 256.0;
|
final double _appBarHeight = 256.0;
|
||||||
@ -132,7 +135,15 @@ class _UserPageRouteState extends State<UserPageRoute> {
|
|||||||
|
|
||||||
Widget _buildBody() {
|
Widget _buildBody() {
|
||||||
return SliverList(
|
return SliverList(
|
||||||
delegate: SliverChildListDelegate(<Widget>[]),
|
delegate: SliverChildListDelegate(
|
||||||
|
<Widget>[
|
||||||
|
PostsListWidget(
|
||||||
|
getPostsList: () => _postsHelper.getUserPosts(widget.userID),
|
||||||
|
showPostsTarget: false,
|
||||||
|
buildListView: false,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,13 +19,16 @@ import 'package:flutter/material.dart';
|
|||||||
class PostsListWidget extends StatefulWidget {
|
class PostsListWidget extends StatefulWidget {
|
||||||
final Future<PostsList> Function() getPostsList;
|
final Future<PostsList> Function() getPostsList;
|
||||||
final bool showPostsTarget;
|
final bool showPostsTarget;
|
||||||
|
final bool buildListView;
|
||||||
|
|
||||||
const PostsListWidget({
|
const PostsListWidget({
|
||||||
Key key,
|
Key key,
|
||||||
@required this.getPostsList,
|
@required this.getPostsList,
|
||||||
@required this.showPostsTarget,
|
@required this.showPostsTarget,
|
||||||
|
this.buildListView = true,
|
||||||
}) : assert(getPostsList != null),
|
}) : assert(getPostsList != null),
|
||||||
assert(showPostsTarget != null),
|
assert(showPostsTarget != null),
|
||||||
|
assert(buildListView != null),
|
||||||
super(key: key);
|
super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -67,7 +70,7 @@ class _PostsListWidgetState extends State<PostsListWidget> {
|
|||||||
|
|
||||||
final groups = await _groupsHelper.getList(list.groupsID);
|
final groups = await _groupsHelper.getList(list.groupsID);
|
||||||
|
|
||||||
if(groups == null) return _loadError();
|
if (groups == null) return _loadError();
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_list = list;
|
_list = list;
|
||||||
@ -83,13 +86,26 @@ class _PostsListWidgetState extends State<PostsListWidget> {
|
|||||||
Widget _buildListView() {
|
Widget _buildListView() {
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
itemCount: _list.length,
|
itemCount: _list.length,
|
||||||
itemBuilder: (c, i) => PostTile(
|
itemBuilder: _buildItem,
|
||||||
post: _list[i],
|
);
|
||||||
usersInfo: _users,
|
}
|
||||||
groupsInfo: _groups,
|
|
||||||
onDeletedPost: _removePost,
|
Widget _buildColumn() {
|
||||||
showPostTarget: widget.showPostsTarget,
|
return Column(
|
||||||
),
|
children: List.generate(
|
||||||
|
_list.length,
|
||||||
|
(i) => _buildItem(null, i),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildItem(BuildContext context, int index) {
|
||||||
|
return PostTile(
|
||||||
|
post: _list[index],
|
||||||
|
usersInfo: _users,
|
||||||
|
groupsInfo: _groups,
|
||||||
|
onDeletedPost: _removePost,
|
||||||
|
showPostTarget: widget.showPostsTarget,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +113,7 @@ class _PostsListWidgetState extends State<PostsListWidget> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (_error == ErrorLevel.MAJOR) return _buildErrorCard();
|
if (_error == ErrorLevel.MAJOR) return _buildErrorCard();
|
||||||
if (_list == null) return buildCenteredProgressBar();
|
if (_list == null) return buildCenteredProgressBar();
|
||||||
return _buildListView();
|
return widget.buildListView ? _buildListView() : _buildColumn();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _removePost(Post post) => setState(() => _list.remove(post));
|
void _removePost(Post post) => setState(() => _list.remove(post));
|
||||||
|
Loading…
Reference in New Issue
Block a user