2021-09-11 01:04:15 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2021-09-11 16:26:10 +02:00
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
2021-09-11 01:04:15 +02:00
|
|
|
import 'package:url_launcher/url_launcher.dart' as ul;
|
|
|
|
|
2021-09-11 16:26:10 +02:00
|
|
|
import '../../hooks/logged_in_action.dart';
|
2021-09-11 01:04:15 +02:00
|
|
|
import '../../pages/create_post.dart';
|
2021-10-01 23:39:43 +02:00
|
|
|
import '../../pages/full_post/full_post_store.dart';
|
2021-09-11 01:04:15 +02:00
|
|
|
import '../../stores/accounts_store.dart';
|
|
|
|
import '../../util/icons.dart';
|
|
|
|
import '../../util/observer_consumers.dart';
|
|
|
|
import '../bottom_modal.dart';
|
|
|
|
import '../info_table_popup.dart';
|
2021-10-24 22:36:41 +02:00
|
|
|
import '../report_dialog.dart';
|
2021-09-11 01:04:15 +02:00
|
|
|
import 'post_store.dart';
|
|
|
|
|
|
|
|
class PostMoreMenuButton extends StatelessWidget {
|
2021-09-11 16:26:10 +02:00
|
|
|
const PostMoreMenuButton();
|
2021-09-11 01:04:15 +02:00
|
|
|
|
2021-10-18 01:11:04 +02:00
|
|
|
static void show({
|
|
|
|
required BuildContext context,
|
|
|
|
required PostStore postStore,
|
|
|
|
required FullPostStore? fullPostStore,
|
|
|
|
}) {
|
|
|
|
// TODO: add blocking!
|
|
|
|
showBottomModal(
|
|
|
|
context: context,
|
|
|
|
builder: (context) =>
|
|
|
|
PostMoreMenu(postStore: postStore, fullPostStore: fullPostStore),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-09-11 01:04:15 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-10-19 01:30:30 +02:00
|
|
|
return IconButton(
|
|
|
|
onPressed: () => show(
|
|
|
|
context: context,
|
|
|
|
postStore: context.read<PostStore>(),
|
|
|
|
fullPostStore: null,
|
|
|
|
),
|
|
|
|
icon: Icon(moreIcon),
|
|
|
|
padding: EdgeInsets.zero,
|
|
|
|
visualDensity: VisualDensity.compact,
|
2021-09-11 01:04:15 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-11 16:26:10 +02:00
|
|
|
class PostMoreMenu extends HookWidget {
|
|
|
|
final PostStore postStore;
|
|
|
|
final FullPostStore? fullPostStore;
|
|
|
|
const PostMoreMenu({
|
|
|
|
required this.postStore,
|
|
|
|
required this.fullPostStore,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final loggedInAction = useLoggedInAction(postStore.postView.instanceHost);
|
|
|
|
|
|
|
|
final isMine = context
|
|
|
|
.read<AccountsStore>()
|
|
|
|
.defaultUserDataFor(postStore.postView.instanceHost)
|
|
|
|
?.userId ==
|
|
|
|
postStore.postView.creator.id;
|
|
|
|
|
|
|
|
return ObserverBuilder<PostStore>(
|
|
|
|
store: postStore,
|
2021-09-11 01:04:15 +02:00
|
|
|
builder: (context, store) {
|
|
|
|
final post = store.postView;
|
|
|
|
|
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
ListTile(
|
|
|
|
leading: const Icon(Icons.open_in_browser),
|
|
|
|
title: const Text('Open in browser'),
|
|
|
|
onTap: () async => await ul.canLaunch(post.post.apId)
|
|
|
|
? ul.launch(post.post.apId)
|
|
|
|
: ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
const SnackBar(content: Text("can't open in browser"))),
|
|
|
|
),
|
|
|
|
if (isMine)
|
|
|
|
ListTile(
|
|
|
|
leading: const Icon(Icons.edit),
|
|
|
|
title: const Text('Edit'),
|
|
|
|
onTap: () async {
|
2021-10-01 23:54:57 +02:00
|
|
|
final postView = await Navigator.of(context).push(
|
|
|
|
CreatePostPage.editRoute(post.post),
|
2021-09-11 01:04:15 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
if (postView != null) {
|
2021-09-11 16:26:10 +02:00
|
|
|
store.updatePostView(postView);
|
2021-09-11 01:04:15 +02:00
|
|
|
}
|
|
|
|
},
|
2021-09-11 16:26:10 +02:00
|
|
|
)
|
|
|
|
else
|
|
|
|
ListTile(
|
|
|
|
leading: store.userBlockingState.isLoading
|
|
|
|
? const CircularProgressIndicator.adaptive()
|
|
|
|
: const Icon(Icons.block),
|
|
|
|
title:
|
|
|
|
Text('${post.creatorBlocked ? 'Unblock' : 'Block'} user'),
|
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
loggedInAction(store.blockUser)();
|
|
|
|
},
|
2021-09-11 01:04:15 +02:00
|
|
|
),
|
2021-10-19 01:30:30 +02:00
|
|
|
if (fullPostStore?.fullPostView != null)
|
2021-09-11 16:26:10 +02:00
|
|
|
ObserverBuilder<FullPostStore>(
|
2021-09-14 23:48:04 +02:00
|
|
|
store: fullPostStore,
|
|
|
|
builder: (context, store) {
|
|
|
|
return ListTile(
|
|
|
|
leading: store.communityBlockingState.isLoading
|
|
|
|
? const CircularProgressIndicator.adaptive()
|
|
|
|
: const Icon(Icons.block),
|
|
|
|
title: Text(
|
|
|
|
'${store.fullPostView!.communityView.blocked ? 'Unblock' : 'Block'} community'),
|
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
loggedInAction(store.blockCommunity)();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2021-10-24 22:36:41 +02:00
|
|
|
ListTile(
|
|
|
|
leading: store.reportingState.isLoading
|
|
|
|
? const CircularProgressIndicator.adaptive()
|
|
|
|
: const Icon(Icons.flag),
|
|
|
|
title: const Text('Report'),
|
2021-10-25 19:52:29 +02:00
|
|
|
onTap: store.reportingState.isLoading
|
|
|
|
? null
|
|
|
|
: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
loggedInAction((token) async {
|
|
|
|
final reason = await ReportDialog.show(context);
|
|
|
|
if (reason != null) {
|
|
|
|
await store.report(token, reason);
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
},
|
2021-10-24 22:36:41 +02:00
|
|
|
),
|
2021-09-11 16:26:10 +02:00
|
|
|
ListTile(
|
|
|
|
leading: const Icon(Icons.info_outline),
|
|
|
|
title: const Text('Nerd stuff'),
|
|
|
|
onTap: () {
|
|
|
|
showInfoTablePopup(context: context, table: {
|
|
|
|
'% of upvotes':
|
|
|
|
'${(100 * (post.counts.upvotes / (post.counts.upvotes + post.counts.downvotes))).toInt()}%',
|
|
|
|
...post.toJson(),
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
2021-09-11 01:04:15 +02:00
|
|
|
],
|
|
|
|
);
|
2021-09-11 16:26:10 +02:00
|
|
|
});
|
|
|
|
}
|
2021-09-11 01:04:15 +02:00
|
|
|
}
|