2020-09-02 00:05:42 +02:00
|
|
|
import 'package:esys_flutter_share/esys_flutter_share.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
2020-09-03 13:02:38 +02:00
|
|
|
import 'package:lemmy_api_client/lemmy_api_client.dart';
|
2020-09-02 00:05:42 +02:00
|
|
|
|
|
|
|
import '../widgets/comment_section.dart';
|
|
|
|
import '../widgets/post.dart';
|
|
|
|
|
|
|
|
class FullPostPage extends HookWidget {
|
|
|
|
final Future<FullPost> fullPost;
|
|
|
|
final PostView post;
|
|
|
|
|
2020-09-03 13:02:38 +02:00
|
|
|
FullPostPage({@required int id, @required String instanceUrl})
|
|
|
|
: assert(id != null),
|
|
|
|
assert(instanceUrl != null),
|
|
|
|
fullPost = LemmyApi(instanceUrl).v1.getPost(id: id),
|
|
|
|
post = null;
|
|
|
|
FullPostPage.fromPostView(this.post)
|
|
|
|
: fullPost = LemmyApi(post.communityActorId.split('/')[2])
|
|
|
|
.v1
|
|
|
|
.getPost(id: post.id);
|
2020-09-02 00:05:42 +02:00
|
|
|
|
|
|
|
void sharePost() => Share.text('Share post', post.apId, 'text/plain');
|
|
|
|
|
|
|
|
void savePost() {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-09-03 13:56:37 +02:00
|
|
|
final fullPostSnap = useFuture(this.fullPost);
|
|
|
|
final fullPost = fullPostSnap.data;
|
2020-09-02 00:05:42 +02:00
|
|
|
|
|
|
|
final savedIcon = () {
|
2020-09-03 13:56:37 +02:00
|
|
|
if (fullPostSnap.hasData) {
|
2020-09-02 00:05:42 +02:00
|
|
|
if (fullPost.post.saved == null || !fullPost.post.saved) {
|
|
|
|
return Icons.bookmark_border;
|
|
|
|
} else {
|
|
|
|
return Icons.bookmark;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (post != null) {
|
|
|
|
if (post.saved == null || !post.saved) {
|
|
|
|
return Icons.bookmark_border;
|
|
|
|
} else {
|
|
|
|
return Icons.bookmark;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Icons.bookmark_border;
|
|
|
|
}();
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
leading: BackButton(),
|
|
|
|
actions: [
|
|
|
|
IconButton(icon: Icon(Icons.share), onPressed: sharePost),
|
|
|
|
IconButton(icon: Icon(savedIcon), onPressed: savePost),
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(Icons.more_vert), onPressed: () {}), // TODO: more menu
|
|
|
|
],
|
|
|
|
),
|
2020-09-03 13:56:37 +02:00
|
|
|
body: fullPostSnap.hasData || post != null
|
2020-09-02 00:05:42 +02:00
|
|
|
// FUTURE SUCCESS
|
|
|
|
? ListView(
|
|
|
|
physics: const AlwaysScrollableScrollPhysics(),
|
|
|
|
children: [
|
2020-09-03 13:56:37 +02:00
|
|
|
if (fullPostSnap.hasData)
|
2020-09-02 00:05:42 +02:00
|
|
|
Post(fullPost.post, fullPost: true)
|
|
|
|
else if (post != null)
|
|
|
|
Post(post, fullPost: true)
|
|
|
|
else
|
|
|
|
CircularProgressIndicator(),
|
2020-09-03 13:56:37 +02:00
|
|
|
if (fullPostSnap.hasData)
|
2020-09-02 00:05:42 +02:00
|
|
|
CommentSection(fullPost.comments,
|
|
|
|
postCreatorId: fullPost.post.creatorId)
|
|
|
|
else
|
|
|
|
Container(
|
|
|
|
child: Center(child: CircularProgressIndicator()),
|
|
|
|
padding: EdgeInsets.only(top: 40),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
2020-09-03 13:56:37 +02:00
|
|
|
: fullPostSnap.hasError
|
2020-09-02 00:05:42 +02:00
|
|
|
// FUTURE FAILURE
|
|
|
|
? Center(
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Icon(Icons.error, size: 30),
|
|
|
|
Padding(padding: EdgeInsets.all(5)),
|
2020-09-03 13:56:37 +02:00
|
|
|
Text('ERROR: ${fullPostSnap.error.toString()}'),
|
2020-09-02 00:05:42 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
// FUTURE IN PROGRESS
|
|
|
|
: Container(
|
|
|
|
child: Center(child: CircularProgressIndicator()),
|
|
|
|
color: Theme.of(context).canvasColor),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|