add community blocking + minor fixes
minor fixes: * make link preview show up in proper times * ListTile for (un)blocking communities had a thing switched around
This commit is contained in:
parent
5ca4748572
commit
88466dfd73
|
@ -39,8 +39,16 @@ class FullPostPage extends StatelessWidget {
|
|||
create: (context) => fullPostStore,
|
||||
builder: (context, store) => AsyncStoreListener(
|
||||
asyncStore: context.read<FullPostStore>().fullPostState,
|
||||
child: AsyncStoreListener<BlockedCommunity>(
|
||||
asyncStore: context.read<FullPostStore>().communityBlockingState,
|
||||
successMessageBuilder: (context, asyncStore) {
|
||||
final name =
|
||||
asyncStore.data.communityView.community.originPreferredName;
|
||||
return '${asyncStore.data.blocked ? 'Blocked' : 'Unblocked'} $name';
|
||||
},
|
||||
child: const _FullPostPage(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -67,15 +75,9 @@ class _FullPostPage extends HookWidget {
|
|||
body: Center(
|
||||
child: (store.fullPostState.isLoading)
|
||||
? const CircularProgressIndicator.adaptive()
|
||||
: Column(
|
||||
children: [
|
||||
const Text('Post failed to load'),
|
||||
ElevatedButton.icon(
|
||||
onPressed: store.refresh,
|
||||
icon: const Icon(Icons.refresh),
|
||||
label: const Text('try again'))
|
||||
],
|
||||
)),
|
||||
: FailedToLoad(
|
||||
message: 'Post failed to load', refresh: store.refresh),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -114,7 +116,7 @@ class _FullPostPage extends HookWidget {
|
|||
),
|
||||
),
|
||||
actions: [
|
||||
IconButton(icon: const Icon(Icons.share), onPressed: sharePost),
|
||||
IconButton(icon: Icon(shareIcon), onPressed: sharePost),
|
||||
Provider<PostStore>(
|
||||
create: (context) => store.postStore!,
|
||||
child: const SavePostButton(),
|
||||
|
@ -168,12 +170,8 @@ class _Comments extends StatelessWidget {
|
|||
} else if (store.fullPostState.errorTerm != null) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 30),
|
||||
child: Column(
|
||||
children: [
|
||||
const Icon(Icons.error),
|
||||
Text('Error: ${store.fullPostState.errorTerm}')
|
||||
],
|
||||
),
|
||||
child: FailedToLoad(
|
||||
message: 'Comments failed to load', refresh: store.refresh),
|
||||
);
|
||||
} else {
|
||||
return const Padding(
|
||||
|
@ -185,3 +183,26 @@ class _Comments extends StatelessWidget {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
class FailedToLoad extends StatelessWidget {
|
||||
final String message;
|
||||
final VoidCallback refresh;
|
||||
|
||||
const FailedToLoad({required this.refresh, required this.message});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(message),
|
||||
const SizedBox(height: 5),
|
||||
ElevatedButton.icon(
|
||||
onPressed: refresh,
|
||||
icon: const Icon(Icons.refresh),
|
||||
label: const Text('try again'),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,10 +40,25 @@ abstract class _FullPostStore with Store {
|
|||
postStore ??= PostStore(result.postView);
|
||||
|
||||
fullPostView = result;
|
||||
postStore?.postView = result.postView;
|
||||
postStore!.postView = result.postView;
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
Future<void> blockCommunity(Jwt token) async {
|
||||
final result = await communityBlockingState.runLemmy(
|
||||
instanceHost,
|
||||
BlockCommunity(
|
||||
communityId: fullPostView!.communityView.community.id,
|
||||
block: !fullPostView!.communityView.blocked,
|
||||
auth: token.raw));
|
||||
if (result != null) {
|
||||
fullPostView =
|
||||
fullPostView!.copyWith(communityView: result.communityView);
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
void addComment(CommentView commentView) =>
|
||||
newComments.insert(0, commentView);
|
||||
|
||||
|
|
|
@ -76,6 +76,28 @@ mixin _$FullPostStore on _FullPostStore, Store {
|
|||
return _$refreshAsyncAction.run(() => super.refresh());
|
||||
}
|
||||
|
||||
final _$blockCommunityAsyncAction =
|
||||
AsyncAction('_FullPostStore.blockCommunity');
|
||||
|
||||
@override
|
||||
Future<void> blockCommunity(Jwt token) {
|
||||
return _$blockCommunityAsyncAction.run(() => super.blockCommunity(token));
|
||||
}
|
||||
|
||||
final _$_FullPostStoreActionController =
|
||||
ActionController(name: '_FullPostStore');
|
||||
|
||||
@override
|
||||
void addComment(CommentView commentView) {
|
||||
final _$actionInfo = _$_FullPostStoreActionController.startAction(
|
||||
name: '_FullPostStore.addComment');
|
||||
try {
|
||||
return super.addComment(commentView);
|
||||
} finally {
|
||||
_$_FullPostStoreActionController.endAction(_$actionInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '''
|
||||
|
|
|
@ -11,7 +11,8 @@ class PostLinkPreview extends StatelessWidget {
|
|||
Widget build(BuildContext context) {
|
||||
return ObserverBuilder<PostStore>(
|
||||
builder: (context, store) {
|
||||
if (store.postView.post.url == null ||
|
||||
if (store.hasMedia ||
|
||||
store.postView.post.url == null ||
|
||||
store.postView.post.url!.isEmpty) {
|
||||
return const SizedBox();
|
||||
}
|
||||
|
|
|
@ -119,9 +119,14 @@ class PostMoreMenu extends HookWidget {
|
|||
? const CircularProgressIndicator.adaptive()
|
||||
: const Icon(Icons.block),
|
||||
title: Text(
|
||||
'${store.fullPostView!.communityView.blocked ? 'Block' : 'Unblock'} community'),
|
||||
'${store.fullPostView!.communityView.blocked ? 'Unblock' : 'Block'} community'),
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
loggedInAction(store.blockCommunity)();
|
||||
},
|
||||
);
|
||||
}),
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.info_outline),
|
||||
title: const Text('Nerd stuff'),
|
||||
|
|
Loading…
Reference in New Issue