merge wrapper and proper FullPost since the separation is not needed anymore
This commit is contained in:
parent
43f2a73ad8
commit
fb78c5654b
|
@ -23,7 +23,8 @@ import '../../widgets/write_comment.dart';
|
|||
import 'comment_section.dart';
|
||||
import 'full_post_store.dart';
|
||||
|
||||
class FullPostPage extends StatelessWidget {
|
||||
/// Displays a post with its comment section
|
||||
class FullPostPage extends HookWidget {
|
||||
final String? instanceHost;
|
||||
final int? id;
|
||||
final PostView? postView;
|
||||
|
@ -45,6 +46,11 @@ class FullPostPage extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scrollController = useScrollController();
|
||||
|
||||
final loggedInAction =
|
||||
useLoggedInAction(context.read<FullPostStore>().instanceHost);
|
||||
|
||||
return AsyncStoreListener(
|
||||
asyncStore: context.read<FullPostStore>().fullPostState,
|
||||
child: AsyncStoreListener<BlockedCommunity>(
|
||||
|
@ -53,7 +59,103 @@ class FullPostPage extends StatelessWidget {
|
|||
final name = data.communityView.community.originPreferredName;
|
||||
return '${data.blocked ? 'Blocked' : 'Unblocked'} $name';
|
||||
},
|
||||
child: const _FullPostPage(),
|
||||
child: AsyncStoreListener(
|
||||
asyncStore: context.read<FullPostStore>().fullPostState,
|
||||
child: AsyncStoreListener<BlockedCommunity>(
|
||||
asyncStore: context.read<FullPostStore>().communityBlockingState,
|
||||
successMessageBuilder: (context, data) {
|
||||
final name = data.communityView.community.originPreferredName;
|
||||
return '${data.blocked ? 'Blocked' : 'Unblocked'} $name';
|
||||
},
|
||||
child: ObserverBuilder<FullPostStore>(
|
||||
builder: (context, store) {
|
||||
Future<void> refresh() async {
|
||||
unawaited(HapticFeedback.mediumImpact());
|
||||
await store.refresh(context
|
||||
.read<AccountsStore>()
|
||||
.defaultUserDataFor(store.instanceHost)
|
||||
?.jwt);
|
||||
}
|
||||
|
||||
final postStore = store.postStore;
|
||||
|
||||
if (postStore == null) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(),
|
||||
body: Center(
|
||||
child: (store.fullPostState.isLoading)
|
||||
? const CircularProgressIndicator.adaptive()
|
||||
: FailedToLoad(
|
||||
message: 'Post failed to load', refresh: refresh),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final post = postStore.postView;
|
||||
|
||||
// VARIABLES
|
||||
|
||||
sharePost() => share(post.post.apId, context: context);
|
||||
|
||||
comment() async {
|
||||
final newComment = await Navigator.of(context).push(
|
||||
WriteComment.toPostRoute(post.post),
|
||||
);
|
||||
|
||||
if (newComment != null) {
|
||||
store.addComment(newComment);
|
||||
}
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: false,
|
||||
title: RevealAfterScroll(
|
||||
scrollController: scrollController,
|
||||
after: 65,
|
||||
child: Text(
|
||||
post.community.originPreferredName,
|
||||
overflow: TextOverflow.fade,
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
IconButton(icon: Icon(shareIcon), onPressed: sharePost),
|
||||
Provider.value(
|
||||
value: postStore,
|
||||
child: const SavePostButton(),
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(moreIcon),
|
||||
onPressed: () => PostMoreMenuButton.show(
|
||||
context: context,
|
||||
postStore: postStore,
|
||||
fullPostStore: store,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
floatingActionButton: post.post.locked
|
||||
? null
|
||||
: FloatingActionButton(
|
||||
onPressed: loggedInAction((_) => comment()),
|
||||
child: const Icon(Icons.comment),
|
||||
),
|
||||
body: RefreshIndicator(
|
||||
onRefresh: refresh,
|
||||
child: ListView(
|
||||
controller: scrollController,
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
children: [
|
||||
const SizedBox(height: 15),
|
||||
PostTile.fromPostStore(postStore),
|
||||
const CommentSection(),
|
||||
],
|
||||
),
|
||||
));
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -89,117 +191,6 @@ class FullPostPage extends StatelessWidget {
|
|||
);
|
||||
}
|
||||
|
||||
/// Displays a post with its comment section
|
||||
class _FullPostPage extends HookWidget {
|
||||
const _FullPostPage();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final scrollController = useScrollController();
|
||||
|
||||
final loggedInAction =
|
||||
useLoggedInAction(context.read<FullPostStore>().instanceHost);
|
||||
|
||||
return AsyncStoreListener(
|
||||
asyncStore: context.read<FullPostStore>().fullPostState,
|
||||
child: AsyncStoreListener<BlockedCommunity>(
|
||||
asyncStore: context.read<FullPostStore>().communityBlockingState,
|
||||
successMessageBuilder: (context, data) {
|
||||
final name = data.communityView.community.originPreferredName;
|
||||
return '${data.blocked ? 'Blocked' : 'Unblocked'} $name';
|
||||
},
|
||||
child: ObserverBuilder<FullPostStore>(
|
||||
builder: (context, store) {
|
||||
Future<void> refresh() async {
|
||||
unawaited(HapticFeedback.mediumImpact());
|
||||
await store.refresh(context
|
||||
.read<AccountsStore>()
|
||||
.defaultUserDataFor(store.instanceHost)
|
||||
?.jwt);
|
||||
}
|
||||
|
||||
final postStore = store.postStore;
|
||||
|
||||
if (postStore == null) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(),
|
||||
body: Center(
|
||||
child: (store.fullPostState.isLoading)
|
||||
? const CircularProgressIndicator.adaptive()
|
||||
: FailedToLoad(
|
||||
message: 'Post failed to load', refresh: refresh),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final post = postStore.postView;
|
||||
|
||||
// VARIABLES
|
||||
|
||||
sharePost() => share(post.post.apId, context: context);
|
||||
|
||||
comment() async {
|
||||
final newComment = await Navigator.of(context).push(
|
||||
WriteComment.toPostRoute(post.post),
|
||||
);
|
||||
|
||||
if (newComment != null) {
|
||||
store.addComment(newComment);
|
||||
}
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: false,
|
||||
title: RevealAfterScroll(
|
||||
scrollController: scrollController,
|
||||
after: 65,
|
||||
child: Text(
|
||||
post.community.originPreferredName,
|
||||
overflow: TextOverflow.fade,
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
IconButton(icon: Icon(shareIcon), onPressed: sharePost),
|
||||
Provider.value(
|
||||
value: postStore,
|
||||
child: const SavePostButton(),
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(moreIcon),
|
||||
onPressed: () => PostMoreMenuButton.show(
|
||||
context: context,
|
||||
postStore: postStore,
|
||||
fullPostStore: store,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
floatingActionButton: post.post.locked
|
||||
? null
|
||||
: FloatingActionButton(
|
||||
onPressed: loggedInAction((_) => comment()),
|
||||
child: const Icon(Icons.comment),
|
||||
),
|
||||
body: RefreshIndicator(
|
||||
onRefresh: refresh,
|
||||
child: ListView(
|
||||
controller: scrollController,
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
children: [
|
||||
const SizedBox(height: 15),
|
||||
PostTile.fromPostStore(postStore),
|
||||
const CommentSection(),
|
||||
],
|
||||
),
|
||||
));
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class FailedToLoad extends StatelessWidget {
|
||||
final String message;
|
||||
final VoidCallback refresh;
|
||||
|
|
Loading…
Reference in New Issue