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,
|
create: (context) => fullPostStore,
|
||||||
builder: (context, store) => AsyncStoreListener(
|
builder: (context, store) => AsyncStoreListener(
|
||||||
asyncStore: context.read<FullPostStore>().fullPostState,
|
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(),
|
child: const _FullPostPage(),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,15 +75,9 @@ class _FullPostPage extends HookWidget {
|
||||||
body: Center(
|
body: Center(
|
||||||
child: (store.fullPostState.isLoading)
|
child: (store.fullPostState.isLoading)
|
||||||
? const CircularProgressIndicator.adaptive()
|
? const CircularProgressIndicator.adaptive()
|
||||||
: Column(
|
: FailedToLoad(
|
||||||
children: [
|
message: 'Post failed to load', refresh: store.refresh),
|
||||||
const Text('Post failed to load'),
|
),
|
||||||
ElevatedButton.icon(
|
|
||||||
onPressed: store.refresh,
|
|
||||||
icon: const Icon(Icons.refresh),
|
|
||||||
label: const Text('try again'))
|
|
||||||
],
|
|
||||||
)),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +116,7 @@ class _FullPostPage extends HookWidget {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
IconButton(icon: const Icon(Icons.share), onPressed: sharePost),
|
IconButton(icon: Icon(shareIcon), onPressed: sharePost),
|
||||||
Provider<PostStore>(
|
Provider<PostStore>(
|
||||||
create: (context) => store.postStore!,
|
create: (context) => store.postStore!,
|
||||||
child: const SavePostButton(),
|
child: const SavePostButton(),
|
||||||
|
@ -168,12 +170,8 @@ class _Comments extends StatelessWidget {
|
||||||
} else if (store.fullPostState.errorTerm != null) {
|
} else if (store.fullPostState.errorTerm != null) {
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 30),
|
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 30),
|
||||||
child: Column(
|
child: FailedToLoad(
|
||||||
children: [
|
message: 'Comments failed to load', refresh: store.refresh),
|
||||||
const Icon(Icons.error),
|
|
||||||
Text('Error: ${store.fullPostState.errorTerm}')
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return const Padding(
|
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);
|
postStore ??= PostStore(result.postView);
|
||||||
|
|
||||||
fullPostView = result;
|
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) =>
|
void addComment(CommentView commentView) =>
|
||||||
newComments.insert(0, commentView);
|
newComments.insert(0, commentView);
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,28 @@ mixin _$FullPostStore on _FullPostStore, Store {
|
||||||
return _$refreshAsyncAction.run(() => super.refresh());
|
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
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return '''
|
return '''
|
||||||
|
|
|
@ -11,7 +11,8 @@ class PostLinkPreview extends StatelessWidget {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ObserverBuilder<PostStore>(
|
return ObserverBuilder<PostStore>(
|
||||||
builder: (context, store) {
|
builder: (context, store) {
|
||||||
if (store.postView.post.url == null ||
|
if (store.hasMedia ||
|
||||||
|
store.postView.post.url == null ||
|
||||||
store.postView.post.url!.isEmpty) {
|
store.postView.post.url!.isEmpty) {
|
||||||
return const SizedBox();
|
return const SizedBox();
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,9 +119,14 @@ class PostMoreMenu extends HookWidget {
|
||||||
? const CircularProgressIndicator.adaptive()
|
? const CircularProgressIndicator.adaptive()
|
||||||
: const Icon(Icons.block),
|
: const Icon(Icons.block),
|
||||||
title: Text(
|
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(
|
ListTile(
|
||||||
leading: const Icon(Icons.info_outline),
|
leading: const Icon(Icons.info_outline),
|
||||||
title: const Text('Nerd stuff'),
|
title: const Text('Nerd stuff'),
|
||||||
|
|
Loading…
Reference in New Issue