Better post edit

This commit is contained in:
shilangyu 2021-04-21 18:59:46 +02:00
parent 7c14fe616d
commit dcc4eba8ad
3 changed files with 46 additions and 10 deletions

View File

@ -15,13 +15,13 @@ import '../util/extensions/api.dart';
import '../util/extensions/spaced.dart';
import '../util/goto.dart';
import '../util/pictrs.dart';
import '../util/unawaited.dart';
import '../widgets/markdown_mode_icon.dart';
import '../widgets/markdown_text.dart';
import '../widgets/radio_picker.dart';
import 'full_post.dart';
/// Fab that triggers the [CreatePost] modal
/// After creation it will navigate to the newly created post
class CreatePostFab extends HookWidget {
final CommunityView? community;
@ -32,17 +32,28 @@ class CreatePostFab extends HookWidget {
final loggedInAction = useAnyLoggedInAction();
return FloatingActionButton(
onPressed: loggedInAction((_) => showCupertinoModalPopup(
onPressed: loggedInAction((_) async {
final postView = await showCupertinoModalPopup<PostView>(
context: context,
builder: (_) => community == null
? const CreatePostPage()
: CreatePostPage.toCommunity(community!))),
: CreatePostPage.toCommunity(community!),
);
if (postView != null) {
await goTo(
context,
(_) => FullPostPage.fromPostView(postView),
);
}
}),
child: const Icon(Icons.add),
);
}
}
/// Modal for creating a post to some community in some instance
/// Pops the navigator stack with a [PostView]
class CreatePostPage extends HookWidget {
final CommunityView? community;
@ -206,7 +217,7 @@ class CreatePostPage extends HookWidget {
));
}
}();
unawaited(goToReplace(context, (_) => FullPostPage.fromPostView(res)));
Navigator.of(context).pop(res);
return;
// ignore: avoid_catches_without_on_clauses
} catch (e) {

View File

@ -109,8 +109,13 @@ class FullPostPage extends HookWidget {
IconButton(icon: const Icon(Icons.share), onPressed: sharePost),
SavePostButton(post),
IconButton(
icon: Icon(moreIcon),
onPressed: () => PostWidget.showMoreMenu(context, post)),
icon: Icon(moreIcon),
onPressed: () => PostWidget.showMoreMenu(
context: context,
post: post,
fullPost: true,
),
),
],
),
floatingActionButton: post.post.locked

View File

@ -63,7 +63,11 @@ class PostWidget extends HookWidget {
// == ACTIONS ==
static void showMoreMenu(BuildContext context, PostView post) {
static void showMoreMenu({
required BuildContext context,
required PostView post,
bool fullPost = false,
}) {
final isMine = context
.read<AccountsStore>()
.defaultUserDataFor(post.instanceHost)
@ -97,11 +101,26 @@ class PostWidget extends HookWidget {
ListTile(
leading: const Icon(Icons.edit),
title: const Text('Edit'),
onTap: () {
showCupertinoModalPopup(
onTap: () async {
final postView = await showCupertinoModalPopup<PostView>(
context: context,
builder: (_) => CreatePostPage.edit(post.post),
);
if (postView != null) {
Navigator.of(context).pop();
if (fullPost) {
await goToReplace(
context,
(_) => FullPostPage.fromPostView(postView),
);
} else {
await goTo(
context,
(_) => FullPostPage.fromPostView(postView),
);
}
}
},
),
],
@ -247,7 +266,8 @@ class PostWidget extends HookWidget {
Column(
children: [
IconButton(
onPressed: () => showMoreMenu(context, post),
onPressed: () =>
showMoreMenu(context: context, post: post),
icon: Icon(moreIcon),
padding: const EdgeInsets.all(0),
visualDensity: VisualDensity.compact,