silly stuff. constructor simplification. remove mistake

This commit is contained in:
Filip Krawczyk 2021-10-19 23:42:28 +02:00
parent fb78c5654b
commit f9d657cac6
1 changed files with 88 additions and 117 deletions

View File

@ -25,24 +25,7 @@ import 'full_post_store.dart';
/// Displays a post with its comment section /// Displays a post with its comment section
class FullPostPage extends HookWidget { class FullPostPage extends HookWidget {
final String? instanceHost; const FullPostPage._();
final int? id;
final PostView? postView;
final PostStore? postStore;
const FullPostPage._({
required int this.id,
required String this.instanceHost,
}) : postView = null,
postStore = null;
const FullPostPage._fromPostView(PostView this.postView)
: id = null,
instanceHost = null,
postStore = null;
const FullPostPage._fromPostStore(PostStore this.postStore)
: id = null,
instanceHost = null,
postView = null;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -59,102 +42,92 @@ class FullPostPage extends HookWidget {
final name = data.communityView.community.originPreferredName; final name = data.communityView.community.originPreferredName;
return '${data.blocked ? 'Blocked' : 'Unblocked'} $name'; return '${data.blocked ? 'Blocked' : 'Unblocked'} $name';
}, },
child: AsyncStoreListener( child: ObserverBuilder<FullPostStore>(
asyncStore: context.read<FullPostStore>().fullPostState, builder: (context, store) {
child: AsyncStoreListener<BlockedCommunity>( Future<void> refresh() async {
asyncStore: context.read<FullPostStore>().communityBlockingState, unawaited(HapticFeedback.mediumImpact());
successMessageBuilder: (context, data) { await store.refresh(context
final name = data.communityView.community.originPreferredName; .read<AccountsStore>()
return '${data.blocked ? 'Blocked' : 'Unblocked'} $name'; .defaultUserDataFor(store.instanceHost)
}, ?.jwt);
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; final postStore = store.postStore;
if (postStore == null) { if (postStore == null) {
return Scaffold( return Scaffold(
appBar: AppBar(), appBar: AppBar(),
body: Center( body: Center(
child: (store.fullPostState.isLoading) child: (store.fullPostState.isLoading)
? const CircularProgressIndicator.adaptive() ? const CircularProgressIndicator.adaptive()
: FailedToLoad( : FailedToLoad(
message: 'Post failed to load', refresh: refresh), 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),
final post = postStore.postView; Provider.value(
value: postStore,
// VARIABLES child: const SavePostButton(),
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 IconButton(
? null icon: Icon(moreIcon),
: FloatingActionButton( onPressed: () => PostMoreMenuButton.show(
onPressed: loggedInAction((_) => comment()), context: context,
child: const Icon(Icons.comment), postStore: postStore,
), fullPostStore: store,
body: RefreshIndicator(
onRefresh: refresh,
child: ListView(
controller: scrollController,
physics: const AlwaysScrollableScrollPhysics(),
children: [
const SizedBox(height: 15),
PostTile.fromPostStore(postStore),
const CommentSection(),
],
), ),
)); ),
}, ],
), ),
), 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(),
],
),
));
},
), ),
), ),
); );
@ -169,10 +142,7 @@ class FullPostPage extends HookWidget {
create: (context) => create: (context) =>
FullPostStore(instanceHost: instanceHost, postId: id) FullPostStore(instanceHost: instanceHost, postId: id)
..refresh(_tryGetJwt(context, instanceHost)), ..refresh(_tryGetJwt(context, instanceHost)),
child: FullPostPage._( child: const FullPostPage._(),
id: id,
instanceHost: instanceHost,
),
), ),
); );
@ -180,14 +150,15 @@ class FullPostPage extends HookWidget {
builder: (context) => Provider( builder: (context) => Provider(
create: (context) => FullPostStore.fromPostView(postView) create: (context) => FullPostStore.fromPostView(postView)
..refresh(_tryGetJwt(context, postView.instanceHost)), ..refresh(_tryGetJwt(context, postView.instanceHost)),
child: FullPostPage._fromPostView(postView), child: const FullPostPage._(),
), ),
); );
static Route fromPostStoreRoute(PostStore postStore) => MaterialPageRoute( static Route fromPostStoreRoute(PostStore postStore) => MaterialPageRoute(
builder: (context) => Provider( builder: (context) => Provider(
create: (context) => FullPostStore.fromPostStore(postStore) create: (context) => FullPostStore.fromPostStore(postStore)
..refresh(_tryGetJwt(context, postStore.postView.instanceHost)), ..refresh(_tryGetJwt(context, postStore.postView.instanceHost)),
child: FullPostPage._fromPostStore(postStore)), child: const FullPostPage._(),
),
); );
} }