diff --git a/lib/widgets/post/compose_card.dart b/lib/widgets/post/compose_card.dart index 16f30cb9..f167d5e7 100644 --- a/lib/widgets/post/compose_card.dart +++ b/lib/widgets/post/compose_card.dart @@ -152,7 +152,7 @@ class PostComposeCard extends HookConsumerWidget { originalPost: originalPost, repliedPost: repliedPost, forwardedPost: forwardedPost, - onSuccess: () { + onSuccess: (SnPost createdPost) { // Mark as submitted submitted.value = true; @@ -163,6 +163,9 @@ class PostComposeCard extends HookConsumerWidget { // Reset the form for new composition ComposeStateUtils.resetForm(state); + + // Call the widget's onSubmit callback to trigger activity list refresh + onSubmit?.call(createdPost); }, ); } diff --git a/lib/widgets/post/compose_submit_utils.dart b/lib/widgets/post/compose_submit_utils.dart index cf1b705f..e16f5527 100644 --- a/lib/widgets/post/compose_submit_utils.dart +++ b/lib/widgets/post/compose_submit_utils.dart @@ -9,16 +9,18 @@ import 'package:island/widgets/post/compose_shared.dart'; /// Utility class for common compose submit logic. class ComposeSubmitUtils { /// Performs the submit action for posts. - static Future performSubmit( + static Future performSubmit( WidgetRef ref, ComposeState state, BuildContext context, { SnPost? originalPost, SnPost? repliedPost, SnPost? forwardedPost, - required VoidCallback onSuccess, + required Function(SnPost) onSuccess, }) async { - if (state.submitting.value) return; + if (state.submitting.value) { + throw Exception('Already submitting'); + } // Don't submit empty posts (no content and no attachments) final hasContent = @@ -34,7 +36,7 @@ class ComposeSubmitUtils { context, ).showSnackBar(SnackBar(content: Text('postContentEmpty'))); } - return; // Don't submit empty posts + throw Exception('Post content is empty'); // Don't submit empty posts } try { @@ -82,15 +84,20 @@ class ComposeSubmitUtils { }; // Send request - client.request( + final response = await client.request( endpoint, queryParameters: {'pub': state.currentPublisher.value?.name}, data: payload, options: Options(method: isNewPost ? 'POST' : 'PATCH'), ); + // Parse the response into a SnPost + final post = SnPost.fromJson(response.data); + // Call the success callback with the created/updated post - onSuccess(); + onSuccess(post); + + return post; } catch (err) { // Show error message if context is mounted if (context.mounted) {